date_format-test.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. "use strict";
  2. var vows = require('vows')
  3. , assert = require('assert')
  4. , dateFormat = require('../lib/date_format');
  5. vows.describe('date_format').addBatch({
  6. 'Date extensions': {
  7. topic: function() {
  8. return new Date(2010, 0, 11, 14, 31, 30, 5);
  9. },
  10. 'should format a date as string using a pattern': function(date) {
  11. assert.equal(
  12. dateFormat.asString(dateFormat.DATETIME_FORMAT, date),
  13. "11 01 2010 14:31:30.005"
  14. );
  15. },
  16. 'should default to the ISO8601 format': function(date) {
  17. assert.equal(
  18. dateFormat.asString(date),
  19. '2010-01-11 14:31:30.005'
  20. );
  21. },
  22. 'should provide a ISO8601 with timezone offset format': function(date) {
  23. date.getTimezoneOffset = function() { return -660; };
  24. assert.equal(
  25. dateFormat.asString(dateFormat.ISO8601_WITH_TZ_OFFSET_FORMAT, date),
  26. "2010-01-11T14:31:30+1100"
  27. );
  28. date.getTimezoneOffset = function() { return 120; };
  29. assert.equal(
  30. dateFormat.asString(dateFormat.ISO8601_WITH_TZ_OFFSET_FORMAT, date),
  31. "2010-01-11T14:31:30-0200"
  32. );
  33. },
  34. 'should provide a just-the-time format': function(date) {
  35. assert.equal(
  36. dateFormat.asString(dateFormat.ABSOLUTETIME_FORMAT, date),
  37. '14:31:30.005'
  38. );
  39. }
  40. }
  41. }).export(module);