Debian Codegraph @

vendor/static/moment/src/lib/units/millisecond.js

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