From f1ec8cf5aedd62613b954803cb48aaa0a065dc32 Mon Sep 17 00:00:00 2001 From: Dan Vanderkam Date: Tue, 4 Nov 2014 17:42:07 -0500 Subject: [PATCH] cleanup --- auto_tests/tests/date_ticker.js | 1 - dygraph.js | 30 +++++++++++------------------- 2 files changed, 11 insertions(+), 20 deletions(-) diff --git a/auto_tests/tests/date_ticker.js b/auto_tests/tests/date_ticker.js index e30a4ff..452db8a 100644 --- a/auto_tests/tests/date_ticker.js +++ b/auto_tests/tests/date_ticker.js @@ -28,7 +28,6 @@ DateTickerTestCase.prototype.createOptionsViewForAxis = function(axis, dict) { }; }; -// Broken, since it assumes EST. DateTickerTestCase.prototype.testBasicDateTicker = function() { var opts = {labelsDateUTC: true}; var options = this.createOptionsViewForAxis('x', opts); diff --git a/dygraph.js b/dygraph.js index 3447493..7dd68a9 100644 --- a/dygraph.js +++ b/dygraph.js @@ -212,28 +212,20 @@ Dygraph.SHORT_MONTH_NAMES_ = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', ' */ Dygraph.dateAxisLabelFormatter = function(date, granularity, opts) { var utc = opts('labelsDateUTC'); - var year, month, day, hours, mins, secs, millis; - if (utc) { - year = date.getUTCFullYear(); - month = date.getUTCMonth(); - day = date.getUTCDate(); - hours = date.getUTCHours(); - mins = date.getUTCMinutes(); - secs = date.getUTCSeconds(); - millis = date.getUTCMilliseconds(); - } else { - year = date.getFullYear(); - month = date.getMonth(); - day = date.getDate(); - hours = date.getHours(); - mins = date.getMinutes(); - secs = date.getSeconds(); - millis = date.getMilliseconds(); - } + var accessors = utc ? Dygraph.DateAccessorsUTC : Dygraph.DateAccessorsLocal; + + var year = accessors.getFullYear(date), + month = accessors.getMonth(date), + day = accessors.getDate(date), + hours = accessors.getHours(date), + mins = accessors.getMinutes(date), + secs = accessors.getSeconds(date), + millis = accessors.getSeconds(date); + if (granularity >= Dygraph.DECADAL) { return '' + year; } else if (granularity >= Dygraph.MONTHLY) { - return Dygraph.SHORT_MONTH_NAMES_[month] + ' ' + Dygraph.zeropad(year); + return Dygraph.SHORT_MONTH_NAMES_[month] + ' ' + year; } else { var frac = hours * 3600 + mins * 60 + secs + 1e-3 * millis; if (frac === 0 || granularity >= Dygraph.DAILY) { -- 2.7.4