[483] | 1 | define([ |
---|
| 2 | "dojo/_base/lang", |
---|
| 3 | "dojox/date/php", |
---|
| 4 | "../_base" |
---|
| 5 | ], function(lang,ddp,dd){ |
---|
| 6 | |
---|
| 7 | var date = lang.getObject("utils.date", true, dd); |
---|
| 8 | /*===== |
---|
| 9 | date = { |
---|
| 10 | // TODO: summary |
---|
| 11 | }; |
---|
| 12 | =====*/ |
---|
| 13 | |
---|
| 14 | date.DateFormat = ddp.DateFormat; |
---|
| 15 | lang.extend(date.DateFormat, ddp.DateFormat.prototype, { |
---|
| 16 | f: function(){ |
---|
| 17 | // summary: |
---|
| 18 | // Time, in 12-hour hours and minutes, with minutes left off if they're zero. |
---|
| 19 | // description: |
---|
| 20 | // Examples: '1', '1:30', '2:05', '2' |
---|
| 21 | // Proprietary extension. |
---|
| 22 | return (!this.date.getMinutes()) ? this.g() : this.g() + ":" + this.i(); |
---|
| 23 | }, |
---|
| 24 | N: function(){ |
---|
| 25 | // summary: |
---|
| 26 | // Month abbreviation in Associated Press style. Proprietary extension. |
---|
| 27 | return date._months_ap[this.date.getMonth()]; |
---|
| 28 | }, |
---|
| 29 | P: function(){ |
---|
| 30 | // summary: |
---|
| 31 | // Time, in 12-hour hours, minutes and 'a.m.'/'p.m.', with minutes left off |
---|
| 32 | // if they're zero and the strings 'midnight' and 'noon' if appropriate. |
---|
| 33 | // description: |
---|
| 34 | // Examples: '1 a.m.', '1:30 p.m.', 'midnight', 'noon', '12:30 p.m.' |
---|
| 35 | // Proprietary extension. |
---|
| 36 | if(!this.date.getMinutes() && !this.date.getHours()){ |
---|
| 37 | return 'midnight'; |
---|
| 38 | } |
---|
| 39 | if(!this.date.getMinutes() && this.date.getHours() == 12){ |
---|
| 40 | return 'noon'; |
---|
| 41 | } |
---|
| 42 | return this.f() + " " + this.a(); |
---|
| 43 | } |
---|
| 44 | }); |
---|
| 45 | |
---|
| 46 | lang.mixin(dojox.dtl.utils.date, { |
---|
| 47 | format: function(/*Date*/ date, /*String*/ format){ |
---|
| 48 | var df = new dojox.dtl.utils.date.DateFormat(format); |
---|
| 49 | return df.format(date); |
---|
| 50 | }, |
---|
| 51 | timesince: function(d, now){ |
---|
| 52 | // summary: |
---|
| 53 | // Takes two datetime objects and returns the time between then and now |
---|
| 54 | // as a nicely formatted string, e.g "10 minutes" |
---|
| 55 | // description: |
---|
| 56 | // Adapted from http://blog.natbat.co.uk/archive/2003/Jun/14/time_since |
---|
| 57 | if(!(d instanceof Date)){ |
---|
| 58 | d = new Date(d.year, d.month, d.day); |
---|
| 59 | } |
---|
| 60 | if(!now){ |
---|
| 61 | now = new Date(); |
---|
| 62 | } |
---|
| 63 | |
---|
| 64 | var delta = Math.abs(now.getTime() - d.getTime()); |
---|
| 65 | for(var i = 0, chunk; chunk = dojox.dtl.utils.date._chunks[i]; i++){ |
---|
| 66 | var count = Math.floor(delta / chunk[0]); |
---|
| 67 | if(count) break; |
---|
| 68 | } |
---|
| 69 | return count + " " + chunk[1](count); |
---|
| 70 | }, |
---|
| 71 | _chunks: [ |
---|
| 72 | [60 * 60 * 24 * 365 * 1000, function(n){ return (n == 1) ? 'year' : 'years'; }], |
---|
| 73 | [60 * 60 * 24 * 30 * 1000, function(n){ return (n == 1) ? 'month' : 'months'; }], |
---|
| 74 | [60 * 60 * 24 * 7 * 1000, function(n){ return (n == 1) ? 'week' : 'weeks'; }], |
---|
| 75 | [60 * 60 * 24 * 1000, function(n){ return (n == 1) ? 'day' : 'days'; }], |
---|
| 76 | [60 * 60 * 1000, function(n){ return (n == 1) ? 'hour' : 'hours'; }], |
---|
| 77 | [60 * 1000, function(n){ return (n == 1) ? 'minute' : 'minutes'; }] |
---|
| 78 | ], |
---|
| 79 | _months_ap: ["Jan.", "Feb.", "March", "April", "May", "June", "July", "Aug.", "Sept.", "Oct.", "Nov.", "Dec."] |
---|
| 80 | }); |
---|
| 81 | |
---|
| 82 | return date; |
---|
| 83 | }); |
---|