ai-week/tools/checktime.go

41 lines
1.3 KiB
Go

package tools
import "time"
func TimeUntilFriday() time.Duration {
today := time.Now()
weekday := today.Weekday()
switch weekday {
case time.Monday:
friday := time.Date(today.Year(), today.Month(), today.Day()+4, 17, 0, 0, 0, today.Location())
return friday.Sub(today)
case time.Tuesday:
friday := time.Date(today.Year(), today.Month(), today.Day()+3, 17, 0, 0, 0, today.Location())
return friday.Sub(today)
case time.Wednesday:
friday := time.Date(today.Year(), today.Month(), today.Day()+2, 17, 0, 0, 0, today.Location())
return friday.Sub(today)
case time.Thursday:
friday := time.Date(today.Year(), today.Month(), today.Day()+1, 17, 0, 0, 0, today.Location())
return friday.Sub(today)
case time.Friday:
friday := time.Date(today.Year(), today.Month(), today.Day(), 17, 0, 0, 0, today.Location())
if friday.Sub(today) > 0 {
return friday.Sub(today)
} else if friday.Sub(today) < 0 {
friday = time.Date(today.Year(), today.Month(), today.Day()+7, 17, 0, 0, 0, today.Location())
return friday.Sub(today)
} else {
return 0
}
case time.Saturday:
friday := time.Date(today.Year(), today.Month(), today.Day()+6, 17, 0, 0, 0, today.Location())
return friday.Sub(today)
case time.Sunday:
friday := time.Date(today.Year(), today.Month(), today.Day()+5, 17, 0, 0, 0, today.Location())
return friday.Sub(today)
}
return 0
}