333
schangxiang@126.com
2025-09-19 18966e02fb573c7e2bb0c6426ed792b38b910940
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
 
/**
 * Module dependencies.
 */
 
var assert = require('assert');
var timeRange = require('../timeRange');
var vanillaGetHours = Date.prototype.getHours;
var vanillaGetMinutes = Date.prototype.getMinutes;
var vanillaGetSeconds = Date.prototype.getSeconds;
var vanillaGetUTCHours = Date.prototype.getUTCHours;
var vanillaGetUTCMinutes = Date.prototype.getUTCMinutes;
var vanillaGetUTCSeconds = Date.prototype.getUTCSeconds;
 
describe('hooks', function() {
 
  before(function() {
    // Setting local time as 01:24:30
    Date.prototype.getHours = function() { return 1; }
    Date.prototype.getMinutes = function() { return 24; }
    Date.prototype.getSeconds = function() { return 30; }
 
    // Setting UTC time as 19:54:30
    Date.prototype.getUTCHours = function() { return 19; }
    Date.prototype.getUTCMinutes = function() { return 54; }
    Date.prototype.getUTCSeconds = function() { return 30; }
  });
 
  after(function() {
    Date.prototype.getHours = vanillaGetHours;
    Date.prototype.getUTCHours = vanillaGetUTCHours;
    Date.prototype.getUTCMinutes = vanillaGetUTCMinutes;
    Date.prototype.getUTCSeconds = vanillaGetUTCSeconds;
  });
 
 
  describe('timeRange()', function () {
 
 
    var tests = [
      [1, true],
      [1, 2, true],
      [0, 0, 0, 30, false],
      [0, 0, 0, 0, 30, 0, false],
      [0, 0, 0, 0, 30, 0, 'GMT', false],
      [0, 0, 0, 20, 0, 0, 'GMT', true],
    ];
 
    tests.forEach(function (test) {
      var expected = test.pop();
      it('should return `' + expected +'` for "' + test.join('", "') + '"', function () {
        assert.equal(expected, timeRange.apply(this, test));
      });
    });
 
  });
});