date.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * Utilities: A classic collection of JavaScript utilities
  3. * Copyright 2112 Matthew Eernisse ([email protected])
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. *
  17. */
  18. var date = require('../lib/date')
  19. , assert = require('assert')
  20. , tests = {}
  21. , _date = new Date();
  22. tests = {
  23. 'test strftime for date': function () {
  24. var data = date.strftime(_date, "%w")
  25. , actual = _date.getDay();
  26. assert.equal(actual, data);
  27. }
  28. , 'test calcCentury using current year for date': function () {
  29. var data = date.calcCentury()
  30. , actual = '21';
  31. assert.equal(actual, data);
  32. }
  33. , 'test calcCentury using 20th century year for date': function () {
  34. var data = date.calcCentury(2000)
  35. , actual = '20';
  36. assert.equal(actual, data);
  37. }
  38. , 'test calcCentury using 1st century year for date': function () {
  39. var data = date.calcCentury(10)
  40. , actual = '1';
  41. assert.equal(actual, data);
  42. }
  43. , 'test getMeridiem for date': function () {
  44. var data = date.getMeridiem(_date.getHours())
  45. , actual = (_date.getHours() > 11) ? 'PM' : 'AM';
  46. assert.equal(actual, data);
  47. }
  48. , 'test parse UTC': function () {
  49. var dt = date.parse('1970-01-01T00:00:00Z');
  50. assert.equal(0, dt.getTime());
  51. }
  52. , 'test parse with offset basic': function () {
  53. var dt;
  54. dt = date.parse('1970-01-01T00:00:00-0100');
  55. assert.equal(3600000, dt.getTime());
  56. dt = date.parse('1970-01-01T00:00:00+0100');
  57. assert.equal(-3600000, dt.getTime());
  58. }
  59. , 'test parse with offset extended': function () {
  60. var dt;
  61. dt = date.parse('1970-01-01T00:00:00-01:00');
  62. assert.equal(3600000, dt.getTime());
  63. dt = date.parse('1970-01-01T00:00:00+01:00');
  64. assert.equal(-3600000, dt.getTime());
  65. }
  66. , 'test parse floating (i.e., local offset)': function () {
  67. var dt;
  68. dt = date.parse('1970-01-01T00:00:00');
  69. assert.equal(dt.getTime() / 1000 / 60, dt.getTimezoneOffset());
  70. }
  71. };
  72. module.exports = tests;