@@ -13,7 +13,7 @@ func CreateFromStdTime(stdTime StdTime, timezone ...string) *Carbon {
1313 loc * Location
1414 err error
1515 )
16- if loc , err = parseTimezone (timezone [ 0 ] ); err != nil {
16+ if loc , err = parseTimezone (timezone ... ); err != nil {
1717 return & Carbon {Error : err }
1818 }
1919 return NewCarbon (stdTime .In (loc ))
@@ -22,16 +22,10 @@ func CreateFromStdTime(stdTime StdTime, timezone ...string) *Carbon {
2222// CreateFromTimestamp creates a Carbon instance from a given timestamp with second precision.
2323func CreateFromTimestamp (timestamp int64 , timezone ... string ) * Carbon {
2424 var (
25- tz string
2625 loc * Location
2726 err error
2827 )
29- if len (timezone ) > 0 {
30- tz = timezone [0 ]
31- } else {
32- tz = DefaultTimezone
33- }
34- if loc , err = parseTimezone (tz ); err != nil {
28+ if loc , err = parseTimezone (timezone ... ); err != nil {
3529 return & Carbon {Error : err }
3630 }
3731 return NewCarbon (time .Unix (timestamp , MinNanosecond ).In (loc ))
@@ -40,16 +34,10 @@ func CreateFromTimestamp(timestamp int64, timezone ...string) *Carbon {
4034// CreateFromTimestampMilli creates a Carbon instance from a given timestamp with millisecond precision.
4135func CreateFromTimestampMilli (timestampMilli int64 , timezone ... string ) * Carbon {
4236 var (
43- tz string
4437 loc * Location
4538 err error
4639 )
47- if len (timezone ) > 0 {
48- tz = timezone [0 ]
49- } else {
50- tz = DefaultTimezone
51- }
52- if loc , err = parseTimezone (tz ); err != nil {
40+ if loc , err = parseTimezone (timezone ... ); err != nil {
5341 return & Carbon {Error : err }
5442 }
5543 return NewCarbon (time .Unix (timestampMilli / 1e3 , (timestampMilli % 1e3 )* 1e6 ).In (loc ))
@@ -58,16 +46,10 @@ func CreateFromTimestampMilli(timestampMilli int64, timezone ...string) *Carbon
5846// CreateFromTimestampMicro creates a Carbon instance from a given timestamp with microsecond precision.
5947func CreateFromTimestampMicro (timestampMicro int64 , timezone ... string ) * Carbon {
6048 var (
61- tz string
6249 loc * Location
6350 err error
6451 )
65- if len (timezone ) > 0 {
66- tz = timezone [0 ]
67- } else {
68- tz = DefaultTimezone
69- }
70- if loc , err = parseTimezone (tz ); err != nil {
52+ if loc , err = parseTimezone (timezone ... ); err != nil {
7153 return & Carbon {Error : err }
7254 }
7355 return NewCarbon (time .Unix (timestampMicro / 1e6 , (timestampMicro % 1e6 )* 1e3 ).In (loc ))
@@ -76,16 +58,10 @@ func CreateFromTimestampMicro(timestampMicro int64, timezone ...string) *Carbon
7658// CreateFromTimestampNano creates a Carbon instance from a given timestamp with nanosecond precision.
7759func CreateFromTimestampNano (timestampNano int64 , timezone ... string ) * Carbon {
7860 var (
79- tz string
8061 loc * Location
8162 err error
8263 )
83- if len (timezone ) > 0 {
84- tz = timezone [0 ]
85- } else {
86- tz = DefaultTimezone
87- }
88- if loc , err = parseTimezone (tz ); err != nil {
64+ if loc , err = parseTimezone (timezone ... ); err != nil {
8965 return & Carbon {Error : err }
9066 }
9167 return NewCarbon (time .Unix (timestampNano / 1e9 , timestampNano % 1e9 ).In (loc ))
@@ -158,16 +134,10 @@ func CreateFromTimeNano(hour, minute, second, nanosecond int, timezone ...string
158134// creates a new Carbon instance from a given date, time and nanosecond.
159135func create (year , month , day , hour , minute , second , nanosecond int , timezone ... string ) * Carbon {
160136 var (
161- tz string
162137 loc * Location
163138 err error
164139 )
165- if len (timezone ) > 0 {
166- tz = timezone [0 ]
167- } else {
168- tz = DefaultTimezone
169- }
170- if loc , err = parseTimezone (tz ); err != nil {
140+ if loc , err = parseTimezone (timezone ... ); err != nil {
171141 return & Carbon {Error : err }
172142 }
173143 return NewCarbon (time .Date (year , time .Month (month ), day , hour , minute , second , nanosecond , loc ))
0 commit comments