-
Notifications
You must be signed in to change notification settings - Fork 31
/
dates.go
33 lines (26 loc) · 747 Bytes
/
dates.go
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 slick
import (
"strconv"
"strings"
"time"
"github.com/nlopes/slack"
)
func NextWeekdayTime(w time.Weekday, hour, min int) (time.Time, time.Duration) {
t := time.Now().UTC()
nowWeekday := t.Weekday()
nowYear, nowMonth, nowDay := t.Date()
delta := (int(w) - int(nowWeekday) + 7) % 7
res := time.Date(nowYear, nowMonth, nowDay+delta, hour, min, 0, 0, t.Location())
if res.Sub(t) <= 0 {
res = res.AddDate(0, 0, 7)
}
return res, res.Sub(t)
}
func AfterNextWeekdayTime(w time.Weekday, hour, min int) <-chan time.Time {
_, duration := NextWeekdayTime(w, hour, min)
return time.After(duration)
}
func unixFromTimestamp(ts string) slack.JSONTime {
i, _ := strconv.Atoi(strings.Split(ts, ".")[0])
return slack.JSONTime(i)
}