-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtime.go
46 lines (37 loc) · 946 Bytes
/
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
package date
import "time"
// Before compares date if it's before or not
func (d Date) Before(ref Date) bool {
return d.ToTime().Before(ref.ToTime())
}
// After compares date if it's after or not
func (d Date) After(ref Date) bool {
return d.ToTime().After(ref.ToTime())
}
// YMD returns year, month and day of the Date
func (d Date) YMD() (year int, month time.Month, day int) {
return d.ToTime().Date()
}
// Year returns the year of the Date
func (d Date) Year() int {
y, _, _ := d.YMD()
return y
}
// Month returns the month of the Date
func (d Date) Month() time.Month {
_, m, _ := d.YMD()
return m
}
// Day returns the day of the NullDate
func (d Date) Day() int {
_, _, day := d.YMD()
return day
}
// Sub return duration date - ref
func (d Date) Sub(ref Date) time.Duration {
return d.ToTime().Sub(ref.ToTime())
}
// Equal to compare with another
func (d Date) Equal(ref Date) bool {
return d.String() == ref.String()
}