@@ -392,7 +392,8 @@ d3.time.minute.utc = d3.time.minute;d3.time.minutes = d3_time_range(d3.time.minu
392392} ) ;
393393
394394d3 . time . minutes . utc = d3 . time . minutes ; d3 . time . hour = function ( date ) {
395- return new Date ( date . getFullYear ( ) , date . getMonth ( ) , date . getDate ( ) , date . getHours ( ) ) ;
395+ var offset = date . getTimezoneOffset ( ) / 60 ;
396+ return new Date ( ( ~ ~ ( date / 36e5 - offset ) + offset ) * 36e5 ) ;
396397} ;
397398
398399d3 . time . hour . utc = function ( date ) {
@@ -463,7 +464,7 @@ d3.time.years.utc = d3_time_range(d3.time.year.utc, function(date) {
463464 date . setUTCFullYear ( date . getUTCFullYear ( ) + 1 ) ;
464465} ) ;
465466// TODO nice
466- d3 . time . scale = function ( ) {
467+ function d3_time_scale ( methods , format ) {
467468 var linear = d3 . scale . linear ( ) ;
468469
469470 function scale ( x ) {
@@ -486,11 +487,11 @@ d3.time.scale = function() {
486487 target = span / m ;
487488 i = d3 . bisect ( d3_time_scaleSteps , target , 1 , d3_time_scaleSteps . length - 1 ) ;
488489 if ( Math . log ( target / d3_time_scaleSteps [ i - 1 ] ) < Math . log ( d3_time_scaleSteps [ i ] / target ) ) -- i ;
489- return d3_time_scaleMethods [ i ] ( extent [ 0 ] , extent [ 1 ] ) ;
490+ return methods [ i ] ( extent [ 0 ] , extent [ 1 ] ) ;
490491 } ;
491492
492493 scale . tickFormat = function ( ) {
493- return d3_time_scaleFormat ;
494+ return format ;
494495 } ;
495496
496497 // TOOD expose d3_scale_linear_rebind?
@@ -500,7 +501,7 @@ d3.time.scale = function() {
500501 scale . clamp = d3 . rebind ( scale , linear . clamp ) ;
501502
502503 return scale ;
503- } ;
504+ }
504505
505506// TODO expose d3_scaleExtent?
506507function d3_time_scaleExtent ( domain ) {
@@ -512,21 +513,13 @@ function d3_time_scaleDate(t) {
512513 return new Date ( t ) ;
513514}
514515
515- var d3_time_scaleFormats = [
516- [ d3 . time . format ( "%Y" ) , function ( d ) { return true ; } ] ,
517- [ d3 . time . format ( "%B" ) , function ( d ) { return d . getMonth ( ) ; } ] ,
518- [ d3 . time . format ( "%b %d" ) , function ( d ) { return d . getDate ( ) != 1 ; } ] ,
519- [ d3 . time . format ( "%a %d" ) , function ( d ) { return d . getDay ( ) && d . getDate ( ) != 1 ; } ] ,
520- [ d3 . time . format ( "%I %p" ) , function ( d ) { return d . getHours ( ) ; } ] ,
521- [ d3 . time . format ( "%I:%M" ) , function ( d ) { return d . getMinutes ( ) ; } ] ,
522- [ d3 . time . format ( ":%S" ) , function ( d ) { return d . getSeconds ( ) || d . getMilliseconds ( ) ; } ]
523- ] ;
524-
525- var d3_time_scaleFormat = function ( date ) {
526- var i = d3_time_scaleFormats . length - 1 , f = d3_time_scaleFormats [ i ] ;
527- while ( ! f [ 1 ] ( date ) ) f = d3_time_scaleFormats [ -- i ] ;
528- return f [ 0 ] ( date ) ;
529- } ;
516+ function d3_time_scaleFormat ( formats ) {
517+ return function ( date ) {
518+ var i = formats . length - 1 , f = formats [ i ] ;
519+ while ( ! f [ 1 ] ( date ) ) f = formats [ -- i ] ;
520+ return f [ 0 ] ( date ) ;
521+ } ;
522+ }
530523
531524var d3_time_scaleSteps = [
532525 1e3 , // 1-second
@@ -549,7 +542,7 @@ var d3_time_scaleSteps = [
549542 31536e6 // 1-year
550543] ;
551544
552- var d3_time_scaleMethods = [
545+ var d3_time_scaleLocalMethods = [
553546 d3 . time . seconds ,
554547 function ( a , b ) { return d3 . time . seconds ( a , b ) . filter ( function ( t ) { return ! ( t . getSeconds ( ) % 5 ) ; } ) ; } ,
555548 function ( a , b ) { return d3 . time . seconds ( a , b ) . filter ( function ( t ) { return ! ( t . getSeconds ( ) % 15 ) ; } ) ; } ,
@@ -570,9 +563,55 @@ var d3_time_scaleMethods = [
570563 d3 . time . years
571564] ;
572565
573- function d3_time_scaleFilter ( method , filter ) {
574- return function ( a , b ) {
575- return method ( a , b ) . filter ( filter ) ;
576- } ;
577- }
566+ var d3_time_scaleLocalFormats = [
567+ [ d3 . time . format ( "%Y" ) , function ( d ) { return true ; } ] ,
568+ [ d3 . time . format ( "%B" ) , function ( d ) { return d . getMonth ( ) ; } ] ,
569+ [ d3 . time . format ( "%b %d" ) , function ( d ) { return d . getDate ( ) != 1 ; } ] ,
570+ [ d3 . time . format ( "%a %d" ) , function ( d ) { return d . getDay ( ) && d . getDate ( ) != 1 ; } ] ,
571+ [ d3 . time . format ( "%I %p" ) , function ( d ) { return d . getHours ( ) ; } ] ,
572+ [ d3 . time . format ( "%I:%M" ) , function ( d ) { return d . getMinutes ( ) ; } ] ,
573+ [ d3 . time . format ( ":%S" ) , function ( d ) { return d . getSeconds ( ) || d . getMilliseconds ( ) ; } ]
574+ ] ;
575+
576+ var d3_time_scaleLocalFormat = d3_time_scaleFormat ( d3_time_scaleLocalFormats ) ;
577+
578+ d3 . time . scale = function ( ) {
579+ return d3_time_scale ( d3_time_scaleLocalMethods , d3_time_scaleLocalFormat ) ;
580+ } ;
581+ var d3_time_scaleUTCMethods = [
582+ d3 . time . seconds . utc ,
583+ function ( a , b ) { return d3 . time . seconds . utc ( a , b ) . filter ( function ( t ) { return ! ( t . getUTCSeconds ( ) % 5 ) ; } ) ; } ,
584+ function ( a , b ) { return d3 . time . seconds . utc ( a , b ) . filter ( function ( t ) { return ! ( t . getUTCSeconds ( ) % 15 ) ; } ) ; } ,
585+ function ( a , b ) { return d3 . time . seconds . utc ( a , b ) . filter ( function ( t ) { return ! ( t . getUTCSeconds ( ) % 30 ) ; } ) ; } ,
586+ d3 . time . minutes . utc ,
587+ function ( a , b ) { return d3 . time . minutes . utc ( a , b ) . filter ( function ( t ) { return ! ( t . getUTCMinutes ( ) % 5 ) ; } ) ; } ,
588+ function ( a , b ) { return d3 . time . minutes . utc ( a , b ) . filter ( function ( t ) { return ! ( t . getUTCMinutes ( ) % 15 ) ; } ) ; } ,
589+ function ( a , b ) { return d3 . time . minutes . utc ( a , b ) . filter ( function ( t ) { return ! ( t . getUTCMinutes ( ) % 30 ) ; } ) ; } ,
590+ d3 . time . hours . utc ,
591+ function ( a , b ) { return d3 . time . hours . utc ( a , b ) . filter ( function ( t ) { return ! ( t . getUTCHours ( ) % 3 ) ; } ) ; } ,
592+ function ( a , b ) { return d3 . time . hours . utc ( a , b ) . filter ( function ( t ) { return ! ( t . getUTCHours ( ) % 6 ) ; } ) ; } ,
593+ function ( a , b ) { return d3 . time . hours . utc ( a , b ) . filter ( function ( t ) { return ! ( t . getUTCHours ( ) % 12 ) ; } ) ; } ,
594+ d3 . time . days . utc ,
595+ function ( a , b ) { return d3 . time . days . utc ( a , b ) . filter ( function ( t ) { return t . getUTCDate ( ) % 2 ; } ) ; } ,
596+ d3 . time . weeks . utc ,
597+ d3 . time . months . utc ,
598+ function ( a , b ) { return d3 . time . months . utc ( a , b ) . filter ( function ( t ) { return ! ( t . getUTCMonth ( ) % 3 ) ; } ) ; } ,
599+ d3 . time . years . utc
600+ ] ;
601+
602+ var d3_time_scaleUTCFormats = [
603+ [ d3 . time . format . utc ( "%Y" ) , function ( d ) { return true ; } ] ,
604+ [ d3 . time . format . utc ( "%B" ) , function ( d ) { return d . getUTCMonth ( ) ; } ] ,
605+ [ d3 . time . format . utc ( "%b %d" ) , function ( d ) { return d . getUTCDate ( ) != 1 ; } ] ,
606+ [ d3 . time . format . utc ( "%a %d" ) , function ( d ) { return d . getUTCDay ( ) && d . getUTCDate ( ) != 1 ; } ] ,
607+ [ d3 . time . format . utc ( "%I %p" ) , function ( d ) { return d . getUTCHours ( ) ; } ] ,
608+ [ d3 . time . format . utc ( "%I:%M" ) , function ( d ) { return d . getUTCMinutes ( ) ; } ] ,
609+ [ d3 . time . format . utc ( ":%S" ) , function ( d ) { return d . getUTCSeconds ( ) || d . getUTCMilliseconds ( ) ; } ]
610+ ] ;
611+
612+ var d3_time_scaleUTCFormat = d3_time_scaleFormat ( d3_time_scaleUTCFormats ) ;
613+
614+ d3 . time . scale . utc = function ( ) {
615+ return d3_time_scale ( d3_time_scaleUTCMethods , d3_time_scaleUTCFormat ) ;
616+ } ;
578617} ) ( ) ;
0 commit comments