Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(date test): Fail with invalid date
Browse files Browse the repository at this point in the history
Constructs a datestring with RFC3339 formatting using the parsed date
values, then attempts to call `time.Parse()` on it, which returns a
non-nil error if datetime string was invalid or `time`'s parsing of
the string failed.

Resolves: part of pelletier#613
jidicula committed Oct 8, 2021
1 parent 62acca2 commit e86a442
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions decode.go
Original file line number Diff line number Diff line change
@@ -99,6 +99,13 @@ func parseDateTime(b []byte) (time.Time, error) {
return time.Time{}, newDecodeError(b, "extra bytes at the end of the timezone")
}

dateString := fmt.Sprintf("%04d-%02d-%02dT%02d:%02d:%02dZ",
dt.Year, dt.Month, dt.Day, dt.Hour, dt.Minute, dt.Second)
_, err = time.Parse(time.RFC3339, dateString)
if err != nil {
return time.Time{}, newDecodeError(b, "invalid date-time")
}

t := time.Date(
dt.Year,
time.Month(dt.Month),

0 comments on commit e86a442

Please sign in to comment.