Skip to content

Commit f967ae2

Browse files
committed
LocationChina => LocChina
1 parent 48ac28f commit f967ae2

10 files changed

+28
-31
lines changed

example_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func ExampleFormatChinaHourMinuteSecond() {
5858
}
5959

6060
func ExampleLocationChina() {
61-
log.Print("now time is :" + time.Now().In(xtime.LocationChina).String())
61+
log.Print("now time is :" + time.Now().In(xtime.LocChina).String())
6262
}
6363
// 直接使用 time.Time 作为json 字段时因为 time.Time{}.UnmarshalJSON() 和 time.Time{}.MarshalJSON() 的原因会以 time.RFC3339 格式作为 layout
6464
func ExampleJSON_RFC3339() {

format.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@ package xtime
22

33
import "time"
44
func FormatChinaYear(t time.Time) string {
5-
return t.In(LocationChina).Format(LayoutYear)
5+
return t.In(LocChina).Format(LayoutYear)
66
}
77
func FormatChinaYearAndMonth(t time.Time) string {
8-
return t.In(LocationChina).Format(LayoutYearAndMonth)
8+
return t.In(LocChina).Format(LayoutYearAndMonth)
99
}
1010
func FormatChinaTime(t time.Time) string {
11-
return t.In(LocationChina).Format(LayoutTime)
11+
return t.In(LocChina).Format(LayoutTime)
1212
}
1313
func FormatChinaDate(t time.Time) string {
14-
return t.In(LocationChina).Format(LayoutDate)
14+
return t.In(LocChina).Format(LayoutDate)
1515
}
1616
func FormatChinaHourMinuteSecond(t time.Time) string {
17-
return t.In(LocationChina).Format(LayoutHourMinuteSecond)
17+
return t.In(LocChina).Format(LayoutHourMinuteSecond)
1818
}

json.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ type ChinaTime struct {
1010
time.Time
1111
}
1212
func NewChinaTime(time time.Time) ChinaTime {
13-
return ChinaTime{Time: time.In(LocationChina)}
13+
return ChinaTime{Time: time.In(LocChina)}
1414
}
1515
func (t ChinaTime) MarshalJSON() ([]byte, error) {
16-
return []byte(`"` + t.In(LocationChina).Format(LayoutTime) + `"`), nil
16+
return []byte(`"` + t.In(LocChina).Format(LayoutTime) + `"`), nil
1717
}
1818
func (t *ChinaTime) UnmarshalJSON(b []byte) error {
19-
v, err := time.ParseInLocation(`"` + LayoutTime + `"`, string(b), LocationChina)
19+
v, err := time.ParseInLocation(`"` + LayoutTime + `"`, string(b), LocChina)
2020
t.Time = v
2121
return err
2222
}

location.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ package xtime
22

33
import "time"
44

5-
var LocationChina = time.FixedZone("CST", 8*3600)
5+
var LocChina = time.FixedZone("CST", 8*3600)

location_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ import (
99
func TestLocation(t *testing.T) {
1010
sometime := time.Date(2020,11,11,11,11,11, 0,time.UTC)
1111
assert.Equal(t, sometime.String(), "2020-11-11 11:11:11 +0000 UTC")
12-
sometime = sometime.In(LocationChina)
12+
sometime = sometime.In(LocChina)
1313
assert.Equal(t, sometime.String(), "2020-11-11 19:11:11 +0800 CST")
1414
}

parse.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ import "time"
44

55

66
func ParseChinaYear(value string) (t time.Time, err error) {
7-
return time.ParseInLocation(LayoutYear, value, LocationChina)
7+
return time.ParseInLocation(LayoutYear, value, LocChina)
88
}
99
func ParseChinaYearAndMonth(value string) (t time.Time, err error) {
10-
return time.ParseInLocation(LayoutYearAndMonth, value, LocationChina)
10+
return time.ParseInLocation(LayoutYearAndMonth, value, LocChina)
1111
}
1212
func ParseChinaDate(value string) (t time.Time, err error) {
13-
return time.ParseInLocation(LayoutDate, value, LocationChina)
13+
return time.ParseInLocation(LayoutDate, value, LocChina)
1414
}
1515
func ParseChinaTime(value string) (t time.Time, err error) {
16-
return time.ParseInLocation(LayoutTime, value, LocationChina)
16+
return time.ParseInLocation(LayoutTime, value, LocChina)
1717
}

parse_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ func mustTime(t time.Time, err error) time.Time {
1111
return t
1212
}
1313
func TestParseChinaYear(t *testing.T) {
14-
assert.Equal(t, time.Date(2021,1,1,0,0,0,0, LocationChina), mustTime(ParseChinaYear("2021")))
14+
assert.Equal(t, time.Date(2021,1,1,0,0,0,0, LocChina), mustTime(ParseChinaYear("2021")))
1515
}
1616
func TestParseChinaYearAndMonth(t *testing.T) {
17-
assert.Equal(t, time.Date(2021,1,1,0,0,0,0, LocationChina), mustTime(ParseChinaYearAndMonth("2021-01")))
17+
assert.Equal(t, time.Date(2021,1,1,0,0,0,0, LocChina), mustTime(ParseChinaYearAndMonth("2021-01")))
1818
}
1919
func TestParseChinaDate(t *testing.T) {
20-
assert.Equal(t, time.Date(2021,01,01,0,0,0,0, LocationChina), mustTime(ParseChinaDate("2021-01-01")))
20+
assert.Equal(t, time.Date(2021,01,01,0,0,0,0, LocChina), mustTime(ParseChinaDate("2021-01-01")))
2121
}
2222
func TestParseChinaTime(t *testing.T) {
23-
assert.Equal(t, time.Date(2021,01,01,7,23,23,0, LocationChina), mustTime(ParseChinaTime("2021-01-01 07:23:23")))
23+
assert.Equal(t, time.Date(2021,01,01,7,23,23,0, LocChina), mustTime(ParseChinaTime("2021-01-01 07:23:23")))
2424
}

time.go

+1-4
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func (d Date) Time(loc *time.Location) time.Time {
7676
return time.Date(d.Year, d.Month, d.Day, 0,0,0,0, loc)
7777
}
7878
func (d Date) ChinaTime() ChinaTime {
79-
return NewChinaTime(d.Time(LocationChina))
79+
return NewChinaTime(d.Time(LocChina))
8080
}
8181
func (d Date) String() string {
8282
return time.Date(d.Year, d.Month, d.Day, 0,0,0,0, time.UTC).Format(LayoutDate)
@@ -104,9 +104,6 @@ type NullDate struct {
104104
func (v NullDate) Date() Date {
105105
return v.date
106106
}
107-
func (v *NullDate) SetDate(date Date) {
108-
v.date = date
109-
}
110107
func (v NullDate) Valid() bool {
111108
return v.valid
112109
}

time_test.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,8 @@ func TestDateSQL(t *testing.T) {
238238
}()
239239
}
240240
func TestNowDate(t *testing.T) {
241-
date := xtime.NowDate(xtime.LocationChina)
242-
y,m,d := time.Now().In(xtime.LocationChina).Date()
241+
date := xtime.NowDate(xtime.LocChina)
242+
y,m,d := time.Now().In(xtime.LocChina).Date()
243243
assert.Equal(t,date, xtime.NewDate(y,m,d))
244244
}
245245
func TestNewDate(t *testing.T) {
@@ -256,7 +256,7 @@ func TestNewDate(t *testing.T) {
256256
}
257257

258258
func TestNewDateForTime(t *testing.T) {
259-
date := xtime.NewDateForTime(time.Date(2022,01,01,0, 0,0,0,xtime.LocationChina))
259+
date := xtime.NewDateForTime(time.Date(2022,01,01,0, 0,0,0,xtime.LocChina))
260260
assert.Equal(t,date, xtime.Date{2022,01,01})
261261
}
262262
func TestParseDate(t *testing.T) {
@@ -298,14 +298,14 @@ func TestDate_MarshalJSON(t *testing.T) {
298298
}
299299
func TestDate_Time(t *testing.T) {
300300
date := xtime.NewDate(2022,11,11)
301-
dateTime := date.Time(xtime.LocationChina)
302-
assert.Equal(t,dateTime, time.Date(2022,11,11,0, 0,0,0,xtime.LocationChina))
301+
dateTime := date.Time(xtime.LocChina)
302+
assert.Equal(t,dateTime, time.Date(2022,11,11,0, 0,0,0,xtime.LocChina))
303303
}
304304

305305
func TestDate_ChinaTime(t *testing.T) {
306306
date := xtime.NewDate(2022,11,11)
307307
dateTime := date.ChinaTime()
308-
assert.Equal(t,dateTime, xtime.NewChinaTime(time.Date(2022,11,11,0, 0,0,0,xtime.LocationChina)))
308+
assert.Equal(t,dateTime, xtime.NewChinaTime(time.Date(2022,11,11,0, 0,0,0,xtime.LocChina)))
309309
}
310310
func TestDate_String(t *testing.T) {
311311
date := xtime.NewDate(2022,11,11)

unix_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ import (
88

99
func TestUnixMilli(t *testing.T) {
1010
{
11-
sometime := time.Date(2020,12,31,23,23,23, 0,LocationChina)
11+
sometime := time.Date(2020,12,31,23,23,23, 0, LocChina)
1212
assert.Equal(t, UnixMilli(sometime), int64(1609428203000), )
1313
}
1414
{
15-
sometime := time.Date(2020,12,31,23,23,23, 333333333,LocationChina)
15+
sometime := time.Date(2020,12,31,23,23,23, 333333333, LocChina)
1616
assert.Equal(t, UnixMilli(sometime), int64(1609428203333), )
1717
}
1818
}

0 commit comments

Comments
 (0)