Coder Social home page Coder Social logo

ssbb / elm-date-format Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ryan-haskell/elm-date-format

0.0 3.0 0.0 20 KB

A reliable way to format dates with Elm.

Home Page: http://package.elm-lang.org/packages/ryannhg/elm-date-format/latest

Elm 100.00%

elm-date-format's Introduction

elm-date-format

A reliable way to format dates with Elm.

Build Status

Using the elm package

elm package install ryannhg/elm-date-format

What is elm-date-format?

If you're coming from Javascript, you might have heard of MomentJS.

MomentJS is a great library for formatting dates!

elm-date-format has the same formatting options 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

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 date

        Err ->
            "This shouldn't happen..."

Would make yourPrettyDate return:

"February 5th, 2018" : String

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.