1c0fe8c89ec7155e9bd3a3f3891282032d85dae7b08034eb9fb85a7a20de71f7b2e92f02b5fdb350796ba64695f5578b01915ee519a4217fe502c48231be70 1.6 KB

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