Skip to content

Commit 3fae1b1

Browse files
authored
feat(b-calendar, b-form-datepicker): relax date YYYY-MM-DD string matching (closes #5232)
1 parent 4b2b7d9 commit 3fae1b1

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/utils/date.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@ import { toInteger } from './number'
66

77
// --- Constants ---
88

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/
1015

1116
// --- Date utility methods ---
1217

@@ -16,7 +21,7 @@ export const createDate = (...args) => new Date(...args)
1621
// Parse a date sting, or Date object, into a Date object (with no time information)
1722
export const parseYMD = date => {
1823
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))
2025
return createDate(year, month - 1, day)
2126
} else if (isDate(date)) {
2227
return createDate(date.getFullYear(), date.getMonth(), date.getDate())

0 commit comments

Comments
 (0)