summaryrefslogtreecommitdiff
path: root/lib/dojo/date/stamp.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/dojo/date/stamp.js')
-rw-r--r--lib/dojo/date/stamp.js146
1 files changed, 2 insertions, 144 deletions
diff --git a/lib/dojo/date/stamp.js b/lib/dojo/date/stamp.js
index 04b68a06a..029a0130b 100644
--- a/lib/dojo/date/stamp.js
+++ b/lib/dojo/date/stamp.js
@@ -4,147 +4,5 @@
see: http://dojotoolkit.org/license for details
*/
-
-if(!dojo._hasResource["dojo.date.stamp"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
-dojo._hasResource["dojo.date.stamp"] = true;
-dojo.provide("dojo.date.stamp");
-
-dojo.getObject("date.stamp", true, dojo);
-
-// Methods to convert dates to or from a wire (string) format using well-known conventions
-
-dojo.date.stamp.fromISOString = function(/*String*/formattedString, /*Number?*/defaultTime){
- // summary:
- // Returns a Date object given a string formatted according to a subset of the ISO-8601 standard.
- //
- // description:
- // Accepts a string formatted according to a profile of ISO8601 as defined by
- // [RFC3339](http://www.ietf.org/rfc/rfc3339.txt), except that partial input is allowed.
- // Can also process dates as specified [by the W3C](http://www.w3.org/TR/NOTE-datetime)
- // The following combinations are valid:
- //
- // * dates only
- // | * yyyy
- // | * yyyy-MM
- // | * yyyy-MM-dd
- // * times only, with an optional time zone appended
- // | * THH:mm
- // | * THH:mm:ss
- // | * THH:mm:ss.SSS
- // * and "datetimes" which could be any combination of the above
- //
- // timezones may be specified as Z (for UTC) or +/- followed by a time expression HH:mm
- // Assumes the local time zone if not specified. Does not validate. Improperly formatted
- // input may return null. Arguments which are out of bounds will be handled
- // by the Date constructor (e.g. January 32nd typically gets resolved to February 1st)
- // Only years between 100 and 9999 are supported.
- //
- // formattedString:
- // A string such as 2005-06-30T08:05:00-07:00 or 2005-06-30 or T08:05:00
- //
- // defaultTime:
- // Used for defaults for fields omitted in the formattedString.
- // Uses 1970-01-01T00:00:00.0Z by default.
-
- if(!dojo.date.stamp._isoRegExp){
- dojo.date.stamp._isoRegExp =
-//TODO: could be more restrictive and check for 00-59, etc.
- /^(?:(\d{4})(?:-(\d{2})(?:-(\d{2}))?)?)?(?:T(\d{2}):(\d{2})(?::(\d{2})(.\d+)?)?((?:[+-](\d{2}):(\d{2}))|Z)?)?$/;
- }
-
- var match = dojo.date.stamp._isoRegExp.exec(formattedString),
- result = null;
-
- if(match){
- match.shift();
- if(match[1]){match[1]--;} // Javascript Date months are 0-based
- if(match[6]){match[6] *= 1000;} // Javascript Date expects fractional seconds as milliseconds
-
- if(defaultTime){
- // mix in defaultTime. Relatively expensive, so use || operators for the fast path of defaultTime === 0
- defaultTime = new Date(defaultTime);
- dojo.forEach(dojo.map(["FullYear", "Month", "Date", "Hours", "Minutes", "Seconds", "Milliseconds"], function(prop){
- return defaultTime["get" + prop]();
- }), function(value, index){
- match[index] = match[index] || value;
- });
- }
- result = new Date(match[0]||1970, match[1]||0, match[2]||1, match[3]||0, match[4]||0, match[5]||0, match[6]||0); //TODO: UTC defaults
- if(match[0] < 100){
- result.setFullYear(match[0] || 1970);
- }
-
- var offset = 0,
- zoneSign = match[7] && match[7].charAt(0);
- if(zoneSign != 'Z'){
- offset = ((match[8] || 0) * 60) + (Number(match[9]) || 0);
- if(zoneSign != '-'){ offset *= -1; }
- }
- if(zoneSign){
- offset -= result.getTimezoneOffset();
- }
- if(offset){
- result.setTime(result.getTime() + offset * 60000);
- }
- }
-
- return result; // Date or null
-};
-
-/*=====
- dojo.date.stamp.__Options = function(){
- // selector: String
- // "date" or "time" for partial formatting of the Date object.
- // Both date and time will be formatted by default.
- // zulu: Boolean
- // if true, UTC/GMT is used for a timezone
- // milliseconds: Boolean
- // if true, output milliseconds
- this.selector = selector;
- this.zulu = zulu;
- this.milliseconds = milliseconds;
- }
-=====*/
-
-dojo.date.stamp.toISOString = function(/*Date*/dateObject, /*dojo.date.stamp.__Options?*/options){
- // summary:
- // Format a Date object as a string according a subset of the ISO-8601 standard
- //
- // description:
- // When options.selector is omitted, output follows [RFC3339](http://www.ietf.org/rfc/rfc3339.txt)
- // The local time zone is included as an offset from GMT, except when selector=='time' (time without a date)
- // Does not check bounds. Only years between 100 and 9999 are supported.
- //
- // dateObject:
- // A Date object
-
- var _ = function(n){ return (n < 10) ? "0" + n : n; };
- options = options || {};
- var formattedDate = [],
- getter = options.zulu ? "getUTC" : "get",
- date = "";
- if(options.selector != "time"){
- var year = dateObject[getter+"FullYear"]();
- date = ["0000".substr((year+"").length)+year, _(dateObject[getter+"Month"]()+1), _(dateObject[getter+"Date"]())].join('-');
- }
- formattedDate.push(date);
- if(options.selector != "date"){
- var time = [_(dateObject[getter+"Hours"]()), _(dateObject[getter+"Minutes"]()), _(dateObject[getter+"Seconds"]())].join(':');
- var millis = dateObject[getter+"Milliseconds"]();
- if(options.milliseconds){
- time += "."+ (millis < 100 ? "0" : "") + _(millis);
- }
- if(options.zulu){
- time += "Z";
- }else if(options.selector != "time"){
- var timezoneOffset = dateObject.getTimezoneOffset();
- var absOffset = Math.abs(timezoneOffset);
- time += (timezoneOffset > 0 ? "-" : "+") +
- _(Math.floor(absOffset/60)) + ":" + _(absOffset%60);
- }
- formattedDate.push(time);
- }
- return formattedDate.join('T'); // String
-};
-
-}
+//>>built
+define("dojo/date/stamp",["../_base/kernel","../_base/lang","../_base/array"],function(_1,_2,_3){_2.getObject("date.stamp",true,_1);_1.date.stamp.fromISOString=function(_4,_5){if(!_1.date.stamp._isoRegExp){_1.date.stamp._isoRegExp=/^(?:(\d{4})(?:-(\d{2})(?:-(\d{2}))?)?)?(?:T(\d{2}):(\d{2})(?::(\d{2})(.\d+)?)?((?:[+-](\d{2}):(\d{2}))|Z)?)?$/;}var _6=_1.date.stamp._isoRegExp.exec(_4),_7=null;if(_6){_6.shift();if(_6[1]){_6[1]--;}if(_6[6]){_6[6]*=1000;}if(_5){_5=new Date(_5);_3.forEach(_3.map(["FullYear","Month","Date","Hours","Minutes","Seconds","Milliseconds"],function(_8){return _5["get"+_8]();}),function(_9,_a){_6[_a]=_6[_a]||_9;});}_7=new Date(_6[0]||1970,_6[1]||0,_6[2]||1,_6[3]||0,_6[4]||0,_6[5]||0,_6[6]||0);if(_6[0]<100){_7.setFullYear(_6[0]||1970);}var _b=0,_c=_6[7]&&_6[7].charAt(0);if(_c!="Z"){_b=((_6[8]||0)*60)+(Number(_6[9])||0);if(_c!="-"){_b*=-1;}}if(_c){_b-=_7.getTimezoneOffset();}if(_b){_7.setTime(_7.getTime()+_b*60000);}}return _7;};_1.date.stamp.toISOString=function(_d,_e){var _f=function(n){return (n<10)?"0"+n:n;};_e=_e||{};var _10=[],_11=_e.zulu?"getUTC":"get",_12="";if(_e.selector!="time"){var _13=_d[_11+"FullYear"]();_12=["0000".substr((_13+"").length)+_13,_f(_d[_11+"Month"]()+1),_f(_d[_11+"Date"]())].join("-");}_10.push(_12);if(_e.selector!="date"){var _14=[_f(_d[_11+"Hours"]()),_f(_d[_11+"Minutes"]()),_f(_d[_11+"Seconds"]())].join(":");var _15=_d[_11+"Milliseconds"]();if(_e.milliseconds){_14+="."+(_15<100?"0":"")+_f(_15);}if(_e.zulu){_14+="Z";}else{if(_e.selector!="time"){var _16=_d.getTimezoneOffset();var _17=Math.abs(_16);_14+=(_16>0?"-":"+")+_f(Math.floor(_17/60))+":"+_f(_17%60);}}_10.push(_14);}return _10.join("T");};return _1.date.stamp;}); \ No newline at end of file