root / trunk / web / dojo / dojox / dtl / utils / date.js @ 9
History | View | Annotate | Download (1.75 KB)
| 1 | 9 | andrej.cim | /*
|
|---|---|---|---|
| 2 | Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved.
|
||
| 3 | Available via Academic Free License >= 2.1 OR the modified BSD license.
|
||
| 4 | see: http://dojotoolkit.org/license for details
|
||
| 5 | */
|
||
| 6 | |||
| 7 | |||
| 8 | if(!dojo._hasResource["dojox.dtl.utils.date"]){ |
||
| 9 | dojo._hasResource["dojox.dtl.utils.date"]=true; |
||
| 10 | dojo.provide("dojox.dtl.utils.date");
|
||
| 11 | dojo.require("dojox.date.php");
|
||
| 12 | dojox.dtl.utils.date.DateFormat=function(_1){ |
||
| 13 | dojox.date.php.DateFormat.call(this,_1);
|
||
| 14 | }; |
||
| 15 | dojo.extend(dojox.dtl.utils.date.DateFormat,dojox.date.php.DateFormat.prototype,{f:function(){
|
||
| 16 | return (!this.date.getMinutes())?this.g():this.g()+":"+this.i(); |
||
| 17 | },N:function(){ |
||
| 18 | return dojox.dtl.utils.date._months_ap[this.date.getMonth()]; |
||
| 19 | },P:function(){ |
||
| 20 | if(!this.date.getMinutes()&&!this.date.getHours()){ |
||
| 21 | return "midnight"; |
||
| 22 | } |
||
| 23 | if(!this.date.getMinutes()&&this.date.getHours()==12){ |
||
| 24 | return "noon"; |
||
| 25 | } |
||
| 26 | return this.f()+" "+this.a(); |
||
| 27 | }}); |
||
| 28 | dojo.mixin(dojox.dtl.utils.date,{format:function(_2,_3){
|
||
| 29 | var df=new dojox.dtl.utils.date.DateFormat(_3); |
||
| 30 | return df.format(_2);
|
||
| 31 | },timesince:function(d,_4){ |
||
| 32 | if(!(d instanceof Date)){ |
||
| 33 | d=new Date(d.year,d.month,d.day);
|
||
| 34 | } |
||
| 35 | if(!_4){
|
||
| 36 | _4=new Date();
|
||
| 37 | } |
||
| 38 | var _5=Math.abs(_4.getTime()-d.getTime());
|
||
| 39 | for(var i=0,_6;_6=dojox.dtl.utils.date._chunks[i];i++){ |
||
| 40 | var _7=Math.floor(_5/_6[0]); |
||
| 41 | if(_7){
|
||
| 42 | break;
|
||
| 43 | } |
||
| 44 | } |
||
| 45 | return _7+" "+_6[1](_7); |
||
| 46 | },_chunks:[[60*60*24*365*1000,function(n){ |
||
| 47 | return (n==1)?"year":"years"; |
||
| 48 | }],[60*60*24*30*1000,function(n){ |
||
| 49 | return (n==1)?"month":"months"; |
||
| 50 | }],[60*60*24*7*1000,function(n){ |
||
| 51 | return (n==1)?"week":"weeks"; |
||
| 52 | }],[60*60*24*1000,function(n){ |
||
| 53 | return (n==1)?"day":"days"; |
||
| 54 | }],[60*60*1000,function(n){ |
||
| 55 | return (n==1)?"hour":"hours"; |
||
| 56 | }],[60*1000,function(n){ |
||
| 57 | return (n==1)?"minute":"minutes"; |
||
| 58 | }]],_months_ap:["Jan.","Feb.","March","April","May","June","July","Aug.","Sept.","Oct.","Nov.","Dec."]}); |
||
| 59 | } |