corrade-nucleus-nucleons – Blame information for rev 38
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
38 | office | 1 | import isArray from '../utils/is-array'; |
2 | import isObject from '../utils/is-object'; |
||
3 | import isObjectEmpty from '../utils/is-object-empty'; |
||
4 | import isUndefined from '../utils/is-undefined'; |
||
5 | import isNumber from '../utils/is-number'; |
||
6 | import isDate from '../utils/is-date'; |
||
7 | import map from '../utils/map'; |
||
8 | import { createInvalid } from './valid'; |
||
9 | import { Moment, isMoment } from '../moment/constructor'; |
||
10 | import { getLocale } from '../locale/locales'; |
||
11 | import { hooks } from '../utils/hooks'; |
||
12 | import checkOverflow from './check-overflow'; |
||
13 | import { isValid } from './valid'; |
||
14 | |||
15 | import { configFromStringAndArray } from './from-string-and-array'; |
||
16 | import { configFromStringAndFormat } from './from-string-and-format'; |
||
17 | import { configFromString } from './from-string'; |
||
18 | import { configFromArray } from './from-array'; |
||
19 | import { configFromObject } from './from-object'; |
||
20 | |||
21 | function createFromConfig (config) { |
||
22 | var res = new Moment(checkOverflow(prepareConfig(config))); |
||
23 | if (res._nextDay) { |
||
24 | // Adding is smart enough around DST |
||
25 | res.add(1, 'd'); |
||
26 | res._nextDay = undefined; |
||
27 | } |
||
28 | |||
29 | return res; |
||
30 | } |
||
31 | |||
32 | export function prepareConfig (config) { |
||
33 | var input = config._i, |
||
34 | format = config._f; |
||
35 | |||
36 | config._locale = config._locale || getLocale(config._l); |
||
37 | |||
38 | if (input === null || (format === undefined && input === '')) { |
||
39 | return createInvalid({nullInput: true}); |
||
40 | } |
||
41 | |||
42 | if (typeof input === 'string') { |
||
43 | config._i = input = config._locale.preparse(input); |
||
44 | } |
||
45 | |||
46 | if (isMoment(input)) { |
||
47 | return new Moment(checkOverflow(input)); |
||
48 | } else if (isDate(input)) { |
||
49 | config._d = input; |
||
50 | } else if (isArray(format)) { |
||
51 | configFromStringAndArray(config); |
||
52 | } else if (format) { |
||
53 | configFromStringAndFormat(config); |
||
54 | } else { |
||
55 | configFromInput(config); |
||
56 | } |
||
57 | |||
58 | if (!isValid(config)) { |
||
59 | config._d = null; |
||
60 | } |
||
61 | |||
62 | return config; |
||
63 | } |
||
64 | |||
65 | function configFromInput(config) { |
||
66 | var input = config._i; |
||
67 | if (isUndefined(input)) { |
||
68 | config._d = new Date(hooks.now()); |
||
69 | } else if (isDate(input)) { |
||
70 | config._d = new Date(input.valueOf()); |
||
71 | } else if (typeof input === 'string') { |
||
72 | configFromString(config); |
||
73 | } else if (isArray(input)) { |
||
74 | config._a = map(input.slice(0), function (obj) { |
||
75 | return parseInt(obj, 10); |
||
76 | }); |
||
77 | configFromArray(config); |
||
78 | } else if (isObject(input)) { |
||
79 | configFromObject(config); |
||
80 | } else if (isNumber(input)) { |
||
81 | // from milliseconds |
||
82 | config._d = new Date(input); |
||
83 | } else { |
||
84 | hooks.createFromInputFallback(config); |
||
85 | } |
||
86 | } |
||
87 | |||
88 | export function createLocalOrUTC (input, format, locale, strict, isUTC) { |
||
89 | var c = {}; |
||
90 | |||
91 | if (locale === true || locale === false) { |
||
92 | strict = locale; |
||
93 | locale = undefined; |
||
94 | } |
||
95 | |||
96 | if ((isObject(input) && isObjectEmpty(input)) || |
||
97 | (isArray(input) && input.length === 0)) { |
||
98 | input = undefined; |
||
99 | } |
||
100 | // object construction must be done this way. |
||
101 | // https://github.com/moment/moment/issues/1423 |
||
102 | c._isAMomentObject = true; |
||
103 | c._useUTC = c._isUTC = isUTC; |
||
104 | c._l = locale; |
||
105 | c._i = input; |
||
106 | c._f = format; |
||
107 | c._strict = strict; |
||
108 | |||
109 | return createFromConfig(c); |
||
110 | } |