<script type="text/javascript" src="../tests/annotations.js"></script>
<script type="text/javascript" src="../tests/scientific_notation.js"></script>
<script type="text/javascript" src="../tests/pathological_cases.js"></script>
+ <script type="text/javascript" src="../tests/date_formats.js"></script>
<script type="text/javascript" src="../tests/update_options.js"></script>
<script type="text/javascript" src="../tests/utils_test.js"></script>
<script type="text/javascript" src="../tests/multiple_axes.js"></script>
--- /dev/null
+/**
+ * @fileoverview Tests that various formats of date are understood by dygraphs.
+ *
+ * @author dan@dygraphs.com (Dan Vanderkam)
+ */
+var dateFormatsTestCase = TestCase("date-formats");
+
+dateFormatsTestCase.prototype.setUp = function() {
+};
+
+dateFormatsTestCase.prototype.tearDown = function() {
+};
+
+dateFormatsTestCase.prototype.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.
+ assertEquals(946816496789, Dygraph.dateParser("2000-01-02T12:34:56.789012Z"));
+};
+
+dateFormatsTestCase.prototype.testHyphenatedDate = function() {
+ // Format: YYYY-MM-DD HH:MM
+
+ // Midnight February 2, 2000, UTC
+ var d = new Date(Date.UTC(2000, 1, 2));
+
+ // Convert to a string in the local time zone: YYYY-DD-MM HH:MM
+ var zp = function(x) { return x < 10 ? '0' + x : x; };
+ var str = d.getFullYear() + '-' +
+ zp(1 + d.getMonth()) + '-' +
+ zp(d.getDate()) + ' ' +
+ zp(d.getHours()) + ':' +
+ zp(d.getMinutes());
+ assertEquals(Date.UTC(2000, 1, 2), Dygraph.dateParser(str));
+};
Dygraph.dateParser = function(dateStr) {
var dateStrSlashed;
var d;
+
+ // Let the system try the format first.
+ d = Dygraph.dateStrToMillis(dateStr);
+ if (d && !isNaN(d)) return d;
+
if (dateStr.search("-") != -1) { // e.g. '2009-7-12' or '2009-07-12'
dateStrSlashed = dateStr.replace("-", "/", "g");
while (dateStrSlashed.search("-") != -1) {
/**
* Returns the full range of the x-axis, as determined by the most extreme
* values in the data set. Not affected by zooming, visibility, etc.
+ * TODO(danvk): merge w/ xAxisExtremes
* @return { Array<Number> } A [low, high] pair
* @private
*/