From 5cdb6678ab1c9c07fdb535dc21696f578edeb003 Mon Sep 17 00:00:00 2001
From: Nick Craig-Wood <nick@craig-wood.com>
Date: Mon, 28 Mar 2022 11:47:27 +0100
Subject: [PATCH] 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
---
 fs/parseduration.go      | 2 +-
 fs/parseduration_test.go | 8 +++++---
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/fs/parseduration.go b/fs/parseduration.go
index 522dbae7a..3184f6e1b 100644
--- a/fs/parseduration.go
+++ b/fs/parseduration.go
@@ -80,7 +80,7 @@ var timeFormats = []string{
 func parseDurationDates(age string, epoch time.Time) (t time.Duration, err error) {
 	var instant time.Time
 	for _, timeFormat := range timeFormats {
-		instant, err = time.Parse(timeFormat, age)
+		instant, err = time.ParseInLocation(timeFormat, age, time.Local)
 		if err == nil {
 			return epoch.Sub(instant), nil
 		}
diff --git a/fs/parseduration_test.go b/fs/parseduration_test.go
index f4be5a9bc..f0efba4bd 100644
--- a/fs/parseduration_test.go
+++ b/fs/parseduration_test.go
@@ -42,10 +42,12 @@ func TestParseDuration(t *testing.T) {
 		{"1x", 0, true},
 		{"off", time.Duration(DurationOff), 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 10:11:12", now.Sub(time.Date(2001, 2, 3, 10, 11, 12, 0, time.UTC)), false},
-		{"2001-02-03T10:11:12", now.Sub(time.Date(2001, 2, 3, 10, 11, 12, 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.Local)), 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.123+00:00", now.Sub(time.Date(2001, 2, 3, 10, 11, 12, 123, time.UTC)), false},
 	} {
 		duration, err := parseDurationFromNow(test.in, getNow)
 		if test.err {