1 if(!dojo._hasResource["dojox.dtl.utils.date"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
2 dojo._hasResource["dojox.dtl.utils.date"] = true;
3 dojo.provide("dojox.dtl.utils.date");
5 dojo.require("dojox.date.php");
7 dojox.dtl.utils.date.DateFormat = function(/*String*/ format){
8 dojox.date.php.DateFormat.call(this, format);
10 dojo.extend(dojox.dtl.utils.date.DateFormat, dojox.date.php.DateFormat.prototype, {
13 // Time, in 12-hour hours and minutes, with minutes left off if they're zero.
15 // Examples: '1', '1:30', '2:05', '2'
16 // Proprietary extension.
17 return (!this.date.getMinutes()) ? this.g() : this.g() + ":" + this.i();
20 // summary: Month abbreviation in Associated Press style. Proprietary extension.
21 return dojox.dtl.utils.date._months_ap[this.date.getMonth()];
25 // Time, in 12-hour hours, minutes and 'a.m.'/'p.m.', with minutes left off
26 // if they're zero and the strings 'midnight' and 'noon' if appropriate.
28 // Examples: '1 a.m.', '1:30 p.m.', 'midnight', 'noon', '12:30 p.m.'
29 // Proprietary extension.
30 if(!this.date.getMinutes() && !this.date.getHours()) return 'midnight';
31 if(!this.date.getMinutes() && this.date.getHours() == 12) return 'noon';
32 return this.f() + " " + this.a();
36 dojo.mixin(dojox.dtl.utils.date, {
37 format: function(/*Date*/ date, /*String*/ format){
38 var df = new dojox.dtl.utils.date.DateFormat(format);
39 return df.format(date);
41 timesince: function(d, now){
43 // Takes two datetime objects and returns the time between then and now
44 // as a nicely formatted string, e.g "10 minutes"
46 // Adapted from http://blog.natbat.co.uk/archive/2003/Jun/14/time_since
47 if(!(d instanceof Date)){
48 d = new Date(d.year, d.month, d.day);
54 var delta = Math.abs(now.getTime() - d.getTime());
55 for(var i = 0, chunk; chunk = dojox.dtl.utils.date._chunks[i]; i++){
56 var count = Math.floor(delta / chunk[0]);
59 return count + " " + chunk[1](count);
62 [60 * 60 * 24 * 365 * 1000, function(n){ return (n == 1) ? 'year' : 'years'; }],
63 [60 * 60 * 24 * 30 * 1000, function(n){ return (n == 1) ? 'month' : 'months'; }],
64 [60 * 60 * 24 * 7 * 1000, function(n){ return (n == 1) ? 'week' : 'weeks'; }],
65 [60 * 60 * 24 * 1000, function(n){ return (n == 1) ? 'day' : 'days'; }],
66 [60 * 60 * 1000, function(n){ return (n == 1) ? 'hour' : 'hours'; }],
67 [60 * 1000, function(n){ return (n == 1) ? 'minute' : 'minutes'; }]
69 _months_ap: ["Jan.", "Feb.", "March", "April", "May", "June", "July", "Aug.", "Sept.", "Oct.", "Nov.", "Dec."]