-
Notifications
You must be signed in to change notification settings - Fork 329
fix(@toss/validators): Increase the accuracy of verification for isBirthDate6 #420
Conversation
👷 Deploy request for slash-libraries pending review.Visit the deploys page to approve it
|
| expect(isBirthDate6('951301')).toEqual(false); | ||
| expect(isBirthDate6('950230')).toEqual(false); | ||
| expect(isBirthDate6('950431')).toEqual(false); |
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.
I think there are too many expect phrases to verify on one test suite(it).
Why don't you split it up in different test suite?
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.
@okinawaa I agree with you. Changed Code
| function isLeapYear(year: number) { | ||
| return year !== 0 && year % 4 === 0; | ||
| } |
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.
The leap year check for the year 2000 is currently incorrect. ex) 000229
// as-is Abnormal behavior
isBirthDate6("000229"); // false
[31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
// to-be Normal behavior
isBirthDate6("000229"); // true
[31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]There are actually 29 days in February 2000.
https://ko.wikipedia.org/wiki/2000%EB%85%84_2%EC%9B%94
| function isLeapYear(year: number) { | |
| return year !== 0 && year % 4 === 0; | |
| } | |
| function isLeapYear(year: number) { | |
| return year % 4 === 0; | |
| } |
Wouldn't the above code be more accurate!? 🤗
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.
@ssi02014 Thank you for finding a bug! I apply the code you suggested. Changed Code
| if (month < 1 || month > 12) { | ||
| return false; | ||
| } |
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.
A small suggestion..!
Why not define the numbers 1 and 12 as JANUARY and DECEMBER constants to manage them? 🤗
| if (month < 1 || month > 12) { | |
| return false; | |
| } | |
| if (month < JANUARY || month > DECEMBER) { | |
| return false; | |
| } |
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.
I like This comment awesome..!
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.
I love it too.
This code prevents the use of magic numbers
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.
@ssi02014 Thanks! I agree with you. Changed code (cc. @minsoo-web, @okinawaa )
|
Hello @po4tion, thanks for your contribution. In my opinion, the best way to handle this is using the proper date library, since import { parse, isValid } from 'date-fns';
const parsed = parse(date, "yyMMdd", new Date());
return isValid(parsed);How about using the proper library instead of implementing the validation logic ourselves? |
raon0211
left a comment
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.
Thanks for your awesome work!
|
@raon0211 That's an incredible speed. Your addition was helpful, thank you! |
…rthDate6 (toss#420) * fix(@toss/validators): Increase the accuracy of verification * test(@toss/validators): add test case * fix: catch 2000y bug * refactor: change from magic number to constant variable * test: split test case * refactor: change constant variable name * refactor(@toss/validators): use proper library(date-fns)
… keep add and remove eventlistener (#453) * fix: add callback dependency on useOutsideClickEffect using preservedCallback * fix: delete touchstart event from `useOutsideClickEffect` * Revert "fix: delete touchstart event from `useOutsideClickEffect`" This reverts commit c1b09c9. * fix(@toss/validators): Increase the accuracy of verification for isBirthDate6 (#420) * fix(@toss/validators): Increase the accuracy of verification * test(@toss/validators): add test case * fix: catch 2000y bug * refactor: change from magic number to constant variable * test: split test case * refactor: change constant variable name * refactor(@toss/validators): use proper library(date-fns) * chore(release): Publish libraries [skip ci] - @toss/[email protected] - [email protected] - @toss/[email protected] - @toss/[email protected] - @toss/[email protected] - @toss/[email protected] - @toss/[email protected] - @toss/[email protected] - @toss/[email protected] - @toss/[email protected] - @toss/[email protected] - @toss/[email protected] - @toss/[email protected] - @toss/[email protected] - @toss/[email protected] - @toss/[email protected] - @toss/[email protected] - @toss/[email protected] - @toss/[email protected] - @toss/[email protected] - @toss/[email protected] - @toss/[email protected] - @toss/[email protected] - @toss/[email protected] - @toss/[email protected] - @toss/[email protected] - @toss/[email protected] - @toss/[email protected] - @toss/[email protected] * Revert "chore(release): Publish libraries [skip ci]" This reverts commit c325c90. * Revert "fix(@toss/validators): Increase the accuracy of verification for isBirthDate6 (#420)" This reverts commit 2565f17. * Apply suggestions from code review --------- Co-authored-by: Dongkyu Kim <[email protected]> Co-authored-by: raon0211 <[email protected]> Co-authored-by: Sojin Park <[email protected]>
Overview
[ What did i do ]
According to the Gregorian calendar, there are months when 30 or 31 days do not exist. For example, February 30 and April 31.
The current "isBirthDate6" is not responsible for this, even though it is a function to verify the correct date of birth. So I've supplemented this.
[ AS-IS ]

[ TO-BE ]
PR Checklist