| 1 | /** |
| 2 | * @fileoverview Tests that various formats of date are understood by dygraphs. |
| 3 | * |
| 4 | * @author dan@dygraphs.com (Dan Vanderkam) |
| 5 | */ |
| 6 | var dateFormatsTestCase = TestCase("date-formats"); |
| 7 | |
| 8 | dateFormatsTestCase.prototype.setUp = function() { |
| 9 | }; |
| 10 | |
| 11 | dateFormatsTestCase.prototype.tearDown = function() { |
| 12 | }; |
| 13 | |
| 14 | dateFormatsTestCase.prototype.testISO8601 = function() { |
| 15 | // Format: YYYY-MM-DDTHH:MM:SS.ddddddZ |
| 16 | // The "Z" indicates UTC, so this test should pass regardless of the time |
| 17 | // zone of the machine on which it is run. |
| 18 | |
| 19 | // Firefox <4 does not support this format: |
| 20 | // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Date/parse |
| 21 | if (navigator.userAgent.indexOf("Firefox/3.5") == -1) { |
| 22 | assertEquals(946816496789, Dygraph.dateParser("2000-01-02T12:34:56.789012Z")); |
| 23 | } |
| 24 | }; |
| 25 | |
| 26 | dateFormatsTestCase.prototype.testHyphenatedDate = function() { |
| 27 | // Format: YYYY-MM-DD HH:MM |
| 28 | |
| 29 | // Midnight February 2, 2000, UTC |
| 30 | var d = new Date(Date.UTC(2000, 1, 2)); |
| 31 | |
| 32 | // Convert to a string in the local time zone: YYYY-DD-MM HH:MM |
| 33 | var zp = function(x) { return x < 10 ? '0' + x : x; }; |
| 34 | var str = d.getFullYear() + '-' + |
| 35 | zp(1 + d.getMonth()) + '-' + |
| 36 | zp(d.getDate()) + ' ' + |
| 37 | zp(d.getHours()) + ':' + |
| 38 | zp(d.getMinutes()); |
| 39 | assertEquals(Date.UTC(2000, 1, 2), Dygraph.dateParser(str)); |
| 40 | }; |