feat: Add negative years support - #2640
Conversation
Testing format without parameter
|
This looks good, I added a test (in manipulate.test.js): Just to make sure that adding/subtracting were working well. I tried to commit to your fork, but it didn't work. |
|
@willismonroe I added those test for you |
|
That looks good! |
|
Hi Dear @willismonroe It's now a plugin to be extended as @iamkun suggested |
| const date3 = '01-03--2021' | ||
| const d = date.match(REGEX_PARSE) | ||
| expect(dayjs(date).format('YYYY-MM-DD')).toBe(`-${moment(date).format('YYYY-MM-DD')}`) | ||
| expect(dayjs(date).format()).toBe(`-${moment(date).format()}`) |
There was a problem hiding this comment.
could we remove moment in this test case? as far as i know, moment does not support nagative year
| if (typeof date === 'string' && date.indexOf(`-${fullYear}`) !== -1) { | ||
| return dayjs(newDate).subtract(fullYear * 2, 'year').toDate() | ||
| } | ||
| return newDate |
There was a problem hiding this comment.
we can return the passed in the original cfg.date directly, without dealing with logic like !date
|
@iamkun Changes are done. Let me know if anything else will be great |
| if (typeof date === 'string' && date.indexOf(`-${fullYear}`) !== -1) { | ||
| return dayjs(newDate).subtract(fullYear * 2, 'year').toDate() | ||
| } | ||
| return newDate |
There was a problem hiding this comment.
maybe we should return date not newDate, cause cfg.date is the untouched original one, just leave it to the current main parse logic
|
THX |
## [1.11.12](v1.11.11...v1.11.12) (2024-07-18) ### Bug Fixes * Add NegativeYear Plugin support ([#2640](#2640)) ([6a42e0d](6a42e0d)) * add UTC support to negativeYear plugin ([#2692](#2692)) ([f3ef705](f3ef705)) * Fix zero offset issue when use tz with locale ([#2532](#2532)) ([d0e6738](d0e6738)) * Improve typing for min/max plugin ([#2573](#2573)) ([4fbe94a](4fbe94a)) * timezone plugin currect parse UTC tz ([#2693](#2693)) ([b575c81](b575c81))
## [1.11.12](iamkun/dayjs@v1.11.11...v1.11.12) (2024-07-18) ### Bug Fixes * Add NegativeYear Plugin support ([#2640](iamkun/dayjs#2640)) ([6a42e0d](iamkun/dayjs@6a42e0d)) * add UTC support to negativeYear plugin ([#2692](iamkun/dayjs#2692)) ([f3ef705](iamkun/dayjs@f3ef705)) * Fix zero offset issue when use tz with locale ([#2532](iamkun/dayjs#2532)) ([d0e6738](iamkun/dayjs@d0e6738)) * Improve typing for min/max plugin ([#2573](iamkun/dayjs#2573)) ([4fbe94a](iamkun/dayjs@4fbe94a)) * timezone plugin currect parse UTC tz ([#2693](iamkun/dayjs#2693)) ([b575c81](iamkun/dayjs@b575c81))

Add ability to parse negative years
This fix 2636 issue