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

feat(isUtcLeap): Add function to determine a leap year in UTC to avoi… #3295

Merged
merged 3 commits into from
Apr 5, 2023

Conversation

RyanClementsHax
Copy link
Contributor

@RyanClementsHax RyanClementsHax commented Mar 30, 2023

…d timezone issues

  • Add isUtcLeap that is the same as isLeap but uses getUTCFullYear to avoid timezone issues
  • Add tests for isUtcLeap
  • Fix tests for isLeap that only failed on machines running in GMT-

Implements #3294

…d timezone issues

- Add isUTCLeap that is the same as isLeap but uses getUTCFullYear to avoid timezone issues
- Add tests for isUTCLeap
- Fix tests for isLeap that only failed on machines running in GMT-<anything>
@CLAassistant
Copy link

CLAassistant commented Mar 30, 2023

CLA assistant check
All committers have signed the CLA.

@lionel-rowe
Copy link
Contributor

TBH the whole idea of determining whether something's a leap year from a Date object seems massively error-prone and difficult to reason about. For example, a developer might reasonably believe isUTCLeap will interpret a Date object as if it's UTC even when it was constructed in a non-UTC timezone, which isn't true.

// in my current timezone, UTC+8
isLeap(new Date(2000, 0 /* zero-indexed month */, 1)) // true (consistently true everywhere)
isUTCLeap(new Date(2000, 0 /* zero-indexed month */, 1))) // false (but would be true if I lived somewhere with a zero or negative UTC offset)
isLeap(new Date("2000-01-01")) // true (but would be false if I lived somewhere with a negative UTC offset)
isUTCLeap(new Date("2000-01-01")) // true (consistently true everywhere)

IMO it'd be better to simply deprecate or remove the (year: Date) => boolean signature.

@RyanClementsHax
Copy link
Contributor Author

I'm ok with either. I can update the PR if needed. How will I know if this is the way we want to go? Does a maintainer need to give the final say?

@lionel-rowe
Copy link
Contributor

I'm ok with either. I can update the PR if needed. How will I know if this is the way we want to go? Does a maintainer need to give the final say?

I'd assume so — I'm just a random contributor so I can't speak authoritatively, just adding my 2 cents as I've come across far too many Date-related timezone bugs. Incidentally, this type of confusion is a big part of the motivation for Temporal, though that's still at stage 3 and AFAIK not implemented in any browsers yet, even behind a flag.

@iuioiua
Copy link
Collaborator

iuioiua commented Apr 2, 2023

How come this functionality isn't being added to isLeap() instead of having a separate function? Having 2 separate functions that have so much overlap may confuse users.

If a separate function is justified, it should be named isUtcLeap() as acronyms should written in camelCase (see #2582).

Disclaimer: I have not looked at this implementation or discussion, so please excuse any ignorance.

@RyanClementsHax
Copy link
Contributor Author

RyanClementsHax commented Apr 2, 2023

I could add an option object to is leap to toggle this feature but it seemed more idiomatic to make a second function to keep in line with the api of JavaScript's date object. This is also why I named the function the way I did. For more details see #3294.

I'm not opposed to changing these details btw. I don’t feel very strongly about them.

@iuioiua
Copy link
Collaborator

iuioiua commented Apr 2, 2023

I see, I see. In that case, a separate function is reasonable.

Again though, the function name would have to be isUtcLeap() with the acronym being in camelCase 👍🏾

@RyanClementsHax RyanClementsHax changed the title feat(isUTCLeap): Add function to determine a leap year in UTC to avoi… feat(isUtcLeap): Add function to determine a leap year in UTC to avoi… Apr 3, 2023
@RyanClementsHax
Copy link
Contributor Author

I've changed the function to be named isUtcLeap

Copy link
Member

@kt3k kt3k left a comment

Choose a reason for hiding this comment

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

LGTM

@kt3k kt3k merged commit 13b798f into denoland:main Apr 5, 2023
7 checks passed
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

5 participants