I am developing a user interface for the planning interface where the user can set timers for several hours in the future. I want, if possible, to be able to manage a summer day, I thought it would be quite simple. Checking the time. The time in golang packages I came across the following inconsistency, if that's what it is.
package main import ( "fmt" "time" ) func main(){ const timeFormat = "2 Jan, 2006 3:04pm (MST)" test , err := time.Parse( timeFormat, "25 Oct, 2015 1:59am (BST)" ) fmt.Println( test , test.UTC() , err) dur , _ := time.ParseDuration( "1m" ) test = test.Add( dur ) fmt.Println( test , test.UTC()) fmt.Println( "--------------------" ) test , err = time.Parse( timeFormat, "25 Oct, 2015 2:01am (BST)" ) fmt.Println( test , test.UTC() , err) test = test.Add( dur ) fmt.Println( test , test.UTC()) test = test.Sub( dur ) fmt.Println( test , test.UTC()) }
I know that at 2:00 a.m. on October 25, 2015, the BST should make the clock return to 1:00 GMT (UTC). If I increase 1:59 a.m. BST for one minute, the time will really switch to GMT.
2015-10-25 01:59:00 +0100 BST 2015-10-25 00:59:00 +0000 UTC <nil> 2015-10-25 01:00:00 +0000 GMT 2015-10-25 01:00:00 +0000 UTC -------------------- 2015-10-25 02:01:00 +0000 BST 2015-10-25 02:01:00 +0000 UTC <nil> 2015-10-25 02:02:00 +0000 BST 2015-10-25 02:02:00 +0000 UTC
However, if I analyze the time after 2 AM in BST, I would expect it to switch to GMT in the same way that the time will increase compared to the transition. In case the transition code is called using the "Add" procedure, I add the minute again, but this also does not return the time to GMT.
I was expecting one of the following events to happen.
a) for BST always stay GMT + 1
b) at any time when the BST is βinvalidβ to automatically change the correct GMT time (invalid BST is between 2:00 after the last Sunday of October and 2:00 after the last Sunday of March of the following year)
c) an error to be caused if a date is created on these dates using BST (and possibly other summer hours in other countries).
Otherwise, I will need to check whether the user enters a date in BST, whether this date is outside of BST and sets or forces users to UTC, which leads to a victory over the object built into the library.
During the study, I noticed this https://www.youtube.com/watch?v=-5wpm-gesOY and decided that it was definitely not as simple as I first thought ...
Any insight or best way to handle daylight saving time would be appreciated.
Using go version 1.0.2 on Debian Wheezy
Edited: repeated using go version 1.3.3 and got this output
2015-10-25 01:59:00 +0100 BST 2015-10-25 00:59:00 +0000 UTC <nil> 2015-10-25 01:00:00 +0000 GMT 2015-10-25 01:00:00 +0000 UTC -------------------- 2015-10-25 01:00:00 +0000 GMT 2015-10-25 01:00:00 +0000 UTC <nil> 2015-10-25 01:01:00 +0000 GMT 2015-10-25 01:01:00 +0000 UTC
So, it seems to work as I expected in later versions ... Also found this question Daylight saving time and time zone recommendations This way, it will read carefully.
Thanks.