-
Notifications
You must be signed in to change notification settings - Fork 1
/
date.go
61 lines (53 loc) · 1023 Bytes
/
date.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
package dateparser
import (
// "fmt"
"time"
)
type Date struct {
year int
month int
day int
hour int
minute int
second int
weekday int
tz *time.Location
}
func (d *Date) AddDefault(t *time.Time) *Date {
if t == nil {
zero := time.Time{}
t = &zero
}
if d.year == 0 {
d.year = t.Year()
}
if d.month == 0 {
d.month = int(t.Month())
}
if d.day == 0 {
d.day = t.Day()
}
// if d.hour == 0 {
// d.hour = t.Hour()
// }
// if d.minute == 0 {
// d.minute = t.Minute()
// }
// if d.second == 0 {
// d.second = t.Second()
// }
// if d.tz == nil {
// d.tz = t.Location()
// }
return d
}
func (d *Date) ToTime() time.Time {
loc := d.tz
if loc == nil {
loc = time.UTC
}
return time.Date(d.year, time.Month(d.month), d.day, d.hour, d.minute, d.second, 0, loc)
}
func (d *Date) String() string {
return d.ToTime().String()
}