elm-community/elm-time/3.0.2

NOTE: this package is not compatible with Elm 0.19.1

Time.Iso8601ErrorMsg

A renderer to format error messages resulting from ISO8601 parsing errors.

At this time, there is a renderer, renderText, to render a fixed-font message to, say, a terminal screen. This renderer strives to output the friendly useful error message that elm is famous for.

Main entry

renderText : Error -> String

Invoking the renderer. This returns an 'elm compiler-style formatted' error string

import Parser


-- The \n in the middle of the string is to provide for the 72-char right margin
failString : String
failString =
    "Expecting the value 29 to be in the range 1 to 28 for the specified\nyear, 1991, and month, 2."


renderedString : String
renderedString =
    "The 'day-of-month' segment is invalid:\n\n" ++
    "    1991-02-29T12:25:12.0Z\n" ++
    "            ^\n\n" ++
    failString


parserError : Parser.Error
parserError =
    { row = 1
    , col = 11
    , source = "1991-02-29T12:25:12.0Z"
    , problem = Parser.Fail failString
    , context = [{ row = 1, col = 11, description = "leap-year" }]
    }


renderText parserError
--> renderedString

Utilities

reflow : String -> String

A convenience function to auto-wrap long strings

Use this method to appropriately wrap the error string returned from renderText above.

-- \n inserted at 72nt position coz is right margin.
reflow "Expecting the value 29 to be in the range 1 to 28 for the specified year, 1991, and month, 2."
--> "Expecting the value 29 to be in the range 1 to 28 for the specified" ++ "\n" ++ "year, 1991, and month, 2."