From: Dan Vanderkam Date: Tue, 4 Nov 2014 22:42:07 +0000 (-0500) Subject: cleanup X-Git-Tag: v1.1.0~31^2~1 X-Git-Url: https://adrianiainlam.tk/git/?a=commitdiff_plain;h=f1ec8cf5aedd62613b954803cb48aaa0a065dc32;p=dygraphs.git cleanup --- 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) {