Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ryan-haskell/elm-date-format
A reliable way to format dates with Elm.
https://github.com/ryan-haskell/elm-date-format
date elm formatter momentjs
Last synced: 23 days ago
JSON representation
A reliable way to format dates with Elm.
- Host: GitHub
- URL: https://github.com/ryan-haskell/elm-date-format
- Owner: ryan-haskell
- Created: 2018-02-21T16:12:44.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2018-10-02T22:17:33.000Z (about 6 years ago)
- Last Synced: 2024-11-27T09:29:31.425Z (26 days ago)
- Topics: date, elm, formatter, momentjs
- Language: Elm
- Homepage: http://package.elm-lang.org/packages/ryannhg/elm-date-format/latest
- Size: 30.3 KB
- Stars: 8
- Watchers: 2
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# elm-date-format
> A reliable way to format dates with Elm.[![Build Status](https://travis-ci.org/ryannhg/elm-date-format.svg?branch=master)](https://travis-ci.org/ryannhg/elm-date-format)
### DEPRECATED: There's a new version!
If you are able to use Elm 0.19, you should check out [ryannhg/date-format](https://www.github.com/ryannhg/date-format).
That version will have the latest updates and features (like supporting multiple languages!)
### Using the [elm package](http://package.elm-lang.org/packages/ryannhg/elm-date-format/latest)
```
elm package install ryannhg/elm-date-format
```### What is `elm-date-format`?
If you're coming from Javascript, you might have heard of [MomentJS](https://momentjs.com).
MomentJS is a great library for formatting dates!
`elm-date-format` 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 exposing (Date)
import DateFormat-- Create a custom formatter
yourFormatter : Date -> String
yourFormatter =
DateFormat.format
[ DateFormat.monthNameFull
, DateFormat.text " "
, DateFormat.dayOfMonthSuffix
, DateFormat.text ", "
, DateFormat.yearNumber
]-- Using your formatter, format your date as a string!
yourPrettyDate : String
yourPrettyDate =
case Date.fromString "2018-02-05T00:00:00.000" of
Ok date ->
yourFormatter dateErr ->
"This shouldn't happen..."```
Would make `yourPrettyDate` return:
```
"February 5th, 2018" : String
```