score:14

Accepted answer

the problem is simply that you are logging date objects to the console, and your browser is applying default formatting to those objects to convert them to your local time zone.

using d3.time.scale.utc() doesn't change the date objects. javascript date objects are always stored internally as numbers of milliseconds since 1970.

what is unique about the utc scale is the tickformat function, which uses a utc time formatter by default. however, the tick format function doesn't affect logging to console, only when you're actually drawing the ticks as labels!

the following fiddle actually uses the tick formatting function of each scale to format the date objects logged to the console:
http://jsfiddle.net/qe9ur/1/

var start = new date("mon oct 21 2013 00:00:00 gmt+0100 (bst)");
var end = new date("mon dec 02 2013 00:00:00 gmt+0000 (gmt)")

var xscale = d3.time.scale.utc()
    .domain([start, end])
    .range([0, 800]);
var xticks =  xscale.ticks(d3.time.mondays, 1);

console.log( xticks.map( xscale.tickformat() ) );

var yscale = d3.time.scale()
    .domain([start, end])
    .range([0, 800]);
var yticks = yscale.ticks(d3.time.mondays, 1);

console.log(yticks.map( yscale.tickformat() ) );

however, you'll discover another problem (assuming you're not in a gmt timezone). the default formatting function for a time scale is a multi-format: if values aren't for midnight, it will return the time instead of the date. when you specify the ticks as mondays, it still calculates them as midnight monday in your current timezone, which for me is 6 or 7 hours off of utc.

that's why there are utc versions of all the time interval functions, as well. changing the ticks specification to

var xticks =  xscale.ticks(d3.time.mondays.utc, 1);

gets the tick values to fall at midnight utc: http://jsfiddle.net/qe9ur/2/

all that said, you'll still probably want to specify a custom tick formatter. the day of the week + day of the month format doesn't really work when you're scanning through multiple months on mondays only.


Related Query

More Query from same tag