From c10dac100a76e90279f83d4aac330b92f15cd0e0 Mon Sep 17 00:00:00 2001 From: David Bach Date: Thu, 3 Feb 2022 10:35:39 +0100 Subject: [PATCH] Dates parsing: remove `throw InexactError` from `tryparsenext`, fixes #44003 (#44004) --- stdlib/Dates/src/io.jl | 2 +- stdlib/Dates/test/io.jl | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/stdlib/Dates/src/io.jl b/stdlib/Dates/src/io.jl index ba0958b57f613..7e007ced0bbee 100644 --- a/stdlib/Dates/src/io.jl +++ b/stdlib/Dates/src/io.jl @@ -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 diff --git a/stdlib/Dates/test/io.jl b/stdlib/Dates/test/io.jl index 822d0101c28ba..1c50676eb8346 100644 --- a/stdlib/Dates/test/io.jl +++ b/stdlib/Dates/test/io.jl @@ -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)]