I have the following code in a program and the goal is to make sure an item is accessible within a timeframe. For some reason, this is coming in as false. I've logged the start, end, and now times.The start/end dates are coming in through a JSON request, with no timezone. The time.Now() is giving a timezone. Is that where I'm having my issue? How would I fix it?
func withinStartAndEnd(item Item) bool {
fmt.Println("Start Date", item.Start_date, "
")
fmt.Println("End Date", item.End_date, "
")
fmt.Println("Now:", time.Now(), "
")
//BUG: For some reason event 0's are still not accessible within the timeframe. The fmt's above are to help look at it. time.Now() is printing MST.. maybe that's it?
/*
Start Date 2016-02-19 09:50:00 +0000 +0000
End Date 2016-02-19 10:00:00 +0000 +0000
Now: 2016-02-19 09:59:48.73003196 -0700 MST
2016/02/19 09:59:48 Item not accessible (#148)
*/
return item.Start_date.Before(time.Now()) && item.End_date.After(time.Now())
}
If there really is no time zone, then use UTC, the Coordinated Universal Time.
now := time.Now().UTC()
The goal is to get everything to UTC time. Perhaps, since DB time is actually MST,
// database time zone is Mountain Time
dbt, err := time.LoadLocation("America/Denver")
if err != nil {
fmt.Println(err)
return
}
now := time.Now().UTC()
start := item.Start_date.In(dbt).UTC()
end := item.End_date.In(dbt).UTC()