-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathperiod_rule.go
120 lines (81 loc) · 3.83 KB
/
period_rule.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
// Copyright © 2020 Danila Petrunko. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package rdate
import "time"
type PeriodRule interface {
Calculate(pivot time.Time, tf TimeFactory) (from, to Time)
Shortcut() PeriodShortcut
}
type periodRuleThisDay struct{}
func (p *periodRuleThisDay) Calculate(pivot time.Time, tf TimeFactory) (from, to Time) {
return tf.Require(pivot, TimeStartOfThisDay),
tf.Require(pivot, TimeEndOfThisDay)
}
func (p *periodRuleThisDay) Shortcut() PeriodShortcut { return PeriodThisDay }
type periodRulePrevDay struct{}
func (p *periodRulePrevDay) Calculate(pivot time.Time, tf TimeFactory) (from, to Time) {
return tf.Require(pivot, TimeStartOfPrevDay),
tf.Require(pivot, TimeEndOfPrevDay)
}
func (p *periodRulePrevDay) Shortcut() PeriodShortcut { return PeriodPrevDay }
type periodRulePrevWeek struct{}
func (p *periodRulePrevWeek) Calculate(pivot time.Time, tf TimeFactory) (from, to Time) {
return tf.Require(pivot, TimeStartOfPrevWeek),
tf.Require(pivot, TimeEndOfPrevWeek)
}
func (p *periodRulePrevWeek) Shortcut() PeriodShortcut { return PeriodPrevWeek }
type periodRulePrevMonth struct{}
func (p *periodRulePrevMonth) Calculate(pivot time.Time, tf TimeFactory) (from, to Time) {
return tf.Require(pivot, TimeStartOfPrevMonth),
tf.Require(pivot, TimeEndOfPrevMonth)
}
func (p *periodRulePrevMonth) Shortcut() PeriodShortcut { return PeriodPrevMonth }
type periodRulePrevQuart struct{}
func (p *periodRulePrevQuart) Calculate(pivot time.Time, tf TimeFactory) (from, to Time) {
return tf.Require(pivot, TimeStartOfPrevQuart),
tf.Require(pivot, TimeEndOfPrevQuart)
}
func (p *periodRulePrevQuart) Shortcut() PeriodShortcut { return PeriodPrevQuart }
type periodRulePrevHalfYear struct{}
func (p *periodRulePrevHalfYear) Calculate(pivot time.Time, tf TimeFactory) (from, to Time) {
return tf.Require(pivot, TimeStartOfPrevHalfYear),
tf.Require(pivot, TimeEndOfPrevHalfYear)
}
func (p *periodRulePrevHalfYear) Shortcut() PeriodShortcut { return PeriodPrevHalfYear }
type periodRulePrevYear struct{}
func (p *periodRulePrevYear) Calculate(pivot time.Time, tf TimeFactory) (from, to Time) {
return tf.Require(pivot, TimeStartOfPrevYear),
tf.Require(pivot, TimeEndOfPrevYear)
}
func (p *periodRulePrevYear) Shortcut() PeriodShortcut { return PeriodPrevYear }
type periodRuleThisWeek struct{}
func (p *periodRuleThisWeek) Calculate(pivot time.Time, tf TimeFactory) (from, to Time) {
return tf.Require(pivot, TimeStartOfThisWeek),
tf.Require(pivot, TimeEndOfThisWeek)
}
func (p *periodRuleThisWeek) Shortcut() PeriodShortcut { return PeriodThisWeek }
type periodRuleThisMonth struct{}
func (p *periodRuleThisMonth) Calculate(pivot time.Time, tf TimeFactory) (from, to Time) {
return tf.Require(pivot, TimeStartOfThisMonth),
tf.Require(pivot, TimeEndOfThisMonth)
}
func (p *periodRuleThisMonth) Shortcut() PeriodShortcut { return PeriodThisMonth }
type periodRuleThisQuart struct{}
func (p *periodRuleThisQuart) Calculate(pivot time.Time, tf TimeFactory) (from, to Time) {
return tf.Require(pivot, TimeStartOfThisQuart),
tf.Require(pivot, TimeEndOfThisQuart)
}
func (p *periodRuleThisQuart) Shortcut() PeriodShortcut { return PeriodThisQuart }
type periodRuleThisHalfYear struct{}
func (p *periodRuleThisHalfYear) Calculate(pivot time.Time, tf TimeFactory) (from, to Time) {
return tf.Require(pivot, TimeStartOfThisHalfYear),
tf.Require(pivot, TimeEndOfThisHalfYear)
}
func (p *periodRuleThisHalfYear) Shortcut() PeriodShortcut { return PeriodThisHalfYear }
type periodRuleThisYear struct{}
func (p *periodRuleThisYear) Calculate(pivot time.Time, tf TimeFactory) (from, to Time) {
return tf.Require(pivot, TimeStartOfThisYear),
tf.Require(pivot, TimeEndOfThisYear)
}
func (p *periodRuleThisYear) Shortcut() PeriodShortcut { return PeriodThisYear }