Ticket #5911: patch5911.diff
| File patch5911.diff, 3.2 kB (added by wolfram, 11 months ago) |
|---|
-
dojo/date/stamp.js
25 25 // input may return null. Arguments which are out of bounds will be handled 26 26 // by the Date constructor (e.g. January 32nd typically gets resolved to February 1st) 27 27 // 28 // formattedString:28 // formattedString: 29 29 // A string such as 2005-06-30T08:05:00-07:00 or 2005-06-30 or T08:05:00 30 // 31 // >>> var t = dojo.date.stamp.fromISOString("2008-01-20T21:45:03") // Note the "T" before the time! 32 // >>> String(t).match(/Sun Jan 20 2008 21:45:03/) // Do only test for the beginning of the string, the end contains the timezone and that might differ on each test system 33 // ["Sun Jan 20 2008 21:45:03"] 30 34 // 35 // >>> dojo.date.stamp.fromISOString("2008-01-20 21:45:03") // Note the space before the time! 36 // >>> String(t).match(/Sun Jan 20 2008 21:45:03/) 37 // ["Sun Jan 20 2008 21:45:03"] 38 // 31 39 // defaultTime: 32 40 // Used for defaults for fields omitted in the formattedString. 33 41 // Uses 1970-01-01T00:00:00.0Z by default. … … 35 43 if(!dojo.date.stamp._isoRegExp){ 36 44 dojo.date.stamp._isoRegExp = 37 45 //TODO: could be more restrictive and check for 00-59, etc. 38 /^(?:(\d{4})(?:-(\d{2})(?:-(\d{2}))?)?)?(?: T(\d{2}):(\d{2})(?::(\d{2})(.\d+)?)?((?:[+-](\d{2}):(\d{2}))|Z)?)?$/;46 /^(?:(\d{4})(?:-(\d{2})(?:-(\d{2}))?)?)?(?:[ T](\d{2}):(\d{2})(?::(\d{2})(.\d+)?)?((?:[+-](\d{2}):(\d{2}))|Z)?)?$/; 39 47 } 40 48 41 49 var match = dojo.date.stamp._isoRegExp.exec(formattedString); … … 100 108 var getter = options.zulu ? "getUTC" : "get"; 101 109 var date = ""; 102 110 if(options.selector != "time"){ 103 date = [dateObject[getter+"FullYear"](), _(dateObject[getter+"Month"]()+1), _(dateObject[getter+"Date"]())].join('-'); 111 var year = dateObject[getter+"FullYear"](); 112 // For a year 100>999 getFullYear() returns a three digit number! 113 year = year<1000 ? "0"+year : year; 114 date = [year, _(dateObject[getter+"Month"]()+1), _(dateObject[getter+"Date"]())].join('-'); 104 115 } 105 116 formattedDate.push(date); 106 117 if(options.selector != "date"){ -
dojo/tests/date/stamp.js
14 14 t.is(5,date.getMinutes()); 15 15 t.is(0,date.getSeconds()); 16 16 17 var rfc = "2005-06-29 08:05:00"; 18 var date = dojo.date.stamp.fromISOString(rfc); 19 t.is(2005,date.getFullYear()); 20 t.is(5,date.getMonth()); 21 t.is(29,date.getDate()); 22 t.is(8,date.getHours()); 23 t.is(5,date.getMinutes()); 24 t.is(0,date.getSeconds()); 25 17 26 rfc = "2004-02-29"; 18 27 date = dojo.date.stamp.fromISOString(rfc); 19 28 t.is(2004,date.getFullYear()); … … 45 54 //truncate for comparison 46 55 t.is("0101-01",rfc.substring(0,7)); 47 56 57 // Make sure years between 100 and 999 are represented by four digits 58 // see http://trac.dojotoolkit.org/ticket/5911 59 date = new Date(100,1,2); 60 rfc = dojo.date.stamp.toISOString(date); 61 t.is("0100-",rfc.substring(0,5)); 62 date = new Date(999,1,2); 63 rfc = dojo.date.stamp.toISOString(date); 64 t.is("0999-",rfc.substring(0,5)); 65 48 66 rfc = "0101-01-01"; 49 67 date = dojo.date.stamp.fromISOString(rfc); 50 68 t.is(101,date.getFullYear());