This Elm package provides a simple Date
type for working with dates without times or zones.
elm install justinmimbs/date
- Get the current local date:
today
- Get dates from
Posix
times:fromPosix
- Convert
Date
values both to and from:- Calendar dates (
2018 Sep 26
) - ISO week dates (
2018 39 Wed
) - Ordinal dates (
2018 269
) - ISO 8601 strings (
"2018-09-26"
) - Rata Die (
736963
)
- Calendar dates (
- Format dates for display:
format
,formatWithLanguage
- Manipulate dates:
add
,floor
,ceiling
- Diff dates:
diff
- Create lists of dates:
range
- Helpers:
compare
,isBetween
,min
,max
,clamp
These examples are only meant to give a feel for the library; see the docs for the full API.
import Date
import Time exposing (Month(..))
Date.fromCalendarDate 2018 Sep 26
|> Date.format "EEEE, MMMM ddd, yyyy"
== "Wednesday, September 26th, 2018"
import Date exposing (Interval(..), Unit(..))
import Time exposing (Month(..))
Date.fromCalendarDate 2018 Sep 26
|> Date.floor Saturday
|> Date.add Weeks 1
|> Date.toIsoString
== "2018-09-29"
import Date exposing (Date, Interval(..), Unit(..))
start : Date
start =
Date.fromOrdinalDate 2019 1
thirdThursday : Date -> Date
thirdThursday date =
date |> Date.add Weeks 2 |> Date.ceiling Thursday
Date.range Month 1 start (start |> Date.add Months 6)
|> List.map thirdThursday
|> List.map Date.toIsoString
== [ "2019-01-17"
, "2019-02-21"
, "2019-03-21"
, "2019-04-18"
, "2019-05-16"
, "2019-06-20"
]