From 086ff4d950fd4856b445a1cf1296d6f239980db7 Mon Sep 17 00:00:00 2001 From: Jay Wineinger Date: Tue, 3 May 2011 08:09:04 -0500 Subject: [PATCH 1/5] Added support for future times --- js/jquery.cuteTime.js | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/js/jquery.cuteTime.js b/js/jquery.cuteTime.js index dbd514e..d89c672 100644 --- a/js/jquery.cuteTime.js +++ b/js/jquery.cuteTime.js @@ -278,8 +278,24 @@ $.fn.cuteTime.settings = { refresh: -1, // time in milliseconds before next refresh of page data; -1 == no refresh time_ranges: [ - {bound: NEG_INF, // IMPORANT: bounds MUST be in ascending order, from negative infinity to positive infinity - cuteness: 'the future!', unit_size: 0}, + {bound: NEG_INF, + cuteness: 'way in the future!', unit_size: 0}, + {bound: -60 * 1000 * 60 * 24 * 30 * 12 * 2, + cuteness: 'in %CT% years', unit_size: -60 * 1000 * 60 * 24 * 30 * 12}, + {bound: -60 * 1000 * 60 * 24 * 30 * 12, + cuteness: 'next year', unit_size: 0}, + {bound: -60 * 1000 * 60 * 24 * 2, + cuteness: 'in %CT% days', unit_size: -60 * 1000 * 60 * 24}, + {bound: -60 * 1000 * 60 * 2, + cuteness: 'in %CT% hours', unit_size: -60 * 1000 * 60}, + {bound: -60 * 1000 * 60, + cuteness: 'in an hour', unit_size: 0}, + {bound: -60 * 1000 * 2, + cuteness: 'in %CT% minutes', unit_size: -60 * 1000}, + {bound: -60 * 1000, + cuteness: 'in a minute', unit_size: 0}, + {bound: -20 * 1000, + cuteness: 'in a few seconds', unit_size: 0}, {bound: 0, cuteness: 'just now', unit_size: 0}, {bound: 20 * 1000, @@ -413,7 +429,7 @@ if (i < time_ranges.length-1) { if (( time_difference >= timespan['bound']) && ( time_difference < time_ranges[i+1]['bound'])) { - if (timespan['unit_size'] > 0) { + if (timespan['unit_size'] != 0) { calculated_time = Math.floor(time_difference / timespan['unit_size']); } else { calculated_time = ''; From da3c6c42df9ac26aec9aa8760d39580f2be16ae5 Mon Sep 17 00:00:00 2001 From: Jay Wineinger Date: Tue, 3 May 2011 08:21:51 -0500 Subject: [PATCH 2/5] Fixed cuteness and unit_size for future dates --- js/jquery.cuteTime.js | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/js/jquery.cuteTime.js b/js/jquery.cuteTime.js index d89c672..e22feea 100644 --- a/js/jquery.cuteTime.js +++ b/js/jquery.cuteTime.js @@ -276,26 +276,31 @@ **********************************************************************************/ $.fn.cuteTime.settings = { - refresh: -1, // time in milliseconds before next refresh of page data; -1 == no refresh + refresh: -1, // time in milliseconds before next refresh of page data; -1 == no refresh time_ranges: [ + // ranges are matched to the range whose bound is LOWER than the + // time difference. This makes the logic for matching future dates + // confusing since they will have a negative time difference. This + // means that the cuteness and unit_size for negative dates must be + // shifted back one range each. {bound: NEG_INF, - cuteness: 'way in the future!', unit_size: 0}, - {bound: -60 * 1000 * 60 * 24 * 30 * 12 * 2, cuteness: 'in %CT% years', unit_size: -60 * 1000 * 60 * 24 * 30 * 12}, - {bound: -60 * 1000 * 60 * 24 * 30 * 12, + {bound: -60 * 1000 * 60 * 24 * 30 * 12 * 2, cuteness: 'next year', unit_size: 0}, - {bound: -60 * 1000 * 60 * 24 * 2, + {bound: -60 * 1000 * 60 * 24 * 30 * 12, cuteness: 'in %CT% days', unit_size: -60 * 1000 * 60 * 24}, - {bound: -60 * 1000 * 60 * 2, + {bound: -60 * 1000 * 60 * 24 * 2, cuteness: 'in %CT% hours', unit_size: -60 * 1000 * 60}, - {bound: -60 * 1000 * 60, + {bound: -60 * 1000 * 60 * 2, cuteness: 'in an hour', unit_size: 0}, - {bound: -60 * 1000 * 2, + {bound: -60 * 1000 * 60, cuteness: 'in %CT% minutes', unit_size: -60 * 1000}, - {bound: -60 * 1000, + {bound: -60 * 1000 * 2, cuteness: 'in a minute', unit_size: 0}, - {bound: -20 * 1000, + {bound: -60 * 1000, cuteness: 'in a few seconds', unit_size: 0}, + {bound: -20 * 1000, + cuteness: 'just now', unit_size: 0}, {bound: 0, cuteness: 'just now', unit_size: 0}, {bound: 20 * 1000, From 3de2d200d3ba4bd172bc4518a4730bdc7cb4ded3 Mon Sep 17 00:00:00 2001 From: Jay Wineinger Date: Tue, 3 May 2011 08:27:52 -0500 Subject: [PATCH 3/5] Slight change to comments regarding unit_size --- js/jquery.cuteTime.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/jquery.cuteTime.js b/js/jquery.cuteTime.js index e22feea..9e0c2fe 100644 --- a/js/jquery.cuteTime.js +++ b/js/jquery.cuteTime.js @@ -111,7 +111,7 @@ e.g. "it was %CT% hours ago" - unit_size: the divisor to apply to the calculated time difference; if unit_size > 0 + unit_size: the divisor to apply to the calculated time difference; if unit_size != 0 then a number value is prepended to the cuteness string as calculated by time_difference / unit_size e.g. 4 hours ago From 245b66e55d44dd98eee4852d34ff1dbdd9c8038b Mon Sep 17 00:00:00 2001 From: Jay Wineinger Date: Tue, 3 May 2011 08:40:59 -0500 Subject: [PATCH 4/5] Bumped version number and date --- js/jquery.cuteTime.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/js/jquery.cuteTime.js b/js/jquery.cuteTime.js index 9e0c2fe..c7b78c0 100644 --- a/js/jquery.cuteTime.js +++ b/js/jquery.cuteTime.js @@ -3,8 +3,8 @@ jQuery.cuteTime Author Jeremy Horn - Version 1.1.3 - Date: 4/6/2010 + Version 1.1.4 + Date: 5/3/2011 Copyright (c) 2009 Jeremy Horn- jeremydhorn(at)gmail(dot)c0m | http://tpgblog.com Dual licensed under MIT and GPL. From c6cd3c0083d54bbbb3e5658fea14c21061476213 Mon Sep 17 00:00:00 2001 From: Jay Wineinger Date: Tue, 3 May 2011 08:41:51 -0500 Subject: [PATCH 5/5] Updated minified file with new version supporting future dates --- js/jquery.cuteTime.min.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/js/jquery.cuteTime.min.js b/js/jquery.cuteTime.min.js index facc1e2..f49db44 100644 --- a/js/jquery.cuteTime.min.js +++ b/js/jquery.cuteTime.min.js @@ -1,3 +1,3 @@ -/* jQuery.CuteTime v 1.1.3 (4/6/2010) http://tpgblog.com/cutetime/ -compiled by http://yui.2clics.net/ */ -(function(f){var b=Number.NEGATIVE_INFINITY;var d=Number.POSITIVE_INFINITY;var a="data-timestamp";f.fn.cuteTime=function(n){var m=new Date().getTime();var o;var p;if((typeof n=="object")||(n==undefined)){f.fn.cuteTime.c_settings=f.extend({},f.fn.cuteTime.settings,n);f.fn.cuteTime.the_selected=this;this.each(function(){p=f(this);o=j(p);p.html(c(m-o))});f.fn.cuteTime.start_cuteness()}return this};f.cuteTime=function(n,q){var m=new Date().getTime();var p;var r;var o=null;if(typeof n=="object"){f.fn.cuteTime.c_settings=f.extend({},f.fn.cuteTime.settings,n)}if(typeof n=="string"){o=n}else{if(typeof q=="string"){o=q}}if(o!=null){p=l(o);if(!isNaN(p)){return c(m-p)}else{return"INVALID_DATETIME_FORMAT"}}return this};f.fn.cuteTime.settings={refresh:-1,time_ranges:[{bound:b,cuteness:"the future!",unit_size:0},{bound:0,cuteness:"just now",unit_size:0},{bound:20*1000,cuteness:"a few seconds ago",unit_size:0},{bound:60*1000,cuteness:"a minute ago",unit_size:0},{bound:60*1000*2,cuteness:" minutes ago",unit_size:60*1000},{bound:60*1000*60,cuteness:"an hour ago",unit_size:0},{bound:60*1000*60*2,cuteness:" hours ago",unit_size:60*1000*60},{bound:60*1000*60*24,cuteness:"yesterday",unit_size:0},{bound:60*1000*60*24*2,cuteness:" days ago",unit_size:60*1000*60*24},{bound:60*1000*60*24*30,cuteness:"last month",unit_size:0},{bound:60*1000*60*24*30*2,cuteness:" months ago",unit_size:60*1000*60*24*30},{bound:60*1000*60*24*30*12,cuteness:"last year",unit_size:0},{bound:60*1000*60*24*30*12*2,cuteness:" years ago",unit_size:60*1000*60*24*30*12},{bound:d,cuteness:"a blinkle ago",unit_size:0}]};f.fn.cuteTime.start_cuteness=function(){var m=f.fn.cuteTime.c_settings.refresh;if(f.fn.cuteTime.process_tracker==null){if(m>0){f.fn.cuteTime.process_tracker=setInterval("$.fn.cuteTime.update_cuteness()",m)}}else{}return this};f.fn.cuteTime.update_cuteness=function(){var m=new Date().getTime();var o;var n;f.fn.cuteTime.the_selected.each(function(){o=f(this);n=j(o);o.html(c(m-n))})};f.fn.cuteTime.stop_cuteness=function(){if(f.fn.cuteTime.process_tracker!=null){clearInterval(f.fn.cuteTime.process_tracker);f.fn.cuteTime.process_tracker=null}else{}return this};function c(q){var o=f.fn.cuteTime.c_settings.time_ranges;var n,p;var m="";jQuery.each(o,function(r,s){if(r=s.bound)&&(q0){p=Math.floor(q/s.unit_size)}else{p=""}n=s.cuteness.replace(/%CT%/,p);if(n==s.cuteness){m=p+s.cuteness}else{m=n}return false}}else{return false}});if(m==""){m="2 pookies ago"}return m}function l(n){var m;if((new_date=g(n))!=null){m=new_date.valueOf()}else{m=(new Date(n)).valueOf();if(isNaN(m)){m=new Date(n.replace(/-/g," "))}}return m}function g(q){var m=q.match(/^(\d{4})((-(\d{2})(-(\d{2})(T(\d{2}):(\d{2})(:(\d{2})(.(\d+))?)?(Z|(([+-])((\d{2}):(\d{2})))))?)?)?)$/);if(m!=null){var n=new Date();var p=0;var o=0;n.setUTCFullYear(m[1]);if(!e(m[4])){n.setUTCMonth(m[4]-1);if(!e(m[6])){n.setUTCDate(m[6]);if(!e(m[16])){p=m[18];o=m[19];if(m[16]=="-"){p*=-1;o*=-1}}if(!e(m[8])){n.setUTCHours(m[8]-p);n.setUTCMinutes(m[9]-o);if(!e(m[11])){n.setUTCSeconds(m[11]);if(!e(m[13])){n.setUTCMilliseconds(m[13]*1000)}}}}}return n}else{return null}}function e(m){if(null==m||""==m){return true}return false}function j(o){var n=Number.NaN;var m=h(o);if(m!=null){n=l(m)}if(isNaN(n)){m=i(o);if(m!=null){n=l(m)}}if(isNaN(n)){m=new Date().toString();n=l(m)}k(m,o);return n}function h(n){var m=n.attr(a);if(m!=undefined){return m}else{return null}}function k(m,n){n.attr(a,m)}function i(m){return m.text()}})(jQuery); \ No newline at end of file +/* jQuery.CuteTime v 1.1.4 (5/3/2011) http://tpgblog.com/cutetime/ + compiled by http://yui.2clics.net/ */ +(function(f){var b=Number.NEGATIVE_INFINITY;var d=Number.POSITIVE_INFINITY;var a="data-timestamp";f.fn.cuteTime=function(n){var m=new Date().getTime();var o;var p;if((typeof n=="object")||(n==undefined)){f.fn.cuteTime.c_settings=f.extend({},f.fn.cuteTime.settings,n);f.fn.cuteTime.the_selected=this;this.each(function(){p=f(this);o=j(p);p.html(c(m-o))});f.fn.cuteTime.start_cuteness()}return this};f.cuteTime=function(n,q){var m=new Date().getTime();var p;var r;var o=null;if(typeof n=="object"){f.fn.cuteTime.c_settings=f.extend({},f.fn.cuteTime.settings,n)}if(typeof n=="string"){o=n}else{if(typeof q=="string"){o=q}}if(o!=null){p=l(o);if(!isNaN(p)){return c(m-p)}else{return"INVALID_DATETIME_FORMAT"}}return this};f.fn.cuteTime.settings={refresh:-1,time_ranges:[{bound:b,cuteness:"in %CT% years",unit_size:-60*1000*60*24*30*12},{bound:-60*1000*60*24*30*12*2,cuteness:"next year",unit_size:0},{bound:-60*1000*60*24*30*12,cuteness:"in %CT% days",unit_size:-60*1000*60*24},{bound:-60*1000*60*24*2,cuteness:"in %CT% hours",unit_size:-60*1000*60},{bound:-60*1000*60*2,cuteness:"in an hour",unit_size:0},{bound:-60*1000*60,cuteness:"in %CT% minutes",unit_size:-60*1000},{bound:-60*1000*2,cuteness:"in a minute",unit_size:0},{bound:-60*1000,cuteness:"in a few seconds",unit_size:0},{bound:-20*1000,cuteness:"just now",unit_size:0},{bound:0,cuteness:"just now",unit_size:0},{bound:20*1000,cuteness:"a few seconds ago",unit_size:0},{bound:60*1000,cuteness:"a minute ago",unit_size:0},{bound:60*1000*2,cuteness:" minutes ago",unit_size:60*1000},{bound:60*1000*60,cuteness:"an hour ago",unit_size:0},{bound:60*1000*60*2,cuteness:" hours ago",unit_size:60*1000*60},{bound:60*1000*60*24,cuteness:"yesterday",unit_size:0},{bound:60*1000*60*24*2,cuteness:" days ago",unit_size:60*1000*60*24},{bound:60*1000*60*24*30,cuteness:"last month",unit_size:0},{bound:60*1000*60*24*30*2,cuteness:" months ago",unit_size:60*1000*60*24*30},{bound:60*1000*60*24*30*12,cuteness:"last year",unit_size:0},{bound:60*1000*60*24*30*12*2,cuteness:" years ago",unit_size:60*1000*60*24*30*12},{bound:d,cuteness:"a blinkle ago",unit_size:0}]};f.fn.cuteTime.start_cuteness=function(){var m=f.fn.cuteTime.c_settings.refresh;if(f.fn.cuteTime.process_tracker==null){if(m>0){f.fn.cuteTime.process_tracker=setInterval("$.fn.cuteTime.update_cuteness()",m)}}else{}return this};f.fn.cuteTime.update_cuteness=function(){var m=new Date().getTime();var o;var n;f.fn.cuteTime.the_selected.each(function(){o=f(this);n=j(o);o.html(c(m-n))})};f.fn.cuteTime.stop_cuteness=function(){if(f.fn.cuteTime.process_tracker!=null){clearInterval(f.fn.cuteTime.process_tracker);f.fn.cuteTime.process_tracker=null}else{}return this};function c(q){var o=f.fn.cuteTime.c_settings.time_ranges;var n,p;var m="";jQuery.each(o,function(r,s){if(r=s.bound)&&(q