Dygraph.dateString_: shows milliseconds if any. (#774)
[dygraphs.git] / auto_tests / tests / date_formats.js
index d0e419a..5148fe7 100644 (file)
@@ -3,27 +3,24 @@
  *
  * @author dan@dygraphs.com (Dan Vanderkam)
  */
-var dateFormatsTestCase = TestCase("date-formats");
 
-dateFormatsTestCase.prototype.setUp = function() {
-};
+import * as utils from '../../src/dygraph-utils';
 
-dateFormatsTestCase.prototype.tearDown = function() {
-};
+describe("date-formats", function() {
 
-dateFormatsTestCase.prototype.testISO8601 = function() {
+it('testISO8601', function() {
   // Format: YYYY-MM-DDTHH:MM:SS.ddddddZ
   // The "Z" indicates UTC, so this test should pass regardless of the time
   // zone of the machine on which it is run.
 
   // Firefox <4 does not support this format:
   // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Date/parse
-  if (new Date("2000-01-02T12:34:56.789012Z")) {
-    assertEquals(946816496789, Dygraph.dateParser("2000-01-02T12:34:56.789012Z"));
+  if (navigator.userAgent.indexOf("Firefox/3.5") == -1) {
+    assert.equal(946816496789, utils.dateParser("2000-01-02T12:34:56.789012Z"));
   }
-};
+});
 
-dateFormatsTestCase.prototype.testHyphenatedDate = function() {
+it('testHyphenatedDate', function() {
   // Format: YYYY-MM-DD HH:MM
 
   // Midnight February 2, 2000, UTC
@@ -36,5 +33,15 @@ dateFormatsTestCase.prototype.testHyphenatedDate = function() {
             zp(d.getDate()) + ' ' +
             zp(d.getHours()) + ':' +
             zp(d.getMinutes());
-  assertEquals(Date.UTC(2000, 1, 2), Dygraph.dateParser(str));
-};
+  assert.equal(Date.UTC(2000, 1, 2), utils.dateParser(str));
+});
+
+it('testMillisecondsDate', function() {
+  // Format: YYYY-MM-DD HH:MM:SS.MS
+
+  // Midnight February 2, 2000 14:25:42.123 UTC
+  var ts = Date.UTC(2000, 1, 2, 14, 25, 42, 123);
+  assert.equal("2000/02/02 14:25:42.123", utils.dateString_(ts, true));
+});
+
+});