Skip to content

Commit

Permalink
fix: add UTC support to negativeYear plugin (#2692)
Browse files Browse the repository at this point in the history
  • Loading branch information
iamkun authored Jul 18, 2024
1 parent d0e6738 commit f3ef705
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/plugin/negativeYear/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@ export default (_, c, dayjs) => {
const proto = c.prototype

const parseDate = (cfg) => {
const { date } = cfg
const { date, utc } = cfg
if (typeof date === 'string' && date.charAt(0) === '-') {
const newDate = new Date(date.slice(1))
const fullYear = newDate.getFullYear()
const normalData = date.slice(1)
let newDate = dayjs(normalData)
if (utc) {
newDate = dayjs.utc(normalData)
} else {
newDate = dayjs(normalData)
}
const fullYear = newDate.year()
if (date.indexOf(`-${fullYear}`) !== -1) {
return dayjs(newDate).subtract(fullYear * 2, 'year').toDate()
}
Expand Down

0 comments on commit f3ef705

Please sign in to comment.