Merge branch 'main' into sogari-association-preloading
This commit is contained in:
commit
c49c709096
|
@ -68,17 +68,13 @@ func String2Time(s string, originalLocation *time.Location, convertedLocation *t
|
||||||
dt = dt.In(convertedLocation)
|
dt = dt.In(convertedLocation)
|
||||||
return &dt, nil
|
return &dt, nil
|
||||||
} else if len(s) == 8 && s[2] == ':' && s[5] == ':' {
|
} else if len(s) == 8 && s[2] == ':' && s[5] == ':' {
|
||||||
currentDate := time.Now()
|
|
||||||
dt, err := time.ParseInLocation("15:04:05", s, originalLocation)
|
dt, err := time.ParseInLocation("15:04:05", s, originalLocation)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
// add current date for correct time locations
|
|
||||||
dt = dt.AddDate(currentDate.Year(), int(currentDate.Month()), currentDate.Day())
|
|
||||||
dt = dt.In(convertedLocation)
|
dt = dt.In(convertedLocation)
|
||||||
// back to zero year
|
res := time.Date(0, time.January, 1, dt.Hour(), dt.Minute(), dt.Second(), 0, convertedLocation)
|
||||||
dt = dt.AddDate(-currentDate.Year(), int(-currentDate.Month()), -currentDate.Day())
|
return &res, nil
|
||||||
return &dt, nil
|
|
||||||
} else {
|
} else {
|
||||||
i, err := strconv.ParseInt(s, 10, 64)
|
i, err := strconv.ParseInt(s, 10, 64)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
|
|
@ -12,8 +12,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestString2Time(t *testing.T) {
|
func TestString2Time(t *testing.T) {
|
||||||
expectedLoc, err := time.LoadLocation("Asia/Shanghai")
|
expectedLoc := time.FixedZone("CST", 8*3600)
|
||||||
assert.NoError(t, err)
|
|
||||||
|
|
||||||
cases := map[string]time.Time{
|
cases := map[string]time.Time{
|
||||||
"2021-08-10": time.Date(2021, 8, 10, 8, 0, 0, 0, expectedLoc),
|
"2021-08-10": time.Date(2021, 8, 10, 8, 0, 0, 0, expectedLoc),
|
||||||
|
|
Loading…
Reference in New Issue