Skip to content

Commit

Permalink
Support simple date formats
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewpage authored and TylerBrock committed Jan 8, 2019
1 parent 4d1fcdc commit ea278e0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
3 changes: 3 additions & 0 deletions config/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ type Configuration struct {
// Define the order of time formats to attempt to use to parse our input absolute time
var absoluteTimeFormats = []string{
time.RFC3339,

"2006-01-02", // Simple date
"2006-01-02 15:04:05", // Simple date & time
}

// Parse the input string into a time.Time object.
Expand Down
16 changes: 16 additions & 0 deletions config/configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,19 @@ func TestGetTimeAbsoluteRFC3339(t *testing.T) {
t.Errorf("Expected to parse absolute time. Error: %s", err)
}
}

func TestGetTimeAbsoluteSimpleDate(t *testing.T) {
absoluteTime1, err := getTime("2018-06-26", testTimeNow)

if err != nil && absoluteTime1.Year() == 2018 && absoluteTime1.Month() == 6 && absoluteTime1.Day() == 26 && absoluteTime1.Hour() == 0 && absoluteTime1.Minute() == 0 && absoluteTime1.Second() == 0 {
t.Errorf("Expected to parse absolute time from simple string. Error: %s", err)
}
}

func TestGetTimeAbsoluteSimpleDateAndTime(t *testing.T) {
absoluteTime1, err := getTime("2018-06-26 12:43:30", testTimeNow)

if err != nil && absoluteTime1.Year() == 2018 && absoluteTime1.Month() == 6 && absoluteTime1.Day() == 26 && absoluteTime1.Hour() == 12 && absoluteTime1.Minute() == 43 && absoluteTime1.Second() == 30 {
t.Errorf("Expected to parse absolute time from simple string. Error: %s", err)
}
}

0 comments on commit ea278e0

Please sign in to comment.