time.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // Node
  2. if (typeof module !== 'undefined' && module.exports) {
  3. var numeral = require('../../numeral');
  4. var expect = require('chai').expect;
  5. }
  6. describe('Time', function() {
  7. after(function() {
  8. numeral.reset();
  9. });
  10. it('should format to time', function() {
  11. var tests = [
  12. [0,'00:00:00','0:00:00'],
  13. [null,'00:00:00','0:00:00'],
  14. [25,'00:00:00','0:00:25'],
  15. [238,'00:00:00','0:03:58'],
  16. [63846,'00:00:00','17:44:06']
  17. ],
  18. i;
  19. for (i = 0; i < tests.length; i++) {
  20. expect(numeral(tests[i][0]).format(tests[i][1])).to.equal(tests[i][2]);
  21. }
  22. });
  23. it('should unformat to time', function() {
  24. var tests = [
  25. ['0:00:00', 0],
  26. ['0:00:25', 25],
  27. ['0:03:58', 238],
  28. ['17:44:06', 63846]
  29. ],
  30. i;
  31. for (i = 0; i < tests.length; i++) {
  32. expect(numeral(tests[i][0]).value()).to.equal(tests[i][1]);
  33. }
  34. });
  35. });