Skip to content

Commit

Permalink
Merge pull request #9 from Code-Hex/fix/parse
Browse files Browse the repository at this point in the history
fixed iso8601 time handling
  • Loading branch information
Code-Hex committed Sep 11, 2023
2 parents fd9f867 + 136f21b commit 92235ef
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
4 changes: 3 additions & 1 deletion iso8601/time.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,11 +267,13 @@ func parseFraction(b []byte) (int, int) {
}

func hmsfTime(h, m, s, f int) (Time, error) {
s += int(math.Trunc(float64(f)/1e9)) % 60
m += int(math.Trunc(float64(f) / 60e9))
t := Time{
Hour: h,
Minute: m,
Second: s,
Nanosecond: f,
Nanosecond: f % int(1e9),
}
if err := t.Validate(); err != nil {
return Time{}, err
Expand Down
24 changes: 12 additions & 12 deletions iso8601/time_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,35 +169,35 @@ func TestParseTime(t *testing.T) {
want: Time{
Hour: 14,
Minute: 30,
Second: 00,
Nanosecond: int(time.Minute) / 2,
Second: 30,
Nanosecond: 0,
},
},
{
name: "1430,5",
want: Time{
Hour: 14,
Minute: 30,
Second: 00,
Nanosecond: int(time.Minute) / 2,
Second: 30,
Nanosecond: 0,
},
},
{
name: "14.5",
want: Time{
Hour: 14,
Minute: 00,
Minute: 30,
Second: 00,
Nanosecond: int(time.Hour) / 2,
Nanosecond: 0,
},
},
{
name: "14,5",
want: Time{
Hour: 14,
Minute: 00,
Minute: 30,
Second: 00,
Nanosecond: int(time.Hour) / 2,
Nanosecond: 0,
},
},
{
Expand Down Expand Up @@ -337,17 +337,17 @@ func TestParseTime(t *testing.T) {
want: Time{
Hour: 14,
Minute: 30,
Second: 00,
Nanosecond: int(time.Minute) / 2,
Second: 30,
Nanosecond: 0,
},
},
{
name: "14:30,5",
want: Time{
Hour: 14,
Minute: 30,
Second: 00,
Nanosecond: int(time.Minute) / 2,
Second: 30,
Nanosecond: 0,
},
},
{
Expand Down

0 comments on commit 92235ef

Please sign in to comment.