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

Colon in timezone #24

Closed
thernstig opened this issue May 15, 2020 · 3 comments · Fixed by #27, #32 or #33
Closed

Colon in timezone #24

thernstig opened this issue May 15, 2020 · 3 comments · Fixed by #27, #32 or #33
Milestone

Comments

@thernstig
Copy link

thernstig commented May 15, 2020

According to https://en.wikipedia.org/wiki/ISO_8601 the timezone is recommended to contain a colon.

Representations can be done in one of two formats – a basic format with a minimal number of separators or an extended format with separators added to enhance human readability.[14][15] The standard notes that "The basic format should be avoided in plain text."[16] The separator used between date values (year, month, week, and day) is the hyphen, while the colon is used as the separator between time values (hours, minutes, and seconds). For example, the 6th day of the 1st month of the year 2009 may be written as "2009-01-06" in the extended format or simply as "20090106" in the basic format without ambiguity.

RFC3339, that is a profile of ISO 8601, also states that the offset between local time and UTC is defined as:

time-numoffset = ("+" / "-") time-hour ":" time-minute

As such, should the the O format string should most likely include a colon, right?

@lamweili
Copy link
Collaborator

lamweili commented Jan 6, 2022

I believe this is what @thernstig is saying.

The date and time portions are using the extended format, which includes - and : delimiters.
Thus, the timezone portion should also be using the extended format, with the : delimiter, for consistency.

2022-01-06T08:47:48.003+0800 -> 2022-01-06T08:47:48.003+08:00

return timezoneOffset < 0 ? "+" + h + m : "-" + h + m;

- return timezoneOffset < 0 ? "+" + h + m : "-" + h + m; 
+ return (timezoneOffset < 0 ? "+" : "-") + h + ":" + m; 

There seems to be little to no regression as JS handles both cases.

let test1 = new Date("2022-01-06T08:47:48.003+0800");
let test2 = new Date("2022-01-06T08:47:48.003+08:00");
console.log(test1.getTime() === test2.getTime());
// true

Might also want to include a case of +0000 or +00:00 to return Z instead.

- return timezoneOffset < 0 ? "+" + h + m : "-" + h + m; 
+ return timezoneOffset === 0 ? "Z" : (timezoneOffset < 0 ? "+" : "-") + h + ":" + m; 

@thernstig
Copy link
Author

@peteriman thank you for that comment. I re-read my original post and must have been very tired when writing it, as it ended quite abruptly without better examples of what I meant, and where the change should be made.

@lamweili lamweili added this to the 4.0.0 milestone Jan 10, 2022
@lamweili
Copy link
Collaborator

For more details: #27 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants