1
0
mirror of https://github.com/rclone/rclone.git synced 2026-01-06 02:23:24 +00:00

fs: fix parsing of times and durations of the form "YYYY-MM-DD HH:MM:SS"

Before this fix, the parsing code gave an error like this

    parsing "2022-08-02 07:00:00" as fs.Time failed: expected newline

This was due to the Scan call failing to read all the data.

This patch fixes that, and redoes the tests
This commit is contained in:
Nick Craig-Wood
2022-08-05 15:23:44 +01:00
parent ebe86c6cec
commit 16039b350d
4 changed files with 42 additions and 17 deletions

View File

@@ -126,7 +126,7 @@ func parseDurationFromNow(age string, getNow func() time.Time) (d time.Duration,
// ParseDuration parses a duration string. Accept ms|s|m|h|d|w|M|y suffixes. Defaults to second if not provided
func ParseDuration(age string) (time.Duration, error) {
return parseDurationFromNow(age, time.Now)
return parseDurationFromNow(age, timeNowFunc)
}
// ReadableString parses d into a human-readable duration.
@@ -216,7 +216,7 @@ func (d *Duration) UnmarshalJSON(in []byte) error {
// Scan implements the fmt.Scanner interface
func (d *Duration) Scan(s fmt.ScanState, ch rune) error {
token, err := s.Token(true, nil)
token, err := s.Token(true, func(rune) bool { return true })
if err != nil {
return err
}