Skip to content
This repository was archived by the owner on Dec 18, 2025. It is now read-only.

Conversation

@po4tion
Copy link
Contributor

@po4tion po4tion commented Jan 19, 2024

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 ]
image

[ TO-BE ]

expect(isBirthDate6('950230')).toEqual(false);
expect(isBirthDate6('950431')).toEqual(false);
image

PR Checklist

  • I read and included theses actions below
  1. I have read the Contributing Guide
  2. I have written documents and tests, if needed.

@netlify
Copy link

netlify bot commented Jan 19, 2024

👷 Deploy request for slash-libraries pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 6f2a44d

@po4tion po4tion changed the title fix(@toss/validators): Increase the accuracy of verification fix(@toss/validators): Increase the accuracy of verification for isBirthDate6 Jan 19, 2024
Comment on lines 14 to 16
expect(isBirthDate6('951301')).toEqual(false);
expect(isBirthDate6('950230')).toEqual(false);
expect(isBirthDate6('950431')).toEqual(false);
Copy link
Member

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?

Copy link
Contributor Author

@po4tion po4tion Feb 12, 2024

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

Comment on lines 25 to 27
function isLeapYear(year: number) {
return year !== 0 && year % 4 === 0;
}
Copy link
Contributor

@ssi02014 ssi02014 Feb 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@po4tion 👋 cc. @okinawaa

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

Suggested change
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!? 🤗

Copy link
Contributor Author

@po4tion po4tion Feb 12, 2024

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

Comment on lines 11 to 13
if (month < 1 || month > 12) {
return false;
}
Copy link
Contributor

@ssi02014 ssi02014 Feb 10, 2024

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? 🤗

Suggested change
if (month < 1 || month > 12) {
return false;
}
if (month < JANUARY || month > DECEMBER) {
return false;
}

Copy link
Member

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..!

Copy link
Member

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

Copy link
Contributor Author

@po4tion po4tion Feb 12, 2024

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 )

@raon0211
Copy link
Collaborator

Hello @po4tion, thanks for your contribution.

In my opinion, the best way to handle this is using the proper date library, since Dates are hard to handle properly. If we were to use date-fns, we might have used:

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?

Copy link
Collaborator

@raon0211 raon0211 left a 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 raon0211 merged commit 81c332e into toss:main Mar 26, 2024
@po4tion
Copy link
Contributor Author

po4tion commented Mar 26, 2024

@raon0211 That's an incredible speed. Your addition was helpful, thank you!

tjrdnjs1534 pushed a commit to tjrdnjs1534/slash that referenced this pull request Apr 20, 2024
…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)
tjrdnjs1534 added a commit to tjrdnjs1534/slash that referenced this pull request Apr 20, 2024
raon0211 added a commit that referenced this pull request May 31, 2024
… 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]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants