File: time.js

package info (click to toggle)
d3 3.5.17-4
  • links: PTS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 11,464 kB
  • sloc: javascript: 43,334; makefile: 8; xml: 4
file content (30 lines) | stat: -rw-r--r-- 942 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
var offset = 0;

exports.local = function(year, month, day, hours, minutes, seconds, milliseconds) {
  var date = new Date;
  date.setFullYear(year, month, day);
  date.setHours(hours || 0, offset + (minutes || 0), seconds || 0, milliseconds || 0);
  return date;
};

exports.utc = function(year, month, day, hours, minutes, seconds, milliseconds) {
  var date = new Date;
  date.setUTCFullYear(year, month, day);
  date.setUTCHours(hours || 0, minutes || 0, seconds || 0, milliseconds || 0);
  return date;
};

exports.zone = function(tzOffset, scope) {
  return function() {
    var o = Date.prototype.getTimezoneOffset;
    try {
      // Note: assumes the dates are not in DST.
      offset = -tzOffset - new Date(0).getTimezoneOffset();
      Date.prototype.getTimezoneOffset = function() { return offset; };
      scope.apply(this, arguments);
    } finally {
      offset = 0;
      Date.prototype.getTimezoneOffset = o;
    }
  };
};