mirror of
https://github.com/rclone/rclone.git
synced 2024-11-25 01:44:41 +01:00
rc: fix output of Time values in options/get
Before this change these were output as `{}` after this change they are output as time strings `"2022-03-26T17:48:19Z"` in standard javascript format.
This commit is contained in:
parent
0468375054
commit
31caa019fa
@ -81,6 +81,11 @@ func (t *Time) UnmarshalJSON(in []byte) error {
|
||||
return t.Set(s)
|
||||
}
|
||||
|
||||
// MarshalJSON marshals as a time.Time value
|
||||
func (t Time) MarshalJSON() ([]byte, error) {
|
||||
return json.Marshal(time.Time(t))
|
||||
}
|
||||
|
||||
// Scan implements the fmt.Scanner interface
|
||||
func (t *Time) Scan(s fmt.ScanState, ch rune) error {
|
||||
token, err := s.Token(true, func(rune) bool { return true })
|
||||
|
@ -153,3 +153,23 @@ func TestParseTimeUnmarshalJSON(t *testing.T) {
|
||||
assert.Equal(t, Time(test.want), parsedTime, test.in)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseTimeMarshalJSON(t *testing.T) {
|
||||
for _, test := range []struct {
|
||||
in time.Time
|
||||
want string
|
||||
err bool
|
||||
}{
|
||||
{time.Time{}, `"0001-01-01T00:00:00Z"`, false},
|
||||
{time.Date(2022, 03, 26, 17, 48, 19, 0, time.UTC), `"2022-03-26T17:48:19Z"`, false},
|
||||
} {
|
||||
gotBytes, err := json.Marshal(test.in)
|
||||
got := string(gotBytes)
|
||||
if test.err {
|
||||
require.Error(t, err, test.in)
|
||||
} else {
|
||||
require.NoError(t, err, test.in)
|
||||
}
|
||||
assert.Equal(t, test.want, got, test.in)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user