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 Location's effect on Time more? #23316
Comments
That's not how it works. This is working as intended:
Note the identical unix time. I admit the docs aren't super clear on this. |
UTC is not Unix time. Following short definitions may be helpful. UTC: Coordinated Universal Time. UTC is within 1 second of the solar mean time at 0" longitude. For most purposes it can be considered to be interchangeable with Greenwich Mean Time (GMT), the latter is however not precisely defined anymore. Unix time: Unix time is the number of seconds elapsed since 1. 1. 1970 00:00:00 UTC minus the leap seconds since then. (Leap seconds are applied to UTC because earth rotation is not constant and one rotation doesn't take exactly 86400 seconds.) Local time: Legal time, subject to regulation, at a location. The time at a location may support daylight saving time, so the difference to UTC is not constant. |
I only used UTC in my example because it was an easy way to get a different Location. I didn't mean to add to any confusion, but I also don't see any confusion about Unix vs UTC above. |
@bradfitz: I apologize for the wording, I changed the wording already yesterday, but this change isn't reflected in the emails going out. What I wonder about what change of documentation is required. The example by @pjebs is using the local time (hour, minutes, second) to initialize The following program shows the proper use of package main
import (
"log"
"time"
)
func main() {
log.SetFlags(0)
t0 := time.Now()
log.Printf("t0: %s", t0)
locShanghai, err := time.LoadLocation("Asia/Shanghai")
if err != nil {
log.Fatalf("LoadLocation error %s", err)
}
t1 := t0.In(locShanghai)
log.Printf("t1: %s", t1)
if t0.Equal(t1) {
log.Print("t0 == t1")
} else {
log.Print("t0 != t1")
}
} |
Change https://golang.org/cl/120060 mentions this issue: |
That's not what it should document. That's obvious. It should state that once you create a Time struct, it's point in time (also represented by it's unix time) is immutable. Using the That was actually what my original concern was about. |
@pjebs If I understand you correctly, it seems to me that that is already documented.
|
Documenation states:
Maybe this should be made a bit clearer. My initial belief based on that statement was that the function returns a new Time struct with the same Year,Month,Day,Hour, Minute etc... EXCEPT with loc changed. |
I've updated CL 120060 with some updated docs on |
@pjebs, why are you closing it? |
I thought it was now sorted. |
Using Go 1.9
Documenation states:
My interpretation is that the function
In
will change the location information but keep all other details the same. The consequence is that it will have a different Unix time usually since they represent different points in time.Output:
Expected output:
startDate.In(time.UTC))
and_startDate
should produce same resultThe text was updated successfully, but these errors were encountered: