Fix for ticks when years are < 100.
authorGeorge Madrid <gmadrid@gmail.com>
Fri, 7 Feb 2014 19:05:25 +0000 (14:05 -0500)
committerDan Vanderkam <danvdk@gmail.com>
Wed, 22 Oct 2014 02:27:13 +0000 (22:27 -0400)
auto_tests/misc/local.html
auto_tests/tests/TwoDigitYears.js [new file with mode: 0644]

index 3939fa4..b016aaf 100644 (file)
@@ -57,6 +57,7 @@
   <script type="text/javascript" src="../tests/stacked.js"></script>
   <script type="text/javascript" src="../tests/to_dom_coords.js"></script>
   <script type="text/javascript" src="../tests/resize.js"></script>
+  <script type="text/javascript" src="../tests/TwoDigitYears.js"></script>
   <script type="text/javascript" src="../tests/update_options.js"></script>
   <script type="text/javascript" src="../tests/update_while_panning.js"></script>
   <script type="text/javascript" src="../tests/utils_test.js"></script>
diff --git a/auto_tests/tests/TwoDigitYears.js b/auto_tests/tests/TwoDigitYears.js
new file mode 100644 (file)
index 0000000..aeb030e
--- /dev/null
@@ -0,0 +1,22 @@
+/**
+ * @fileoverview Test to check that years < 100 get the correct ticks.
+ *
+ * @author gmadrid@gmail.com (George Madrid)
+ */
+var TwoDigitYearsTestCase = TestCase("TwoDigitYears");
+
+TwoDigitYearsTestCase.prototype.testTwoDigitYears = function() {
+  var start = new Date(9, 2, 3);
+  var end = new Date(11, 3, 5);
+
+  // Javascript will automatically add 1900 to our years if they are < 100.
+  // Use setFullYear() to get the actual years we desire.
+  start.setFullYear(9);
+  end.setFullYear(11);
+
+  var ticks = Dygraph.getDateAxis(start, end, Dygraph.QUARTERLY, function(x) {
+    return Dygraph.DEFAULT_ATTRS.axes['x'][x];
+  });
+
+  assertEquals([{"v":-61875345600000,"label":"Apr 9"},{"v":-61867483200000,"label":"Jul 9"},{"v":-61859534400000,"label":"Oct 9"},{"v":-61851582000000,"label":"Jan 10"},{"v":-61843809600000,"label":"Apr 10"},{"v":-61835947200000,"label":"Jul 10"},{"v":-61827998400000,"label":"Oct 10"},{"v":-61820046000000,"label":"Jan 11"},{"v":-61812273600000,"label":"Apr 11"}], ticks);
+};