Skip to content

Commit d37cf9c

Browse files
committed
refactor: Refactor time related type definitions
1 parent 5e67390 commit d37cf9c

File tree

1 file changed

+58
-68
lines changed

1 file changed

+58
-68
lines changed

type_builtin.go

Lines changed: 58 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,47 @@
11
package carbon
22

3+
type (
4+
timestampType int64
5+
timestampMicroType int64
6+
timestampMilliType int64
7+
timestampNanoType int64
8+
9+
datetimeType string
10+
datetimeMicroType string
11+
datetimeMilliType string
12+
datetimeNanoType string
13+
14+
dateType string
15+
dateMilliType string
16+
dateMicroType string
17+
dateNanoType string
18+
19+
timeType string
20+
timeMilliType string
21+
timeMicroType string
22+
timeNanoType string
23+
)
24+
325
type (
426
Timestamp = TimestampType[timestampType]
527
TimestampMilli = TimestampType[timestampMilliType]
628
TimestampMicro = TimestampType[timestampMicroType]
729
TimestampNano = TimestampType[timestampNanoType]
830

9-
DateTime = LayoutType[DateTimeType]
10-
DateTimeMicro = LayoutType[DateTimeMicroType]
11-
DateTimeMilli = LayoutType[DateTimeMilliType]
12-
DateTimeNano = LayoutType[DateTimeNanoType]
31+
DateTime = LayoutType[datetimeType]
32+
DateTimeMicro = LayoutType[datetimeMicroType]
33+
DateTimeMilli = LayoutType[datetimeMilliType]
34+
DateTimeNano = LayoutType[datetimeNanoType]
1335

14-
Date = LayoutType[DateType]
15-
DateMilli = LayoutType[DateMilliType]
16-
DateMicro = LayoutType[DateMicroType]
17-
DateNano = LayoutType[DateNanoType]
36+
Date = LayoutType[dateType]
37+
DateMilli = LayoutType[dateMilliType]
38+
DateMicro = LayoutType[dateMicroType]
39+
DateNano = LayoutType[dateNanoType]
1840

19-
Time = LayoutType[TimeType]
20-
TimeMilli = LayoutType[TimeMilliType]
21-
TimeMicro = LayoutType[TimeMicroType]
22-
TimeNano = LayoutType[TimeNanoType]
41+
Time = LayoutType[timeType]
42+
TimeMilli = LayoutType[timeMilliType]
43+
TimeMicro = LayoutType[timeMicroType]
44+
TimeNano = LayoutType[timeNanoType]
2345
)
2446

2547
func NewTimestamp(c Carbon) Timestamp {
@@ -36,136 +58,104 @@ func NewTimestampNano(c Carbon) TimestampNano {
3658
}
3759

3860
func NewDateTime(c Carbon) DateTime {
39-
return NewLayoutType[DateTimeType](c)
61+
return NewLayoutType[datetimeType](c)
4062
}
4163
func NewDateTimeMilli(c Carbon) DateTimeMilli {
42-
return NewLayoutType[DateTimeMilliType](c)
64+
return NewLayoutType[datetimeMilliType](c)
4365
}
4466
func NewDateTimeMicro(c Carbon) DateTimeMicro {
45-
return NewLayoutType[DateTimeMicroType](c)
67+
return NewLayoutType[datetimeMicroType](c)
4668
}
4769
func NewDateTimeNano(c Carbon) DateTimeNano {
48-
return NewLayoutType[DateTimeNanoType](c)
70+
return NewLayoutType[datetimeNanoType](c)
4971
}
5072

5173
func NewDate(c Carbon) Date {
52-
return NewLayoutType[DateType](c)
74+
return NewLayoutType[dateType](c)
5375
}
5476
func NewDateMilli(c Carbon) DateMilli {
55-
return NewLayoutType[DateMilliType](c)
77+
return NewLayoutType[dateMilliType](c)
5678
}
5779
func NewDateMicro(c Carbon) DateMicro {
58-
return NewLayoutType[DateMicroType](c)
80+
return NewLayoutType[dateMicroType](c)
5981
}
6082
func NewDateNano(c Carbon) DateNano {
61-
return NewLayoutType[DateNanoType](c)
83+
return NewLayoutType[dateNanoType](c)
6284
}
6385

6486
func NewTime(c Carbon) Time {
65-
return NewLayoutType[TimeType](c)
87+
return NewLayoutType[timeType](c)
6688
}
6789
func NewTimeMilli(c Carbon) TimeMilli {
68-
return NewLayoutType[TimeMilliType](c)
90+
return NewLayoutType[timeMilliType](c)
6991
}
7092
func NewTimeMicro(c Carbon) TimeMicro {
71-
return NewLayoutType[TimeMicroType](c)
93+
return NewLayoutType[timeMicroType](c)
7294
}
7395
func NewTimeNano(c Carbon) TimeNano {
74-
return NewLayoutType[TimeNanoType](c)
96+
return NewLayoutType[timeNanoType](c)
7597
}
7698

77-
type timestampType int64
78-
7999
func (t timestampType) Precision() string {
80100
return PrecisionSecond
81101
}
82102

83-
type timestampMilliType int64
84-
85103
func (t timestampMilliType) Precision() string {
86104
return PrecisionMillisecond
87105
}
88106

89-
type timestampMicroType int64
90-
91107
func (t timestampMicroType) Precision() string {
92108
return PrecisionMicrosecond
93109
}
94110

95-
type timestampNanoType int64
96-
97111
func (t timestampNanoType) Precision() string {
98112
return PrecisionNanosecond
99113
}
100114

101-
type DateTimeType string
102-
103-
func (t DateTimeType) Layout() string {
115+
func (t datetimeType) Layout() string {
104116
return DateTimeLayout
105117
}
106118

107-
type DateTimeMilliType string
108-
109-
func (t DateTimeMilliType) Layout() string {
119+
func (t datetimeMilliType) Layout() string {
110120
return DateTimeMilliLayout
111121
}
112122

113-
type DateTimeMicroType string
114-
115-
func (t DateTimeMicroType) Layout() string {
123+
func (t datetimeMicroType) Layout() string {
116124
return DateTimeMicroLayout
117125
}
118126

119-
type DateTimeNanoType string
120-
121-
func (t DateTimeNanoType) Layout() string {
127+
func (t datetimeNanoType) Layout() string {
122128
return DateTimeNanoLayout
123129
}
124130

125-
type DateType string
126-
127-
func (t DateType) Layout() string {
131+
func (t dateType) Layout() string {
128132
return DateLayout
129133
}
130134

131-
type DateMilliType string
132-
133-
func (t DateMilliType) Layout() string {
135+
func (t dateMilliType) Layout() string {
134136
return DateMilliLayout
135137
}
136138

137-
type DateMicroType string
138-
139-
func (t DateMicroType) Layout() string {
139+
func (t dateMicroType) Layout() string {
140140
return DateMicroLayout
141141
}
142142

143-
type DateNanoType string
144-
145-
func (t DateNanoType) Layout() string {
143+
func (t dateNanoType) Layout() string {
146144
return DateNanoLayout
147145
}
148146

149-
type TimeType string
150-
151-
func (t TimeType) Layout() string {
147+
func (t timeType) Layout() string {
152148
return TimeLayout
153149
}
154150

155-
type TimeMilliType string
156-
157-
func (t TimeMilliType) Layout() string {
151+
func (t timeMilliType) Layout() string {
158152
return TimeMilliLayout
159153
}
160154

161-
type TimeMicroType string
162-
163-
func (t TimeMicroType) Layout() string {
155+
func (t timeMicroType) Layout() string {
164156
return TimeMicroLayout
165157
}
166158

167-
type TimeNanoType string
168-
169-
func (t TimeNanoType) Layout() string {
159+
func (t timeNanoType) Layout() string {
170160
return TimeNanoLayout
171161
}

0 commit comments

Comments
 (0)