Skip to content

Commit

Permalink
added leap year test
Browse files Browse the repository at this point in the history
also use method chaining for date manipulation
  • Loading branch information
Avokadoen committed Jul 15, 2021
1 parent 4b5468f commit 3297cd9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
6 changes: 2 additions & 4 deletions pkg/server/warcserver/daterange.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
14 changes: 14 additions & 0 deletions pkg/server/warcserver/daterange_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
"",
Expand Down

0 comments on commit 3297cd9

Please sign in to comment.