mirror of
https://github.com/rclone/rclone.git
synced 2024-12-22 23:22:08 +01:00
filter: fix timezone of --min-age/-max-age from UTC to local as documented
Before this change if the timezone was omitted in a --min-age/--max-age time specifier then rclone defaulted to a UTC timezone. This is documented as using the local timezone if the time zone specifier is omitted which is a much more useful default and this patch corrects the implementation to agree with the documentation. See: https://forum.rclone.org/t/problem-utc-windows-europe-1-summer-problem/29917
This commit is contained in:
parent
76d5f02b2c
commit
5cdb6678ab
@ -80,7 +80,7 @@ var timeFormats = []string{
|
|||||||
func parseDurationDates(age string, epoch time.Time) (t time.Duration, err error) {
|
func parseDurationDates(age string, epoch time.Time) (t time.Duration, err error) {
|
||||||
var instant time.Time
|
var instant time.Time
|
||||||
for _, timeFormat := range timeFormats {
|
for _, timeFormat := range timeFormats {
|
||||||
instant, err = time.Parse(timeFormat, age)
|
instant, err = time.ParseInLocation(timeFormat, age, time.Local)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return epoch.Sub(instant), nil
|
return epoch.Sub(instant), nil
|
||||||
}
|
}
|
||||||
|
@ -42,10 +42,12 @@ func TestParseDuration(t *testing.T) {
|
|||||||
{"1x", 0, true},
|
{"1x", 0, true},
|
||||||
{"off", time.Duration(DurationOff), false},
|
{"off", time.Duration(DurationOff), false},
|
||||||
{"1h2m3s", time.Hour + 2*time.Minute + 3*time.Second, false},
|
{"1h2m3s", time.Hour + 2*time.Minute + 3*time.Second, false},
|
||||||
{"2001-02-03", now.Sub(time.Date(2001, 2, 3, 0, 0, 0, 0, time.UTC)), false},
|
{"2001-02-03", now.Sub(time.Date(2001, 2, 3, 0, 0, 0, 0, time.Local)), false},
|
||||||
{"2001-02-03 10:11:12", now.Sub(time.Date(2001, 2, 3, 10, 11, 12, 0, time.UTC)), false},
|
{"2001-02-03 10:11:12", now.Sub(time.Date(2001, 2, 3, 10, 11, 12, 0, time.Local)), false},
|
||||||
{"2001-02-03T10:11:12", now.Sub(time.Date(2001, 2, 3, 10, 11, 12, 0, time.UTC)), false},
|
{"2001-08-03 10:11:12", now.Sub(time.Date(2001, 8, 3, 10, 11, 12, 0, time.Local)), false},
|
||||||
|
{"2001-02-03T10:11:12", now.Sub(time.Date(2001, 2, 3, 10, 11, 12, 0, time.Local)), false},
|
||||||
{"2001-02-03T10:11:12.123Z", now.Sub(time.Date(2001, 2, 3, 10, 11, 12, 123, time.UTC)), false},
|
{"2001-02-03T10:11:12.123Z", now.Sub(time.Date(2001, 2, 3, 10, 11, 12, 123, time.UTC)), false},
|
||||||
|
{"2001-02-03T10:11:12.123+00:00", now.Sub(time.Date(2001, 2, 3, 10, 11, 12, 123, time.UTC)), false},
|
||||||
} {
|
} {
|
||||||
duration, err := parseDurationFromNow(test.in, getNow)
|
duration, err := parseDurationFromNow(test.in, getNow)
|
||||||
if test.err {
|
if test.err {
|
||||||
|
Loading…
Reference in New Issue
Block a user