corrade-nucleus-nucleons – Blame information for rev 10
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
10 | office | 1 | import { configFromStringAndFormat } from './from-string-and-format'; |
2 | import { hooks } from '../utils/hooks'; |
||
3 | import { deprecate } from '../utils/deprecate'; |
||
4 | import getParsingFlags from './parsing-flags'; |
||
5 | |||
6 | // iso 8601 regex |
||
7 | // 0000-00-00 0000-W00 or 0000-W00-0 + T + 00 or 00:00 or 00:00:00 or 00:00:00.000 + +00:00 or +0000 or +00) |
||
8 | var extendedIsoRegex = /^\s*((?:[+-]\d{6}|\d{4})-(?:\d\d-\d\d|W\d\d-\d|W\d\d|\d\d\d|\d\d))(?:(T| )(\d\d(?::\d\d(?::\d\d(?:[.,]\d+)?)?)?)([\+\-]\d\d(?::?\d\d)?|\s*Z)?)?$/; |
||
9 | var basicIsoRegex = /^\s*((?:[+-]\d{6}|\d{4})(?:\d\d\d\d|W\d\d\d|W\d\d|\d\d\d|\d\d))(?:(T| )(\d\d(?:\d\d(?:\d\d(?:[.,]\d+)?)?)?)([\+\-]\d\d(?::?\d\d)?|\s*Z)?)?$/; |
||
10 | |||
11 | var tzRegex = /Z|[+-]\d\d(?::?\d\d)?/; |
||
12 | |||
13 | var isoDates = [ |
||
14 | ['YYYYYY-MM-DD', /[+-]\d{6}-\d\d-\d\d/], |
||
15 | ['YYYY-MM-DD', /\d{4}-\d\d-\d\d/], |
||
16 | ['GGGG-[W]WW-E', /\d{4}-W\d\d-\d/], |
||
17 | ['GGGG-[W]WW', /\d{4}-W\d\d/, false], |
||
18 | ['YYYY-DDD', /\d{4}-\d{3}/], |
||
19 | ['YYYY-MM', /\d{4}-\d\d/, false], |
||
20 | ['YYYYYYMMDD', /[+-]\d{10}/], |
||
21 | ['YYYYMMDD', /\d{8}/], |
||
22 | // YYYYMM is NOT allowed by the standard |
||
23 | ['GGGG[W]WWE', /\d{4}W\d{3}/], |
||
24 | ['GGGG[W]WW', /\d{4}W\d{2}/, false], |
||
25 | ['YYYYDDD', /\d{7}/] |
||
26 | ]; |
||
27 | |||
28 | // iso time formats and regexes |
||
29 | var isoTimes = [ |
||
30 | ['HH:mm:ss.SSSS', /\d\d:\d\d:\d\d\.\d+/], |
||
31 | ['HH:mm:ss,SSSS', /\d\d:\d\d:\d\d,\d+/], |
||
32 | ['HH:mm:ss', /\d\d:\d\d:\d\d/], |
||
33 | ['HH:mm', /\d\d:\d\d/], |
||
34 | ['HHmmss.SSSS', /\d\d\d\d\d\d\.\d+/], |
||
35 | ['HHmmss,SSSS', /\d\d\d\d\d\d,\d+/], |
||
36 | ['HHmmss', /\d\d\d\d\d\d/], |
||
37 | ['HHmm', /\d\d\d\d/], |
||
38 | ['HH', /\d\d/] |
||
39 | ]; |
||
40 | |||
41 | var aspNetJsonRegex = /^\/?Date\((\-?\d+)/i; |
||
42 | |||
43 | // date from iso format |
||
44 | export function configFromISO(config) { |
||
45 | var i, l, |
||
46 | string = config._i, |
||
47 | match = extendedIsoRegex.exec(string) || basicIsoRegex.exec(string), |
||
48 | allowTime, dateFormat, timeFormat, tzFormat; |
||
49 | |||
50 | if (match) { |
||
51 | getParsingFlags(config).iso = true; |
||
52 | |||
53 | for (i = 0, l = isoDates.length; i < l; i++) { |
||
54 | if (isoDates[i][1].exec(match[1])) { |
||
55 | dateFormat = isoDates[i][0]; |
||
56 | allowTime = isoDates[i][2] !== false; |
||
57 | break; |
||
58 | } |
||
59 | } |
||
60 | if (dateFormat == null) { |
||
61 | config._isValid = false; |
||
62 | return; |
||
63 | } |
||
64 | if (match[3]) { |
||
65 | for (i = 0, l = isoTimes.length; i < l; i++) { |
||
66 | if (isoTimes[i][1].exec(match[3])) { |
||
67 | // match[2] should be 'T' or space |
||
68 | timeFormat = (match[2] || ' ') + isoTimes[i][0]; |
||
69 | break; |
||
70 | } |
||
71 | } |
||
72 | if (timeFormat == null) { |
||
73 | config._isValid = false; |
||
74 | return; |
||
75 | } |
||
76 | } |
||
77 | if (!allowTime && timeFormat != null) { |
||
78 | config._isValid = false; |
||
79 | return; |
||
80 | } |
||
81 | if (match[4]) { |
||
82 | if (tzRegex.exec(match[4])) { |
||
83 | tzFormat = 'Z'; |
||
84 | } else { |
||
85 | config._isValid = false; |
||
86 | return; |
||
87 | } |
||
88 | } |
||
89 | config._f = dateFormat + (timeFormat || '') + (tzFormat || ''); |
||
90 | configFromStringAndFormat(config); |
||
91 | } else { |
||
92 | config._isValid = false; |
||
93 | } |
||
94 | } |
||
95 | |||
96 | // RFC 2822 regex: For details see https://tools.ietf.org/html/rfc2822#section-3.3 |
||
97 | var basicRfcRegex = /^((?:Mon|Tue|Wed|Thu|Fri|Sat|Sun),?\s)?(\d?\d\s(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s(?:\d\d)?\d\d\s)(\d\d:\d\d)(\:\d\d)?(\s(?:UT|GMT|[ECMP][SD]T|[A-IK-Za-ik-z]|[+-]\d{4}))$/; |
||
98 | |||
99 | // date and time from ref 2822 format |
||
100 | export function configFromRFC2822(config) { |
||
101 | var string, match, dayFormat, |
||
102 | dateFormat, timeFormat, tzFormat; |
||
103 | var timezones = { |
||
104 | ' GMT': ' +0000', |
||
105 | ' EDT': ' -0400', |
||
106 | ' EST': ' -0500', |
||
107 | ' CDT': ' -0500', |
||
108 | ' CST': ' -0600', |
||
109 | ' MDT': ' -0600', |
||
110 | ' MST': ' -0700', |
||
111 | ' PDT': ' -0700', |
||
112 | ' PST': ' -0800' |
||
113 | }; |
||
114 | var military = 'YXWVUTSRQPONZABCDEFGHIKLM'; |
||
115 | var timezone, timezoneIndex; |
||
116 | |||
117 | string = config._i |
||
118 | .replace(/\([^\)]*\)|[\n\t]/g, ' ') // Remove comments and folding whitespace |
||
119 | .replace(/(\s\s+)/g, ' ') // Replace multiple-spaces with a single space |
||
120 | .replace(/^\s|\s$/g, ''); // Remove leading and trailing spaces |
||
121 | match = basicRfcRegex.exec(string); |
||
122 | |||
123 | if (match) { |
||
124 | dayFormat = match[1] ? 'ddd' + ((match[1].length === 5) ? ', ' : ' ') : ''; |
||
125 | dateFormat = 'D MMM ' + ((match[2].length > 10) ? 'YYYY ' : 'YY '); |
||
126 | timeFormat = 'HH:mm' + (match[4] ? ':ss' : ''); |
||
127 | |||
128 | // TODO: Replace the vanilla JS Date object with an indepentent day-of-week check. |
||
129 | if (match[1]) { // day of week given |
||
130 | var momentDate = new Date(match[2]); |
||
131 | var momentDay = ['Sun','Mon','Tue','Wed','Thu','Fri','Sat'][momentDate.getDay()]; |
||
132 | |||
133 | if (match[1].substr(0,3) !== momentDay) { |
||
134 | getParsingFlags(config).weekdayMismatch = true; |
||
135 | config._isValid = false; |
||
136 | return; |
||
137 | } |
||
138 | } |
||
139 | |||
140 | switch (match[5].length) { |
||
141 | case 2: // military |
||
142 | if (timezoneIndex === 0) { |
||
143 | timezone = ' +0000'; |
||
144 | } else { |
||
145 | timezoneIndex = military.indexOf(match[5][1].toUpperCase()) - 12; |
||
146 | timezone = ((timezoneIndex < 0) ? ' -' : ' +') + |
||
147 | (('' + timezoneIndex).replace(/^-?/, '0')).match(/..$/)[0] + '00'; |
||
148 | } |
||
149 | break; |
||
150 | case 4: // Zone |
||
151 | timezone = timezones[match[5]]; |
||
152 | break; |
||
153 | default: // UT or +/-9999 |
||
154 | timezone = timezones[' GMT']; |
||
155 | } |
||
156 | match[5] = timezone; |
||
157 | config._i = match.splice(1).join(''); |
||
158 | tzFormat = ' ZZ'; |
||
159 | config._f = dayFormat + dateFormat + timeFormat + tzFormat; |
||
160 | configFromStringAndFormat(config); |
||
161 | getParsingFlags(config).rfc2822 = true; |
||
162 | } else { |
||
163 | config._isValid = false; |
||
164 | } |
||
165 | } |
||
166 | |||
167 | // date from iso format or fallback |
||
168 | export function configFromString(config) { |
||
169 | var matched = aspNetJsonRegex.exec(config._i); |
||
170 | |||
171 | if (matched !== null) { |
||
172 | config._d = new Date(+matched[1]); |
||
173 | return; |
||
174 | } |
||
175 | |||
176 | configFromISO(config); |
||
177 | if (config._isValid === false) { |
||
178 | delete config._isValid; |
||
179 | } else { |
||
180 | return; |
||
181 | } |
||
182 | |||
183 | configFromRFC2822(config); |
||
184 | if (config._isValid === false) { |
||
185 | delete config._isValid; |
||
186 | } else { |
||
187 | return; |
||
188 | } |
||
189 | |||
190 | // Final attempt, use Input Fallback |
||
191 | hooks.createFromInputFallback(config); |
||
192 | } |
||
193 | |||
194 | hooks.createFromInputFallback = deprecate( |
||
195 | 'value provided is not in a recognized RFC2822 or ISO format. moment construction falls back to js Date(), ' + |
||
196 | 'which is not reliable across all browsers and versions. Non RFC2822/ISO date formats are ' + |
||
197 | 'discouraged and will be removed in an upcoming major release. Please refer to ' + |
||
198 | 'http://momentjs.com/guides/#/warnings/js-date/ for more info.', |
||
199 | function (config) { |
||
200 | config._d = new Date(config._i + (config._useUTC ? ' UTC' : '')); |
||
201 | } |
||
202 | ); |