-
Notifications
You must be signed in to change notification settings - Fork 1
/
formatter.go
162 lines (125 loc) · 2.71 KB
/
formatter.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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
package datebin
/**
* 格式化时间 / Formatter time
*
* @create 2022-12-11
* @author deatil
*/
type Formatter struct {
// 传入的时间 / input time
time int64
}
// 构造函数
// New Formatter
func NewFormatter() Formatter {
return Formatter{}
}
// 设置时间
// set Time
func (this Formatter) WithTime(data int64) Formatter {
this.time = data
return this
}
// 获取时间
// Get Time
func (this Formatter) GetTime() int64 {
return this.time
}
// 传入周
// set Week
func (this Formatter) FromWeek(data int64) Formatter {
this.time = data * int64(Day) * 7
return this
}
// 传入天
// set Day
func (this Formatter) FromDay(data int64) Formatter {
this.time = data * int64(Day)
return this
}
// 传入小时
// set Hour
func (this Formatter) FromHour(data int64) Formatter {
this.time = data * int64(Hour)
return this
}
// 传入分钟
// set Minute
func (this Formatter) FromMinute(data int64) Formatter {
this.time = data * int64(Minute)
return this
}
// 传入秒
// set Second
func (this Formatter) FromSecond(data int64) Formatter {
this.time = data * int64(Second)
return this
}
// 传入毫秒
// set Millisecond
func (this Formatter) FromMillisecond(data int64) Formatter {
this.time = data * int64(Millisecond)
return this
}
// 传入微秒
// set Microsecond
func (this Formatter) FromMicrosecond(data int64) Formatter {
this.time = data * int64(Microsecond)
return this
}
// 传入纳秒
// set Nanosecond
func (this Formatter) FromNanosecond(data int64) Formatter {
this.time = data
return this
}
// 获取周数和天数
// get Week And Day
func (this Formatter) WeekAndDay() (int, int) {
weeks := this.time / int64(Week)
days := (this.time % int64(Week)) / int64(Day)
return int(weeks), int(days)
}
// 获取天
// get Day
func (this Formatter) Day() int {
data := this.time / int64(Day)
return int(data)
}
// 获取小时
// get Hour
func (this Formatter) Hour() int {
data := (this.time % int64(Day)) / int64(Hour)
return int(data)
}
// 获取分钟
// get Minute
func (this Formatter) Minute() int {
data := (this.time % int64(Hour)) / int64(Minute)
return int(data)
}
// 获取秒
// get Second
func (this Formatter) Second() int {
data := (this.time % int64(Minute)) / int64(Second)
return int(data)
}
// 获取毫秒
// get Millisecond
func (this Formatter) Millisecond() int {
data := (this.time % int64(Second)) / int64(Millisecond)
return int(data)
}
// 获取微秒
// get Microsecond
func (this Formatter) Microsecond() int {
data := (this.time % int64(Millisecond)) / int64(Microsecond)
return int(data)
}
// 获取纳秒
// get Nanosecond
func (this Formatter) Nanosecond() int {
// 余数 / mod
data := this.time % int64(Microsecond)
return int(data)
}