/
time.go
134 lines (122 loc) · 4.53 KB
/
time.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
package helper
import "time"
// IsBeforeNow if the parameter entered was before now it will return true, otherwise it will return false
func IsBeforeNow(a any) bool {
t, err := ConvertToTime(a)
if err != nil {
panic("the parameter A error to convert to time:" + err.Error())
}
return t.Before(time.Now())
}
// IsBeforeDateToday If the parameter entered is before today it will return true, otherwise it will return false
func IsBeforeDateToday(a any) bool {
t, err := ConvertToTime(a)
if err != nil {
panic("the parameter A error to convert to time:" + err.Error())
}
t = time.Date(t.Year(), t.Month(), t.Day(), 0, 0, 0, 0, t.Location())
now := time.Now()
now = time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, t.Location())
return t.Before(time.Now())
}
// IsBeforeDate If parameter A has a date before the date of parameter B, it returns true, otherwise it will return false.
func IsBeforeDate(a, b any) bool {
ta, err := ConvertToTime(a)
if err != nil {
panic("the parameter A error to convert to time:" + err.Error())
}
tb, err := ConvertToTime(b)
if err != nil {
panic("the parameter B error to convert to time:" + err.Error())
}
ta = time.Date(ta.Year(), ta.Month(), ta.Day(), 0, 0, 0, 0, ta.Location())
tb = time.Date(tb.Year(), tb.Month(), tb.Day(), 0, 0, 0, 0, tb.Location())
return ta.Before(tb)
}
// IsBefore If parameter A is before parameter B it will return true, otherwise it will return false.
func IsBefore(a, b any) bool {
ta, err := ConvertToTime(a)
if err != nil {
panic("the parameter A error to convert to time:" + err.Error())
}
tb, err := ConvertToTime(b)
if err != nil {
panic("the parameter B error to convert to time:" + err.Error())
}
return ta.Before(tb)
}
// IsAfterNow if the parameter entered was after now it will return true, otherwise it will return false
func IsAfterNow(a any) bool {
t, err := ConvertToTime(a)
if err != nil {
panic("the parameter A error to convert to time:" + err.Error())
}
return t.After(time.Now())
}
// IsAfterDateToday If the parameter entered is after today it will return true, otherwise it will return false
func IsAfterDateToday(a any) bool {
t, err := ConvertToTime(a)
if err != nil {
panic("the parameter A error to convert to time:" + err.Error())
}
t = time.Date(t.Year(), t.Month(), t.Day(), 0, 0, 0, 0, t.Location())
now := time.Now()
now = time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, t.Location())
return t.After(time.Now())
}
// IsAfterDate If parameter A has a date after the date of parameter B, it returns true, otherwise it will return false.
func IsAfterDate(a, b any) bool {
ta, err := ConvertToTime(a)
if err != nil {
panic("the parameter A error to convert to time:" + err.Error())
}
tb, err := ConvertToTime(b)
if err != nil {
panic("the parameter B error to convert to time:" + err.Error())
}
ta = time.Date(ta.Year(), ta.Month(), ta.Day(), 0, 0, 0, 0, ta.Location())
tb = time.Date(tb.Year(), tb.Month(), tb.Day(), 0, 0, 0, 0, tb.Location())
return ta.After(tb)
}
// IsAfter If parameter A is after parameter B it will return true, otherwise it will return false.
func IsAfter(a, b any) bool {
ta, err := ConvertToTime(a)
if err != nil {
panic("the parameter A error to convert to time:" + err.Error())
}
tb, err := ConvertToTime(b)
if err != nil {
panic("the parameter B error to convert to time:" + err.Error())
}
return ta.After(tb)
}
// IsToday If the parameter entered is today it will return true, otherwise it will return false
func IsToday(a any) bool {
t, err := ConvertToTime(a)
if err != nil {
panic("the parameter A error to convert to time:" + err.Error())
}
t = time.Date(t.Year(), t.Month(), t.Day(), 0, 0, 0, 0, t.Location())
now := time.Now()
now = time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, t.Location())
return t.Equal(now)
}
// IsNow If the parameter entered is now (not counting the nanosecond) it will return true, otherwise it will return false
func IsNow(a any) bool {
t, err := ConvertToTime(a)
if err != nil {
panic("the parameter A error to convert to time:" + err.Error())
}
t = time.Date(t.Year(), t.Month(), t.Day(), t.Hour(), t.Minute(), t.Second(), 0, t.Location())
now := time.Now()
now = time.Date(now.Year(), now.Month(), now.Day(), t.Hour(), t.Minute(), t.Second(), 0, t.Location())
return t.Equal(now)
}
// IsFullNow If the parameter entered is now it will return true, otherwise it will return false
func IsFullNow(a any) bool {
t, err := ConvertToTime(a)
if err != nil {
panic("the parameter A error to convert to time:" + err.Error())
}
return t.Equal(time.Now())
}