Created
January 2, 2013 21:55
-
-
Save anonymous/4438527 to your computer and use it in GitHub Desktop.
Most irritating datetime implemenation ever
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
id := line[0] | |
length , err := strconv.ParseInt(line[1], 10, 64) | |
if err != nil{ | |
log.Printf("Error parsing duration - empty? %v", err) | |
length = 0 | |
} | |
//The DAY component of this may be wrong, but the time will be correct, in GMT | |
time, err := strconv.ParseInt(line[2], 10, 64) | |
if err != nil{ | |
log.Printf("Error parsing time - empty time? %v", err) | |
time = 0 | |
} | |
//The TIME component of this will be wrong (noon), but the DATE will be correct, in GMT | |
date, err := strconv.ParseInt(line[3], 10, 64) | |
if err != nil{ | |
log.Printf("Error parsing date - empty date? %v", err) | |
date= 0 | |
} | |
//The day and clock time (hour/min/sec) are correct when read in GMT and interpreted as local time | |
year, month, day := time.Unix(date, 0).UTC().Date() | |
hour, min, sec := time.Unix(time, 0).UTC().Clock() | |
//For some reason it gives the year as 1974 sometimes | |
if year < 2010 { | |
year, _, _ = time.Now().Date() | |
} | |
log.Printf("HERE: %d %d %d %d %d %d", year, month, day, hour, min, sec) | |
:= time.Date(year, month, day, hour, min, sec, 0, time.Local) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment