@@ -6,7 +6,12 @@ import { toInteger } from './number'
6
6
7
7
// --- Constants ---
8
8
9
- const RX_DATE = / ^ \d + - \d + - \d + $ /
9
+ // Loose YYYY-MM-DD matching, ignores any appended time inforation
10
+ // Matches '1999-12-20', '1999-1-1', '1999-01-20T22:51:49.118Z', '1999-01-02 13:00:00'
11
+ const RX_DATE = / ^ \d + - \d \d ? - \d \d ? (?: \s | T | $ ) /
12
+
13
+ // Used to split off the date parts of the YYYY-MM-DD string
14
+ const RX_DATE_SPLIT = / - | \s | T /
10
15
11
16
// --- Date utility methods ---
12
17
@@ -16,7 +21,7 @@ export const createDate = (...args) => new Date(...args)
16
21
// Parse a date sting, or Date object, into a Date object (with no time information)
17
22
export const parseYMD = date => {
18
23
if ( isString ( date ) && RX_DATE . test ( date . trim ( ) ) ) {
19
- const [ year , month , day ] = date . split ( '-' ) . map ( toInteger )
24
+ const [ year , month , day ] = date . split ( RX_DATE_SPLIT ) . map ( v => toInteger ( v , 1 ) )
20
25
return createDate ( year , month - 1 , day )
21
26
} else if ( isDate ( date ) ) {
22
27
return createDate ( date . getFullYear ( ) , date . getMonth ( ) , date . getDate ( ) )
0 commit comments