toolkit/javascript/d3/test/time/month-test.js
changeset 47 c0b4a8b5a012
equal deleted inserted replaced
46:efd9c589177a 47:c0b4a8b5a012
       
     1 require("../env");
       
     2 require("../../d3");
       
     3 require("../../d3.time");
       
     4 
       
     5 var vows = require("vows"),
       
     6     assert = require("assert");
       
     7 
       
     8 var suite = vows.describe("d3.time.month");
       
     9 
       
    10 suite.addBatch({
       
    11   "month": {
       
    12     topic: function() {
       
    13       return d3.time.month;
       
    14     },
       
    15     "returns months": function(floor) {
       
    16       assert.deepEqual(floor(local(2010, 11, 31, 23, 59, 59)), local(2010, 11, 1));
       
    17       assert.deepEqual(floor(local(2011, 0, 1, 0, 0, 0)), local(2011, 0, 1));
       
    18       assert.deepEqual(floor(local(2011, 0, 1, 0, 0, 1)), local(2011, 0, 1));
       
    19     },
       
    20     "observes the start of daylight savings time": function(floor) {
       
    21       assert.deepEqual(floor(local(2011, 2, 13, 1)), local(2011, 2, 1));
       
    22     },
       
    23     "observes the end of the daylight savings time": function(floor) {
       
    24       assert.deepEqual(floor(local(2011, 10, 6, 1)), local(2011, 10, 1));
       
    25     },
       
    26     "UTC": {
       
    27       topic: function(floor) {
       
    28         return floor.utc;
       
    29       },
       
    30       "returns months": function(floor) {
       
    31         assert.deepEqual(floor(utc(2010, 11, 31, 23, 59, 59)), utc(2010, 11, 1));
       
    32         assert.deepEqual(floor(utc(2011, 0, 1, 0, 0, 0)), utc(2011, 0, 1));
       
    33         assert.deepEqual(floor(utc(2011, 0, 1, 0, 0, 1)), utc(2011, 0, 1));
       
    34       },
       
    35       "does not observe the start of daylight savings time": function(floor) {
       
    36         assert.deepEqual(floor(utc(2011, 2, 13, 1)), utc(2011, 2, 1));
       
    37       },
       
    38       "does not observe the end of the daylight savings time": function(floor) {
       
    39         assert.deepEqual(floor(utc(2011, 10, 6, 1)), utc(2011, 10, 1));
       
    40       }
       
    41     }
       
    42   }
       
    43 });
       
    44 
       
    45 function local(year, month, day, hours, minutes, seconds) {
       
    46   return new Date(year, month, day, hours || 0, minutes || 0, seconds || 0);
       
    47 }
       
    48 
       
    49 function utc(year, month, day, hours, minutes, seconds) {
       
    50   return new Date(Date.UTC(year, month, day, hours || 0, minutes || 0, seconds || 0));
       
    51 }
       
    52 
       
    53 suite.export(module);