-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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
time: Document time.Parse leap second behavior #50888
Comments
The time package in general does not know anything about leap seconds. That covers the entire package, including the parsing routines. Personally I think is covered by the general statement of the time package. Is it necessary to repeat that for In particular, it would be misleadig to parse second 60, because the time package can't represent it. It would be identical to either second 59 or second 0 of the next minute. |
I personally took the In the case that my program encounters an error as a result of trying to read :60 from a different program, it would be nice to have a very obvious place to point operators to to understand what is going on, although, perhaps this exists and I've missed it. |
Per RFC 3339, though, which I may be misreading it, but I think the parser could actually handle that gracefully. Edit, to add: I think this could be done without having to address leap-second awareness more generally. This appears to mostly be a syntactic property (e.g., if seconds == 60 and we're at the end of the last day of the month, do a special thing). |
I don't think that is accurate. A leap second really is an additional second. For cases where leap seconds have been inserted, second 60 really does exist. However, that is only true for time systems that understand leap seconds. The time package is not such a system. The time package has no way to represent the fact that some minutes are 61 seconds long. If we accepted second 60 in |
go version
:go version go1.17.5 linux/amd64
RFC3339 documents that leap seconds will be denoted as
YYYY-MM-DDT23:59:60Z
. Attempting to parse such a value usingtime.Parse
returns the following error:https://go.dev/play/p/es_oGD37vZl
This behavior seems perfectly reasonable, given the fact that Go's time keeping does not account for the leap second and instead uses the Unix style of time. However, while I notice that the documentation for package
time
mentions thatcalendrical calculations always assume a Gregorian calendar, with no leap seconds
, it doesn't seem to indicate the parser behavior.I see that issues have been opened in the past to change the behavior, #8728. This issue is just a request that the behavior be documented as part of the time package.
Happy to provide any other information needed.
The text was updated successfully, but these errors were encountered: