[Bps-public-commit] Prophet - A disconnected, replicated p2p database branch, master, updated. 31b83fa72db32c201360e66fdff421f65d14906d

jesse jesse at bestpractical.com
Mon Jan 26 18:51:35 EST 2009


The branch, master has been updated
       via  31b83fa72db32c201360e66fdff421f65d14906d (commit)
      from  3834533d5e24c8eeae8baa66436c6a6f38953f8b (commit)

Summary of changes:
 lib/Prophet/Server.pm                |    1 +
 share/web/static/jquery/js/pretty.js |   53 ++++++++++++++++++++++++++++++++++
 2 files changed, 54 insertions(+), 0 deletions(-)
 create mode 100644 share/web/static/jquery/js/pretty.js

- Log -----------------------------------------------------------------
commit 31b83fa72db32c201360e66fdff421f65d14906d
Author: Jesse Vincent <jesse at bestpractical.com>
Date:   Mon Jan 26 18:51:20 2009 -0500

    * Added support for pretty-printing dates

diff --git a/lib/Prophet/Server.pm b/lib/Prophet/Server.pm
index a193b34..44724a6 100644
--- a/lib/Prophet/Server.pm
+++ b/lib/Prophet/Server.pm
@@ -84,6 +84,7 @@ sub css {
 sub js {
     return
      '/static/prophet/jquery/js/jquery-1.2.6.min.js',
+     '/static/prophet/jquery/js/pretty.js', 
      '/static/prophet/jquery/js/hoverIntent.js', 
      '/static/prophet/jquery/js/jquery.bgiframe.min.js', 
      '/static/prophet/jquery/js/jquery-autocomplete.js', 
diff --git a/share/web/static/jquery/js/pretty.js b/share/web/static/jquery/js/pretty.js
new file mode 100644
index 0000000..aea52c8
--- /dev/null
+++ b/share/web/static/jquery/js/pretty.js
@@ -0,0 +1,53 @@
+/*
+ * JavaScript Pretty Date
+ * Copyright (c) 2008 John Resig (jquery.com)
+ * Licensed under the MIT license.
+ * Downloaded from http://ejohn.org/files/pretty.js on 2009-01-22
+ */
+
+// Takes an ISO time and returns a string representing how
+// long ago the date represents.
+function prettyDate(time){
+	var date = new Date((time || "").replace(/-/g,"/").replace(/[TZ]/g," ")),
+		diff = (((new Date()).getTime() - date.getTime()) / 1000),
+		day_diff = Math.floor(diff / 86400);
+			
+	if ( isNaN(day_diff) || day_diff < 0 || day_diff >= 31 )
+		return;
+		
+    // JRV 2009-01-26 - date thresholds changed	
+	return day_diff == 0 && (
+			diff < 60 && "just now" ||
+			diff < 120 && "1 minute ago" ||
+			diff < 3600 && Math.floor( diff / 60 ) + " minutes ago" ||
+			diff < 7200 && "1 hour ago" ||
+			diff < 86400 && Math.floor( diff / 3600 ) + " hours ago") ||
+		day_diff == 1 && "Yesterday" ||
+		day_diff < 13 && day_diff + " days ago" ||
+		day_diff < 45 && Math.ceil( day_diff / 7 ) + " weeks ago" ||
+        day_diff < 100 && Math.ceil(day_diff/30) + "months ago"
+}
+
+// If jQuery is included in the page, adds a jQuery plugin to handle it as well
+if ( typeof jQuery != "undefined" ) {
+	jQuery.fn.prettyDate = function(){
+		return this.each(function(){
+			var date = prettyDate(this.title);
+			if ( date )
+				jQuery(this).text( date );
+		});
+	};
+
+    // Jesse Vincent added this function to let you prettify a div rather than
+    // an HREF on 2009-01-26
+    jQuery.fn.prettyDateTag = function(){
+        return this.each(function(){
+            var original_date = this.innerHTML;
+            var date = prettyDate(this.innerHTML);
+             if (!date) return;
+            jQuery(this).attr('title', original_date) ;
+            jQuery(this).text( date );
+        });
+    }
+
+}

-----------------------------------------------------------------------



More information about the Bps-public-commit mailing list