Skip to content

Commit 11e5e8d

Browse files
committed
begin -> start
1 parent 4c40e56 commit 11e5e8d

File tree

3 files changed

+12
-13
lines changed

3 files changed

+12
-13
lines changed

json.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
11
package xtime
22

3-
43
import (
5-
"time"
4+
"time"
65
)
76

8-
97
type ChinaTime struct {
108
time.Time
119
}
10+
1211
func NewChinaTime(time time.Time) ChinaTime {
1312
return ChinaTime{Time: time.In(LocChina)}
1413
}
1514
func (t ChinaTime) MarshalJSON() ([]byte, error) {
1615
return []byte(`"` + t.In(LocChina).Format(LayoutTime) + `"`), nil
1716
}
1817
func (t *ChinaTime) UnmarshalJSON(b []byte) error {
19-
v, err := time.ParseInLocation(`"` + LayoutTime + `"`, string(b), LocChina)
18+
v, err := time.ParseInLocation(`"`+LayoutTime+`"`, string(b), LocChina)
2019
t.Time = v
2120
return err
2221
}

time.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@ import (
1111
)
1212

1313
type Range struct {
14-
Begin time.Time
14+
Start time.Time
1515
End time.Time
1616
}
1717

1818
func InRange(target time.Time, r Range) (in bool) {
19-
begin := r.Begin
19+
begin := r.Start
2020
end := r.End
21-
if r.Begin.After(r.End) {
21+
if r.Start.After(r.End) {
2222
begin = r.End
23-
end = r.Begin
24-
log.Print("goclub/time: InRange(target time.Time, r Range) r.Begin can not be after r.End, InRange() already replacement they")
23+
end = r.Start
24+
log.Print("goclub/time: InRange(target time.Time, r Range) r.Start can not be after r.End, InRange() already replacement they")
2525
}
2626
// begin <= target <= end -> true
2727
if (begin.Before(target) || begin.Equal(target)) &&
@@ -33,13 +33,13 @@ func InRange(target time.Time, r Range) (in bool) {
3333
}
3434

3535
type DateRange struct {
36-
Begin Date `note:"当日期是 2022-01-01 时等同于 Range{Begin: 2022-01-01 00:00:00}"`
36+
Begin Date `note:"当日期是 2022-01-01 时等同于 Range{Start: 2022-01-01 00:00:00}"`
3737
End Date `note:"当日期是 2022-01-03 时等同于 Range{End: 2022-01-03 23:59:59}"`
3838
}
3939

4040
func InRangeFromDate(target time.Time, r DateRange) (in bool) {
4141
timeRange := Range{
42-
Begin: FirstSecondOfDate(r.Begin.Time(target.Location())),
42+
Start: FirstSecondOfDate(r.Begin.Time(target.Location())),
4343
End: LastSecondOfDate(r.End.Time(target.Location())),
4444
}
4545
return InRange(target, timeRange)

time_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func TestInRangeTime2(t *testing.T) {
5454
target := item.Time[1]
5555
end := item.Time[2]
5656
in := xtime.InRange(target, xtime.Range{
57-
Begin: begin,
57+
Start: begin,
5858
End: end,
5959
})
6060
assert.Equalf(t, in, item.In, "Time: []time.Time{t%d, t%d, t%d}, %v, }", begin.Second(), target.Second(), end.Second(), item.In)
@@ -225,7 +225,7 @@ func TestInRangeTime(t *testing.T) {
225225

226226
for k, v := range dataList {
227227
in := xtime.InRange(v.Target, xtime.Range{
228-
Begin: v.Begin,
228+
Start: v.Begin,
229229
End: v.End,
230230
})
231231
assert.Equal(t, v.In, in, k+1)

0 commit comments

Comments
 (0)