<script type="text/javascript" src="../tests/date_formats.js"></script>
<script type="text/javascript" src="../tests/formats.js"></script>
<script type="text/javascript" src="../tests/update_while_panning.js"></script>
+ <script type="text/javascript" src="../tests/no_hours.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 we don'show specify hours, minutes or seconds
+ * in your dates if you don't specify them. This can get mixed up becaues of
+ * time zones.
+ *
+ * @author danvk@google.com (Dan Vanderkam)
+ */
+var noHoursTestCase = TestCase("no-hours");
+
+noHoursTestCase.prototype.setUp = function() {
+ document.body.innerHTML = "<div id='graph'></div>";
+};
+
+noHoursTestCase.prototype.tearDown = function() {
+};
+
+function getLegend() {
+ var legend = document.getElementsByClassName("dygraph-legend")[0];
+ return legend.textContent;
+}
+
+noHoursTestCase.prototype.testNoHours = function() {
+ var opts = {
+ width: 480,
+ height: 320
+ };
+ var data = "Date,Y\n" +
+ "2012/03/13,-1\n" +
+ "2012/03/14,0\n" +
+ "2012/03/15,1\n" +
+ "2012/03/16,0\n"
+ ;
+
+ var graph = document.getElementById("graph");
+ var g = new Dygraph(graph, data, opts);
+
+ g.setSelection(0);
+ assertEquals("2012/03/13: Y:-1", getLegend());
+
+ g.setSelection(1);
+ assertEquals("2012/03/14: Y:0", getLegend());
+
+ g.setSelection(2);
+ assertEquals("2012/03/15: Y:1", getLegend());
+
+ g.setSelection(3);
+ assertEquals("2012/03/16: Y:0", getLegend());
+};
+
+noHoursTestCase.prototype.testNoHoursDashed = function() {
+ var opts = {
+ width: 480,
+ height: 320
+ };
+ var data = "Date,Y\n" +
+ "2012-03-13,-1\n" +
+ "2012-03-14,0\n" +
+ "2012-03-15,1\n" +
+ "2012-03-16,0\n"
+ ;
+
+ var graph = document.getElementById("graph");
+ var g = new Dygraph(graph, data, opts);
+
+ g.setSelection(0);
+ assertEquals("2012/03/13: Y:-1", getLegend());
+
+ g.setSelection(1);
+ assertEquals("2012/03/14: Y:0", getLegend());
+
+ g.setSelection(2);
+ assertEquals("2012/03/15: Y:1", getLegend());
+
+ g.setSelection(3);
+ assertEquals("2012/03/16: Y:0", getLegend());
+};
+
var dateStrSlashed;
var d;
- // Let the system try the format first.
- d = Dygraph.dateStrToMillis(dateStr);
- if (d && !isNaN(d)) return d;
+ // Let the system try the format first, with one caveat:
+ // YYYY-MM-DD[ HH:MM:SS] is interpreted as UTC by a variety of browsers.
+ // dygraphs displays dates in local time, so this will result in surprising
+ // inconsistencies. But if you specify "T" or "Z" (i.e. YYYY-MM-DDTHH:MM:SS),
+ // then you probably know what you're doing, so we'll let you go ahead.
+ // Issue: http://code.google.com/p/dygraphs/issues/detail?id=255
+ if (dateStr.search("-") == -1 ||
+ dateStr.search("T") != -1 || dateStr.search("Z") != -1) {
+ 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");