I am trying to find a way to check if the current time is in a given interval, where start and end are given (eventually) by a user.
I have been trying by using the After and Before from the Time package after making sure all times are in UTC, but clearly I am doing something wrong.
The code looks similar to this example:
func inTimeSpan(start, end, check time.Time) bool {
return check.After(start) && check.Before(end)
}
func main() {
now := time.Now()
newLayout := "15:04"
ns, _ := time.Parse(newLayout, strconv.Itoa(now.Hour())+":"+strconv.Itoa(now.Minute()))
srt, _ := time.Parse(newLayout, "23:00")
end, _ := time.Parse(newLayout, "05:00")
fmt.Println("1 : ", inTimeSpan(srt, end, ns))
}
Any help is appreciated.