Files
pobounty/timer.go

26 lines
551 B
Go

package main
import (
"math"
"time"
)
/*
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)
offset += int(target.Weekday())
if target.Weekday() == time.Sunday {
offset++
}
diff := target.Sub(start).Truncate(time.Hour * 24)
weeks := float64(diff.Hours()/24) / 7
return int(math.Round(weeks)*5) + offset - 1
}