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

fix(datetime/day_of_year): respect time zone of date #3443

Merged
merged 10 commits into from
Jun 14, 2023
Merged

fix(datetime/day_of_year): respect time zone of date #3443

merged 10 commits into from
Jun 14, 2023

Conversation

familyboat
Copy link
Contributor

Maybe fix #1114

@familyboat familyboat requested a review from kt3k as a code owner June 12, 2023 03:19
@kt3k
Copy link
Member

kt3k commented Jun 12, 2023

I'm not sure #1114 is a 'bug'.

Does it make sense to have both UTC and local timezone versions of APIs (like #3295 ) ?

@familyboat
Copy link
Contributor Author

familyboat commented Jun 12, 2023

You can specify time zone in two ways.

  1. Specify it in date string (e.g.: new Date("2023-01-01T00:00:00.000+08:00)).

  2. Do not specify it explicitly, which means Date will use your local time zone.

But there are some cases where you cannot get result what you want.

const firstDay = new Date("2023-01-01T00:00:00.000+09:00"); // first day in year 2023 in east 9th district
console.log(firstDay.getFullYear()) // 2022, my local time zone is east 8th district

Maybe it is not a bug.

@familyboat
Copy link
Contributor Author

When Intantiating Date with different arguments, the time zone of date varies. Some is utc time zone, some is your local time zone, some is your specified time zone, which will be converted to your local time zone. See more information in https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date#date_time_string_format.
In this line https://github.com/denoland/deno_std/blob/aea85151e872338f9d6c52041e58ed14fbf21650/datetime/day_of_year.ts#L13 , the time zone of date is your local time zone, so the reault may be 70, or 69.
Here what I want to say is that developer should know the time zone of date instance, and time zone used in dayOfYear should be pointed out in docs. Leave the responsibility to the developer.

*
* @return Number of the day in the year in UTC time
*/
export function dayOfUtcYear(date: Date): number {
Copy link
Member

Choose a reason for hiding this comment

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

Utc in the middle of dayOfYear sounds strange to me. How about utcDayOfYear or dayOfYearUtc?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I prefer dayOfYearUtc. Updated.

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

@familyboat familyboat requested a review from kt3k June 14, 2023 11:48
@kt3k kt3k merged commit d1879dd into denoland:main Jun 14, 2023
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.

datetime: dayOfYear() wrong output when date is instantiated with individual date components
3 participants