/
githubmirror
/
dayjs
Обзор
Документация
Войти
/
githubmirror
/
dayjs
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
dev
src/plugin/negativeYear/index.js
28 строк
730 B
iamkun
fix: add UTC support to negativeYear plugin (#2692)
18 июл 2024, 14:37
Не верифицирован
18 июл 2024, 14:37
f3ef705
Код
Авторство
О чём код?
export default (_, c, dayjs) => { const proto = c.prototype const parseDate = (cfg) => { const { date, utc } = cfg if (typeof date === 'string' && date.charAt(0) === '-') { 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() } return date } return date } const oldParse = proto.parse proto.parse = function (cfg) { cfg.date = parseDate.bind(this)(cfg) oldParse.bind(this)(cfg) } }