Files
pobounty/timer.go

26 lines
551 B
Go
Raw Normal View History

2023-09-17 13:34:03 -04:00
package main
import (
2023-10-02 14:38:49 -04:00
"math"
2023-09-17 13:34:03 -04:00
"time"
)
2023-10-02 14:38:49 -04:00
/*
totally punked from stackoverflow
https://stackoverflow.com/questions/31327124/how-to-calculate-number-of-business-days-in-golang/51607001#51607001
*/
func GetWeekDaysUntil(target time.Time) int {
start := time.Now()
offset := -int(start.Weekday())
start.AddDate(0, 0, offset)
2023-09-17 13:34:03 -04:00
2023-10-02 14:38:49 -04:00
offset += int(target.Weekday())
if target.Weekday() == time.Sunday {
offset++
2023-09-17 13:34:03 -04:00
}
2023-10-02 14:38:49 -04:00
diff := target.Sub(start).Truncate(time.Hour * 24)
weeks := float64(diff.Hours()/24) / 7
return int(math.Round(weeks)*5) + offset - 1
2023-09-17 13:34:03 -04:00
}