Skip to content

Commit f3ef705

Browse files
authored
fix: add UTC support to negativeYear plugin (#2692)
1 parent d0e6738 commit f3ef705

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/plugin/negativeYear/index.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,16 @@ export default (_, c, dayjs) => {
22
const proto = c.prototype
33

44
const parseDate = (cfg) => {
5-
const { date } = cfg
5+
const { date, utc } = cfg
66
if (typeof date === 'string' && date.charAt(0) === '-') {
7-
const newDate = new Date(date.slice(1))
8-
const fullYear = newDate.getFullYear()
7+
const normalData = date.slice(1)
8+
let newDate = dayjs(normalData)
9+
if (utc) {
10+
newDate = dayjs.utc(normalData)
11+
} else {
12+
newDate = dayjs(normalData)
13+
}
14+
const fullYear = newDate.year()
915
if (date.indexOf(`-${fullYear}`) !== -1) {
1016
return dayjs(newDate).subtract(fullYear * 2, 'year').toDate()
1117
}

0 commit comments

Comments
 (0)