f0i / iso8601

Elm package to format elm/time posix time as an ISO8601 strings for humans

Home Page:https://package.elm-lang.org/packages/f0i/iso8601/latest/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Iso8601

Format a posix time to a ISO8601 String.

This package is intended to format time stamps for user interfaces with custom precision.

Install

elm install f0i/iso8601

Examples

See guide.elm-lang.org/…/time.html for how to get the current time.

import Iso8601
import Time exposing (Posix)

...

-- get a Posix time from elm/time
time =
    Time.millisToPosix 1584875883199


-- this will format the time as "2020-03-22T11:18:03.199"
milli =
    Iso8601.toUtcMilliString time

-- this will format the time as "2020-03-22T11:18"
minute =
    Iso8601.toUtcString Iso8601.Minute time

-- this will format the time as "11:18:03"
hourToSecond =
    Iso8601.toUtcString Iso8601.HourSecond time

-- or get each part of the String as Tuple to create a custom format
custom =
    let
        ( ( year, month, day ), ( hour, minute, second ), ms ) =
            Iso8601.toTuple time
    in
    year ++ "/" ++ month ++ "/" ++ day ++ " " ++ hour ++ "_" ++ minute ++ "!"

A complete list of the helper functions can be found in the Iso8601 module docs.

About

Elm package to format elm/time posix time as an ISO8601 strings for humans

https://package.elm-lang.org/packages/f0i/iso8601/latest/

License:BSD 3-Clause "New" or "Revised" License


Languages

Language:Elm 100.0%