-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathutils.go
More file actions
99 lines (88 loc) · 1.75 KB
/
Copy pathutils.go
File metadata and controls
99 lines (88 loc) · 1.75 KB
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
package chronos
import (
"time"
)
func parseFirstArg(v []any) any {
if len(v) > 0 {
return v[0]
}
return nil
}
func parseArgs(v []any) []any {
if len(v) > 1 {
return v[1:]
}
return nil
}
func parseStringFormat(f string, v ...any) string {
if len(v) == 0 {
return f
}
df, ok := (v[0]).(string)
if ok {
f = df
}
return f
}
func parseStringDateFormat(t string, vv ...string) *calendarTime {
c := &calendarTime{
time: localTime(),
}
if t == "" {
return c
}
f := DateFormatYMDHMS
if len(vv) > 0 {
f = vv[0]
}
tt, err := time.ParseInLocation(f, t, loc)
if err == nil {
c.time = tt
}
return c
}
func parseStringDate(t string, vv ...any) *calendarTime {
c := &calendarTime{
time: localTime(),
}
if t == "" {
return c
}
f := parseStringFormat(DateFormatYMDHMS, vv...)
tt, err := time.ParseInLocation(f, t, loc)
if err == nil {
c.time = tt
}
return c
}
func parseTime(t time.Time) *calendarTime {
c := &calendarTime{
time: t,
}
return c
}
// ParseTime creates a Calendar from a time.Time value.
func ParseTime(t time.Time) Calendar {
return parseTime(t).initialize()
}
func parseIntDate(vv int, args ...any) *calendarTime {
var c calendarTime
switch len(args) {
case 0:
c.time = TimeFromY(vv)
case 1:
c.time = TimeFromYm(vv, args[0].(time.Month))
case 2:
c.time = TimeFromYmd(vv, args[0].(time.Month), args[1].(int))
case 3:
c.time = TimeFromYmdHms(vv, args[0].(time.Month), args[1].(int), args[2].(int), 0, 0)
case 4:
c.time = TimeFromYmdHms(vv, args[0].(time.Month), args[1].(int), args[2].(int), args[3].(int), 0)
default:
c.time = TimeFromYmdHms(vv, args[0].(time.Month), args[1].(int), args[2].(int), args[3].(int), args[4].(int))
}
return &c
}
func localTime() time.Time {
return time.Now().In(loc)
}