-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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 |
test/plugin/negativeYear.test.js
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could we remove moment in this test case? as far as i know, moment does not support nagative year
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@iamkun Sure
src/plugin/negativeYear/index.js
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can return the passed in the original cfg.date directly, without dealing with logic like !date
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@iamkun Got you
@iamkun Changes are done. Let me know if anything else will be great |
src/plugin/negativeYear/index.js
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe we should return date not newDate, cause cfg.date
is the untouched original one, just leave it to the current main parse logic
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@iamkun Updated
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