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