Skip to content

Commit

Permalink
Dates parsing: remove throw InexactError from tryparsenext, fixes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
David Bach authored Feb 3, 2022
1 parent 1edafa0 commit c10dac1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion stdlib/Dates/src/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ struct Decimal3 end
len = ii - i
if len > 3
ms, r = divrem(ms0, Int64(10) ^ (len - 3))
r == 0 || throw(InexactError(:convert, Decimal3, ms0))
r == 0 || return nothing
else
ms = ms0 * Int64(10) ^ (3 - len)
end
Expand Down
6 changes: 5 additions & 1 deletion stdlib/Dates/test/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -465,13 +465,17 @@ end
# Issue #21504
@test tryparse(Dates.Date, "0-1000") === nothing

# Issue #44003
@test tryparse(Dates.Date, "2017", Dates.DateFormat(".s")) === nothing

@testset "parse milliseconds, Issue #22100" begin
@test Dates.DateTime("2017-Mar-17 00:00:00.0000", "y-u-d H:M:S.s") == Dates.DateTime(2017, 3, 17)
@test Dates.parse_components(".1", Dates.DateFormat(".s")) == [Dates.Millisecond(100)]
@test Dates.parse_components(".12", Dates.DateFormat(".s")) == [Dates.Millisecond(120)]
@test Dates.parse_components(".123", Dates.DateFormat(".s")) == [Dates.Millisecond(123)]
@test Dates.parse_components(".1230", Dates.DateFormat(".s")) == [Dates.Millisecond(123)]
@test_throws InexactError Dates.parse_components(".1234", Dates.DateFormat(".s"))
# Issue #44003
@test_throws ArgumentError Dates.parse_components(".1234", Dates.DateFormat(".s"))

# Ensure that no overflow occurs when using Int32 literals: Int32(10)^10
@test Dates.parse_components("." * rpad(999, 10, '0'), Dates.DateFormat(".s")) == [Dates.Millisecond(999)]
Expand Down

0 comments on commit c10dac1

Please sign in to comment.