diff --git a/pkg/server/warcserver/daterange.go b/pkg/server/warcserver/daterange.go index 6ff49da..42c4374 100644 --- a/pkg/server/warcserver/daterange.go +++ b/pkg/server/warcserver/daterange.go @@ -102,12 +102,10 @@ func To(t string) (int64, error) { switch tLen { case 4: - to = to.AddDate(0, 12, -1) // 31 days in decemeber - to = to.Add(time.Hour*23 + time.Minute*59 + time.Second*59) + to = to.AddDate(0, 12, -1).Add(time.Hour*23 + time.Minute*59 + time.Second*59) case 6: // add one month - one day, i.e: user supplies january, we add 29 - 1 - to = to.AddDate(0, 1, -1) - to = to.Add(time.Hour*23 + time.Minute*59 + time.Second*59) + to = to.AddDate(0, 1, -1).Add(time.Hour*23 + time.Minute*59 + time.Second*59) case 8: to = to.Add(time.Hour*23 + time.Minute*59 + time.Second*59) case 10: diff --git a/pkg/server/warcserver/daterange_test.go b/pkg/server/warcserver/daterange_test.go index 6d0a344..34d79d7 100644 --- a/pkg/server/warcserver/daterange_test.go +++ b/pkg/server/warcserver/daterange_test.go @@ -134,6 +134,20 @@ func TestFromAndToParsing(t *testing.T) { 23*60*60 + 60*59 + 59, false, }, + { + "normal year date string succeeds", + "197002", + time.Date(1970, 2, 1, 0, 0, 0, 0, time.UTC).Unix(), + time.Date(1970, 2, 28, 23, 59, 59, 0, time.UTC).Unix(), + false, + }, + { + "leap year date string succeeds", + "200002", + time.Date(2000, 2, 1, 0, 0, 0, 0, time.UTC).Unix(), + time.Date(2000, 2, 29, 23, 59, 59, 0, time.UTC).Unix(), + false, + }, { "empty date string succeeds", "",