Skip to content

Commit c10dac1

Browse files
author
David Bach
authored
Dates parsing: remove throw InexactError from tryparsenext, fixes #44003 (#44004)
1 parent 1edafa0 commit c10dac1

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

stdlib/Dates/src/io.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ struct Decimal3 end
150150
len = ii - i
151151
if len > 3
152152
ms, r = divrem(ms0, Int64(10) ^ (len - 3))
153-
r == 0 || throw(InexactError(:convert, Decimal3, ms0))
153+
r == 0 || return nothing
154154
else
155155
ms = ms0 * Int64(10) ^ (3 - len)
156156
end

stdlib/Dates/test/io.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,13 +465,17 @@ end
465465
# Issue #21504
466466
@test tryparse(Dates.Date, "0-1000") === nothing
467467

468+
# Issue #44003
469+
@test tryparse(Dates.Date, "2017", Dates.DateFormat(".s")) === nothing
470+
468471
@testset "parse milliseconds, Issue #22100" begin
469472
@test Dates.DateTime("2017-Mar-17 00:00:00.0000", "y-u-d H:M:S.s") == Dates.DateTime(2017, 3, 17)
470473
@test Dates.parse_components(".1", Dates.DateFormat(".s")) == [Dates.Millisecond(100)]
471474
@test Dates.parse_components(".12", Dates.DateFormat(".s")) == [Dates.Millisecond(120)]
472475
@test Dates.parse_components(".123", Dates.DateFormat(".s")) == [Dates.Millisecond(123)]
473476
@test Dates.parse_components(".1230", Dates.DateFormat(".s")) == [Dates.Millisecond(123)]
474-
@test_throws InexactError Dates.parse_components(".1234", Dates.DateFormat(".s"))
477+
# Issue #44003
478+
@test_throws ArgumentError Dates.parse_components(".1234", Dates.DateFormat(".s"))
475479

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

0 commit comments

Comments
 (0)