PageRenderTime 32ms CodeModel.GetById 21ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

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