From 819b54968664a3ee45359b97a6713a804587faf4 Mon Sep 17 00:00:00 2001 From: James Robb <47126579+jamesrweb@users.noreply.github.com> Date: Wed, 30 Nov 2022 13:56:25 +0100 Subject: [PATCH] support ISO months --- elm.json | 2 +- src/Iso8601.elm | 1 + tests/Example.elm | 11 ++++++++++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/elm.json b/elm.json index 672b5de..84431bd 100644 --- a/elm.json +++ b/elm.json @@ -15,6 +15,6 @@ "elm/time": "1.0.0 <= v < 2.0.0" }, "test-dependencies": { - "elm-explorations/test": "1.0.0 <= v < 2.0.0" + "elm-explorations/test": "2.0.0 <= v < 3.0.0" } } diff --git a/src/Iso8601.elm b/src/Iso8601.elm index 230559f..0b9d7f7 100644 --- a/src/Iso8601.elm +++ b/src/Iso8601.elm @@ -419,6 +419,7 @@ monthYearDayInMs = |. symbol "-" |= paddedInt 2 , paddedInt 2 + , succeed 1 ] -- DD |> Parser.andThen yearMonthDay diff --git a/tests/Example.elm b/tests/Example.elm index 83c6590..ba23641 100644 --- a/tests/Example.elm +++ b/tests/Example.elm @@ -3,9 +3,9 @@ module Example exposing (knownValues, reflexive) import Expect import Fuzz import Iso8601 +import Json.Decode exposing (decodeString, errorToString) import Test exposing (..) import Time -import Json.Decode exposing (decodeString, errorToString) knownValues : Test @@ -99,11 +99,20 @@ knownValues = \_ -> Iso8601.toTime "2019-05-30T06:30" |> Expect.equal (Ok (Time.millisToPosix 1559197800000)) + , test "toTime supports yyyy-mm format with time attached" <| + \_ -> + Iso8601.toTime "2022-01T00:00" + |> Expect.equal (Ok (Time.millisToPosix 1640995200000)) + , test "toTime supports yyyy-mm format without time attached" <| + \_ -> + Iso8601.toTime "2022-11" + |> Expect.equal (Ok (Time.millisToPosix 1667260800000)) , test "decoder returns clearer error for dead ends" <| \_ -> case decodeString Iso8601.decoder "2010-09-31T14:29:25.01235Z" of Err error -> Expect.notEqual (errorToString error) "TODO deadEndsToString" + Ok _ -> Expect.fail "Should fail on dead ends" ]