Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ryan-haskell/elm-moment
A reliable way to format dates with elm.
https://github.com/ryan-haskell/elm-moment
date elm formatting moment
Last synced: 24 days ago
JSON representation
A reliable way to format dates with elm.
- Host: GitHub
- URL: https://github.com/ryan-haskell/elm-moment
- Owner: ryan-haskell
- Created: 2018-02-19T05:30:56.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2018-02-21T16:20:57.000Z (almost 7 years ago)
- Last Synced: 2024-11-27T09:29:32.343Z (27 days ago)
- Topics: date, elm, formatting, moment
- Language: Elm
- Homepage: http://package.elm-lang.org/packages/ryannhg/elm-moment/latest
- Size: 9.77 KB
- Stars: 3
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# elm-moment
> A reliable way to format dates with elm.# This project has moved!
And now it's [over here](https://github.com/RyanNHG/elm-date-format).
Following Elm's literal name policy, `elm-date-format` is probably more useful for discoverability.
---
### Using the [elm package](http://package.elm-lang.org/packages/ryannhg/elm-moment/latest)
```
elm package install ryannhg/elm-moment
```### What is `elm-moment`?
If you're coming from Javascript, you might have heard of [MomentJS](https://momentjs.com).
MomentJS is a great library for formatting dates!
`elm-moment` has the same [formatting options](https://momentjs.com/docs/#/displaying/format/) as Moment, but uses Elm's awesome type system to provide human readable names, and catch typos for you at compile time!
No need to remember the difference between `mm` and `MM` and `M`!
### A quick example
```elm
import Date
import Moment-- Create a custom formatter
yourFormatter : Date -> String
yourFormatter =
Moment.format
[ Moment.MonthNameFull
, Moment.Text " "
, Moment.DayOfMonthSuffix
, Moment.Text ", "
, Moment.YearNumber
]-- Using your formatter, format your date as a string!
yourPrettyDate : String
yourPrettyDate =
case Date.fromString "2018-02-05T00:00:00.000Z" of
Ok date ->
yourFormatter dateErr ->
"This shouldn't happen..."```
Would make `yourPrettyDate` return:
```
"February 5th, 2018" : String
```