]> git.pond.sub.org Git - eow/blob - static/dojo-release-1.1.1/dojox/dtl/filter/dates.js
add Dojo 1.1.1
[eow] / static / dojo-release-1.1.1 / dojox / dtl / filter / dates.js
1 if(!dojo._hasResource["dojox.dtl.filter.dates"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
2 dojo._hasResource["dojox.dtl.filter.dates"] = true;
3 dojo.provide("dojox.dtl.filter.dates");
4
5 dojo.require("dojox.dtl.utils.date");
6
7 (function(){
8         var ddfd = dojox.dtl.filter.dates;
9
10         dojo.mixin(ddfd, {
11                 _toDate: function(value){
12                         if(value instanceof Date){
13                                 return value;
14                         }
15                         value = new Date(value);
16                         if(value.getTime() == new Date(0).getTime()){
17                                 return "";
18                         }
19                         return value;
20                 },
21                 date: function(value, arg){
22                         // summary: Formats a date according to the given format
23                         value = ddfd._toDate(value);
24                         if(!value) return "";
25                         arg = arg || "N j, Y";
26                         return dojox.dtl.utils.date.format(value, arg);
27                 },
28                 time: function(value, arg){
29                         // summary: Formats a time according to the given format
30                         value = ddfd._toDate(value);
31                         if(!value) return "";
32                         arg = arg || "P";
33                         return dojox.dtl.utils.date.format(value, arg);
34                 },
35                 timesince: function(value, arg){
36                         // summary: Formats a date as the time since that date (i.e. "4 days, 6 hours")
37                         value = ddfd._toDate(value);
38                         if(!value) return "";
39                         var timesince = dojox.dtl.utils.date.timesince;
40                         if(arg) return timesince(arg, value);
41                         return timesince(value);
42                 },
43                 timeuntil: function(value, arg){
44                         // summary: Formats a date as the time until that date (i.e. "4 days, 6 hours")
45                         value = ddfd._toDate(value);
46                         if(!value) return "";
47                         var timesince = dojox.dtl.utils.date.timesince;
48                         if(arg) return timesince(arg, value);
49                         return timesince(new Date(), value);
50                 }
51         });
52 })();
53
54 }