/node_modules/moment/src/lib/units/millisecond.js

https://bitbucket.org/coleman333/smartsite · JavaScript · 69 lines · 49 code · 15 blank · 5 comment · 2 complexity · 10467099e7de9dd25c216cef85eafc27 MD5 · raw file

  1. import { makeGetSet } from '../moment/get-set';
  2. import { addFormatToken } from '../format/format';
  3. import { addUnitAlias } from './aliases';
  4. import { addUnitPriority } from './priorities';
  5. import { addRegexToken, match1, match2, match3, match1to3, matchUnsigned } from '../parse/regex';
  6. import { addParseToken } from '../parse/token';
  7. import { MILLISECOND } from './constants';
  8. import toInt from '../utils/to-int';
  9. // FORMATTING
  10. addFormatToken('S', 0, 0, function () {
  11. return ~~(this.millisecond() / 100);
  12. });
  13. addFormatToken(0, ['SS', 2], 0, function () {
  14. return ~~(this.millisecond() / 10);
  15. });
  16. addFormatToken(0, ['SSS', 3], 0, 'millisecond');
  17. addFormatToken(0, ['SSSS', 4], 0, function () {
  18. return this.millisecond() * 10;
  19. });
  20. addFormatToken(0, ['SSSSS', 5], 0, function () {
  21. return this.millisecond() * 100;
  22. });
  23. addFormatToken(0, ['SSSSSS', 6], 0, function () {
  24. return this.millisecond() * 1000;
  25. });
  26. addFormatToken(0, ['SSSSSSS', 7], 0, function () {
  27. return this.millisecond() * 10000;
  28. });
  29. addFormatToken(0, ['SSSSSSSS', 8], 0, function () {
  30. return this.millisecond() * 100000;
  31. });
  32. addFormatToken(0, ['SSSSSSSSS', 9], 0, function () {
  33. return this.millisecond() * 1000000;
  34. });
  35. // ALIASES
  36. addUnitAlias('millisecond', 'ms');
  37. // PRIORITY
  38. addUnitPriority('millisecond', 16);
  39. // PARSING
  40. addRegexToken('S', match1to3, match1);
  41. addRegexToken('SS', match1to3, match2);
  42. addRegexToken('SSS', match1to3, match3);
  43. var token;
  44. for (token = 'SSSS'; token.length <= 9; token += 'S') {
  45. addRegexToken(token, matchUnsigned);
  46. }
  47. function parseMs(input, array) {
  48. array[MILLISECOND] = toInt(('0.' + input) * 1000);
  49. }
  50. for (token = 'S'; token.length <= 9; token += 'S') {
  51. addParseToken(token, parseMs);
  52. }
  53. // MOMENTS
  54. export var getSetMillisecond = makeGetSet('Milliseconds', false);