Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Permit only year component in date #23

Merged
merged 1 commit into from
Jan 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions iso8601.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,10 @@ parse:
// Sometimes a date can end without a non-integer character
if c > 0 {
switch p {
case year:
Y = c
M = 1
d = 1
case day:
d = c
case hour:
Expand Down
8 changes: 7 additions & 1 deletion iso8601_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (tc TestCase) CheckError(err error, t *testing.T) bool {
if err == nil && (tc.ShouldFailParse || tc.ShouldInvalidRange) {
reason := "fail to parse"
if tc.ShouldInvalidRange {
reason = "catch an invalid date range"
reason = "to catch an invalid date range"
}
t.Fatalf("Expected test case %s", reason)
return true
Expand Down Expand Up @@ -245,6 +245,12 @@ var cases = []TestCase{
MilliSecond: 502,
Zone: 0,
},
{
Using: "2017",
Year: 2017, Month: 1, Day: 1, Hour: 0, Minute: 0, Second: 0,
MilliSecond: 0,
Zone: 0,
},

// Invalid Parse Test Cases
{
Expand Down
Loading