-
Notifications
You must be signed in to change notification settings - Fork 4
/
getters.go
71 lines (59 loc) · 1.94 KB
/
getters.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
package tinydate
import "time"
// Year returns the year as the readable numerical value e.g. 2020
func (td TinyDate) Year() int {
return int(td.year)
}
// Month returns the month of the date 1-12
func (td TinyDate) Month() time.Month {
return time.Month(td.month + 1)
}
// Day retruns the day of the month as an integer
func (td TinyDate) Day() int {
return int(td.day + 1)
}
// String returns the month formatted as a readable string
func (td TinyDate) String() string {
return td.Format(iso8601Date)
}
// IsZero returns true if the date represents the first day,
// January 01, 0000
func (td TinyDate) IsZero() bool {
return td.year == 0 && td.month == 0 && td.day == 0
}
// Unix returns the date as a Unix timestamp
// where the precision is only to the day. Hours, minutes, and seconds
// are just padded zeros
func (td TinyDate) Unix() int64 {
t := td.ToTime()
return t.Unix()
}
// UnixNano returns the date as a Unix timestamp in nanoseconds
// where the precision is only to the day. Hours, minutes, seconds and nanoseconds
// are just padded zeros
func (td TinyDate) UnixNano() int64 {
t := td.ToTime()
return t.UnixNano()
}
// Weekday returns the day of the week
func (td TinyDate) Weekday() time.Weekday {
t := td.ToTime()
return t.Weekday()
}
// YearDay returns the day of the year specified by t, in the range [1,365] for non-leap years, and [1,366] in leap years
func (td TinyDate) YearDay() int {
t := td.ToTime()
return t.YearDay()
}
// ISOWeek returns the ISO 8601 year and week number in which t occurs.
// Week ranges from 1 to 53. Jan 01 to Jan 03 of year n might belong to
// week 52 or 53 of year n-1, and Dec 29 to Dec 31 might belong to week 1
// of year n+1.
func (td TinyDate) ISOWeek() (year, week int) {
t := td.ToTime()
return t.ISOWeek()
}
// Date returns the readable numerical values of the date
func (td TinyDate) Date() (year int, month time.Month, day int) {
return int(td.year), time.Month(td.Month()), int(td.Day())
}