-
Notifications
You must be signed in to change notification settings - Fork 0
/
day.go
54 lines (44 loc) · 896 Bytes
/
day.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package workcalendar
import "time"
type day struct {
time.Time
hodiday bool
}
func (d day) IsHoliday() bool {
return d.hodiday
}
func isWeekend(t time.Time) bool {
return t.Weekday() == time.Sunday || t.Weekday() == time.Saturday
}
func dayFromTime(t time.Time, holiday bool) day {
return day{
Time: t,
hodiday: holiday,
}
}
type dayListKey struct {
year int
month time.Month
day int
}
func listKey(t time.Time) dayListKey {
return dayListKey{
year: t.Year(),
month: t.Month(),
day: t.Day(),
}
}
func rangeDate(start, end time.Time) func() time.Time {
y, m, d := start.Date()
start = time.Date(y, m, d, 0, 0, 0, 0, start.Location())
y, m, d = end.Date()
end = time.Date(y, m, d, 0, 0, 0, 0, end.Location())
return func() time.Time {
if start.After(end) {
return time.Time{}
}
date := start
start = start.AddDate(0, 0, 1)
return date
}
}