timeRange.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /**
  2. * Module dependencies.
  3. */
  4. var assert = require('assert');
  5. var timeRange = require('../timeRange');
  6. var vanillaGetHours = Date.prototype.getHours;
  7. var vanillaGetMinutes = Date.prototype.getMinutes;
  8. var vanillaGetSeconds = Date.prototype.getSeconds;
  9. var vanillaGetUTCHours = Date.prototype.getUTCHours;
  10. var vanillaGetUTCMinutes = Date.prototype.getUTCMinutes;
  11. var vanillaGetUTCSeconds = Date.prototype.getUTCSeconds;
  12. describe('hooks', function() {
  13. before(function() {
  14. // Setting local time as 01:24:30
  15. Date.prototype.getHours = function() { return 1; }
  16. Date.prototype.getMinutes = function() { return 24; }
  17. Date.prototype.getSeconds = function() { return 30; }
  18. // Setting UTC time as 19:54:30
  19. Date.prototype.getUTCHours = function() { return 19; }
  20. Date.prototype.getUTCMinutes = function() { return 54; }
  21. Date.prototype.getUTCSeconds = function() { return 30; }
  22. });
  23. after(function() {
  24. Date.prototype.getHours = vanillaGetHours;
  25. Date.prototype.getUTCHours = vanillaGetUTCHours;
  26. Date.prototype.getUTCMinutes = vanillaGetUTCMinutes;
  27. Date.prototype.getUTCSeconds = vanillaGetUTCSeconds;
  28. });
  29. describe('timeRange()', function () {
  30. var tests = [
  31. [1, true],
  32. [1, 2, true],
  33. [0, 0, 0, 30, false],
  34. [0, 0, 0, 0, 30, 0, false],
  35. [0, 0, 0, 0, 30, 0, 'GMT', false],
  36. [0, 0, 0, 20, 0, 0, 'GMT', true],
  37. ];
  38. tests.forEach(function (test) {
  39. var expected = test.pop();
  40. it('should return `' + expected +'` for "' + test.join('", "') + '"', function () {
  41. assert.equal(expected, timeRange.apply(this, test));
  42. });
  43. });
  44. });
  45. });