|
278 | 278 | } |
279 | 279 | , localDateTimestamp = function localDateTimestamp(rawDate, dateFormatDefinition) { |
280 | 280 |
|
281 | | - var formattingTokens = /(\[[^\[]*\])|(\\)?([Hh]mm(ss)?|MM?M?M?|dd?d?|yy?yy?y?|gg(ggg?)?|GG(GGG?)?|e|E|a|A|hh?|HH?|kk?|mm?|ss?|S{1,9}|x|X|zz?|ZZ?|.)/g |
282 | | - ,formatDate = dateFormatDefinition.match(formattingTokens) |
283 | | - ,dateSplit, m, d, y, index, el; |
| 281 | + var formattingTokens = /(\[[^\[]*\])|(\\)?([Hh]mm(ss)?|MMMM|MMM|MM|M|dd?d?|yy?yy?y?|gg(ggg?)?|GG(GGG?)?|e|E|a|A|hh?|HH?|kk?|mm?|ss?|S{1,9}|x|X|zz?|ZZ?|.)/g |
| 282 | + ,formatDate,dateSplit, m, d, y, index, el, longName, shortName; |
284 | 283 |
|
285 | 284 | for (index = 0; index < datetime.MONTH.length; index += 1) { |
286 | | - el = datetime.MONTH[index]; |
287 | | - if (rawDate.indexOf(el) > -1) { |
288 | | - rawDate = rawDate.replace(el, index + 1); |
| 285 | + longName = datetime.MONTH[index]; |
| 286 | + shortName = datetime.SHORTMONTH[index]; |
| 287 | + |
| 288 | + if (rawDate.indexOf(longName) !== -1) { |
| 289 | + rawDate = rawDate.replace(longName, index + 1); |
289 | 290 | break; |
290 | 291 | } |
| 292 | + |
| 293 | + if (rawDate.indexOf(shortName) !== -1) { |
| 294 | + rawDate = rawDate.replace(shortName, index + 1); |
| 295 | + break; |
| 296 | + } |
291 | 297 | } |
292 | 298 |
|
293 | | - dateSplit = rawDate.split(/\D/); |
| 299 | + dateSplit = rawDate |
| 300 | + .split(/\D/) |
| 301 | + .filter(function dateSplitFilter(item) { |
| 302 | + return item.length > 0; |
| 303 | + }); |
294 | 304 |
|
295 | | - dateSplit = dateSplit.filter(function dateSplitFilter(item) { |
296 | | - if (item.length > 0) { |
297 | | - return item; |
298 | | - } |
299 | | - }); |
300 | | - |
301 | | - formatDate = formatDate.filter(function fromatDateFilter(item) { |
302 | | - if (item.match(/^[a-zA-Z]+$/i) !== null) { |
303 | | - return item; |
304 | | - } |
305 | | - }); |
| 305 | + formatDate = dateFormatDefinition |
| 306 | + .match(formattingTokens) |
| 307 | + .filter(function fromatDateFilter(item) { |
| 308 | + return item.match(/^[a-zA-Z]+$/i) !== null; |
| 309 | + }); |
306 | 310 |
|
307 | 311 | for (index = 0; index < formatDate.length; index += 1) { |
308 | 312 | el = formatDate[index]; |
309 | 313 |
|
310 | | - if (el.indexOf('d') > -1) { |
311 | | - d = dateSplit[index]; |
312 | | - } |
313 | | - |
314 | | - if (el.indexOf('M') > -1) { |
315 | | - m = dateSplit[index]; |
316 | | - } |
317 | | - |
318 | | - if (el.indexOf('y') > -1) { |
319 | | - y = dateSplit[index]; |
| 314 | + switch (true) { |
| 315 | + case el.indexOf('d') !== -1: { |
| 316 | + d = dateSplit[index]; |
| 317 | + break; |
| 318 | + } |
| 319 | + case el.indexOf('M') !== -1: { |
| 320 | + m = dateSplit[index]; |
| 321 | + break; |
| 322 | + } |
| 323 | + case el.indexOf('y') !== -1: { |
| 324 | + y = dateSplit[index]; |
| 325 | + break; |
| 326 | + } |
| 327 | + default: { |
| 328 | + break; |
| 329 | + } |
320 | 330 | } |
321 | 331 | } |
322 | 332 |
|
|
0 commit comments