You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What steps will reproduce the problem?
This code does not work in Go Playground as-is, so just put it right there:
// DatesDiff returns the number of days and seconds resp. between two given dates
func DatesDiff(t1, t2 time.Time) (int, int64) {
v := int64(t2.Sub(t1))
return int(v / 864e11), v / 1e9
}
func main() {
loc, err := time.LoadLocation("Europe/Berlin")
if err != nil {
fmt.Println(err.Error())
return
}
t1 := time.Date(1957, time.September, 10, 0, 0, 0, 0, loc)
t2 := time.Date(2013, time.May, 14, 0, 0, 0, 0, loc)
fmt.Println(DatesDiff(t1, t2))
t3 := time.Date(1957, time.September, 10, 0, 0, 0, 0, time.UTC)
t4 := time.Date(2013, time.May, 14, 0, 0, 0, 0, time.UTC)
fmt.Println(DatesDiff(t3, t4))
}
What is the expected output?
20335 1756944000
20335 1756944000
What do you see instead?
20334 1756940400
20335 1756944000
Which compiler are you using (5g, 6g, 8g, gccgo)?
8g
Which operating system are you using?
Windows 7 Prof x86
Ubuntu Linux 12.04 LTS x86
Which version are you using? (run 'go version')
go version go1.0.1
Please provide any additional information below.
The text was updated successfully, but these errors were encountered:
Daylight saving time was not observed in Germany in 1957:
http://en.wikipedia.org/wiki/Daylight_saving_time_in_Germany
In your first example, you are computing the difference between "09 Sep 1957 23:00 UTC"
and "14 May 2013 22:00 UTC", which is one hour less than your second example. You should
take that into account if you need to compute *date* differences. Package time cares
about time.
by pkorotkov:
The text was updated successfully, but these errors were encountered: