1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| package main
import ( "fmt" "time" )
const INTERVAL_PERIOD time.Duration = 24 * time.Hour
const HOUR_TO_TICK int = 23 const MINUTE_TO_TICK int = 00 const SECOND_TO_TICK int = 03
func main() { ticker := updateTicker() for { <-ticker.C fmt.Println(time.Now(), "- just ticked") ticker = updateTicker() } }
func updateTicker() *time.Ticker { n := time.Date(time.Now().Year(), time.Now().Month(), time.Now().Day(), HOUR_TO_TICK, MINUTE_TO_TICK, SECOND_TO_TICK, 0, time.Local)
if !n.After(time.Now()) { n = n.Add(INTERVAL_PERIOD) } fmt.Println(n, "- next tick") diff := n.Sub(time.Now()) return time.NewTicker(diff) }
|