Skip to content
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

Leap Year: isValid bug #2607 #2614

Draft
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

iSanjayAchar
Copy link

Javascript (and most other programming languages) recognize that February only has 28 days (or 29 in a leap year). So, when you enter a date like "2024-02-31" using new Date("2024-02-31"), it attempts to create a valid date.

Here's what happens behind the scenes:

  • Javascript creates a Date object with the provided year, month (0-indexed, so February is 1), and day.
    It recognizes February doesn't have 31 days.
  • To create a valid date, Javascript automatically adjusts the date to the closest valid date. In this case, it becomes March 1st (the 1st day of the next month).
  • This behavior is to ensure the Date object represents a real date within the calendar system.

This PR adds an additional check to isValid method ensuring the date matches before checking for validity

Before

  isValid() {
    return !(this.$d.toString() === C.INVALID_DATE_STRING)
  }

After

  isValid() {
    switch (this.$D !== this.$d.getDate()) {
      case true:
        return !(this.$d.toString() === C.INVALID_DATE_STRING)
      default:
        return false
    }
  }

@iSanjayAchar iSanjayAchar marked this pull request as draft March 25, 2024 10:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants