fix issue in cycle import for gtime

This commit is contained in:
John
2019-09-30 15:51:15 +08:00
parent 39d654e3f2
commit 35ad4d869f
4 changed files with 20 additions and 3 deletions

View File

@ -8,7 +8,6 @@ package gtime
import (
"bytes"
"github.com/gogf/gf/util/gconv"
"time"
)
@ -196,12 +195,12 @@ func (t *Time) Truncate(d time.Duration) *Time {
// MarshalJSON implements the interface MarshalJSON for json.Marshal.
func (t *Time) MarshalJSON() ([]byte, error) {
return gconv.UnsafeStrToBytes(`"` + t.String() + `"`), nil
return []byte(`"` + t.String() + `"`), nil
}
// UnmarshalJSON implements the interface UnmarshalJSON for json.Unmarshal.
func (t *Time) UnmarshalJSON(b []byte) error {
newTime, err := StrToTime(gconv.UnsafeBytesToStr(bytes.Trim(b, `"`)))
newTime, err := StrToTime(string(bytes.Trim(b, `"`)))
if err != nil {
return err
}

View File

@ -1,3 +1,9 @@
// Copyright 2019 gf Author(https://github.com/gogf/gf). All Rights Reserved.
//
// This Source Code Form is subject to the terms of the MIT License.
// If a copy of the MIT was not distributed with this file,
// You can obtain one at https://github.com/gogf/gf.
package gtime_test
import (

View File

@ -1,3 +1,9 @@
// Copyright 2019 gf Author(https://github.com/gogf/gf). All Rights Reserved.
//
// This Source Code Form is subject to the terms of the MIT License.
// If a copy of the MIT was not distributed with this file,
// You can obtain one at https://github.com/gogf/gf.
package gtime_test
import (

View File

@ -1,3 +1,9 @@
// Copyright 2019 gf Author(https://github.com/gogf/gf). All Rights Reserved.
//
// This Source Code Form is subject to the terms of the MIT License.
// If a copy of the MIT was not distributed with this file,
// You can obtain one at https://github.com/gogf/gf.
package gtime_test
import (