amocrm/pkg/timer/timer.go

20 lines
338 B
Go
Raw Normal View History

2024-12-03 13:22:05 +00:00
package timer
2024-04-11 12:45:01 +00:00
import (
"time"
)
2024-12-02 20:41:46 +00:00
func CalculateTime(hour int) int64 {
2024-04-11 12:45:01 +00:00
now := time.Now()
2024-12-02 20:41:46 +00:00
targetTime := time.Date(now.Year(), now.Month(), now.Day(), hour, 0, 0, 0, now.Location())
2024-04-11 12:45:01 +00:00
if now.After(targetTime) {
targetTime = targetTime.AddDate(0, 0, 1)
}
toTarget := targetTime.Sub(now)
2024-05-20 09:36:04 +00:00
sec := toTarget.Nanoseconds()
2024-04-11 12:45:01 +00:00
return sec
}