ryannhg/date-format/2.1.0

NOTE: the latest version is 2.3.0

Renamed to ryan-haskell/date-format. It is published under that name, and new versions come out there.

Versions published as ryannhg/date-format still install under that name. 6 versions of 6 come from the new location (see their notes).

Rerouted (renamed, verified). The GitHub user or repository was renamed. The tag is still there, at the new name. The Lamdera package server serves a copy recovered from https://github.com/ryan-haskell/date-format.

What we checked: The repo moved to github.com/ryan-haskell/date-format. Rebuilt with git archive from commit 9026848eeac1 of https://github.com/ryan-haskell/date-format (zip prefix ryannhg-date-format-b7b4944/, America/Los_Angeles times): the zip is byte-identical to the one package.elm-lang.org recorded, SHA-1 97d2811673bc335469a9943b9cad330bdb97708c.

The Lamdera compiler uses this copy and prints a one-line notice saying so. elm itself fails to download this version.

Details · package.elm-lang.org's zip: https://github.com/ryannhg/date-format/zipball/2.1.0/

DateFormat

A reliable way to format dates and times with Elm.

Formatting dates

format : List Token -> Zone -> Posix -> String

This function takes in a list of tokens, Zone, and Posix to create your formatted string!

Let's say ourPosixValue is November 15, 1993 at 15:06.

-- "15:06"
format
    [ hourMilitaryFixed
    , text ":"
    , minuteFixed
    ]
    utc
    ourPosixValue




-- "3:06 pm"
format
    [ hourNumber
    , text ":"
    , minuteFixed
    , text " "
    , amPmLowercase
    ]
    utc
    ourPosixValue




-- "Nov 15th, 1993"
format
    [ monthNameFirstThree
    , text " "
    , dayOfMonthSuffix
    , text ", "
    , yearNumber
    ]
    utc
    ourPosixValue

Supporting a different language?

formatWithLanguage : Language -> List Token -> Zone -> Posix -> String

If our users don't speak English, printing out "Monday" or "Tuesday" might not be a great fit.

Thanks to a great recommendation, date-format now supports multilingual output!

All you need to do is provide your own options, and format will use your preferences instead:

For a complete example, check out the FormatWithOptions.elm in the examples folder.

Available formatting options

type Token

These are the available tokens to help you format dates.

Month

Get the numeric value of the month.

Examples: 1, 2, 3, ... 11, 12

Get the numeric value of the month, with a suffix at the end.

Examples: 1st, 2nd, 3rd, ... 11th, 12th

Get the numeric value of the month, fixed to two places.

Examples: 01, 02, 03, ... 11, 12

Get the name of the month, but abbreviated (abbreviation function comes from the language settings)

Examples: Jan, Feb, Mar, ... Nov, Dec

Get the full name of the month.

Examples: January, February, ... December

Day of the Month

Get the numeric value of the day of the month.

Examples: 1, 2, 3, ... 30, 31

Get the numeric value of the day of the month, with a suffix at the end.

Examples: 1st, 2nd, 3rd, ... 30th, 31st

Get the numeric value of the day of the month, fixed to two places.

Examples: 01, 02, 03, ... 30, 31

Day of the Year

Get the numeric value of the day of the year.

Examples: 1, 2, 3, ... 364, 365

Get the numeric value of the day of the year, with a suffix at the end.

Examples: 1st, 2nd, 3rd, ... 364th, 365th

Get the numeric value of the day of the year, fixed to three places.

Examples: 001, 002, 003, ... 364, 365

Day of the Week

Get the numeric value of the day of the week.

Examples: 0, 1, 2, ... 5, 6

Get the numeric value of the day of the week, with a suffix at the end.

Examples: 0th, 1st, 2nd, ... 5th, 6th

Gets the name of the day of the week, but just the first two letters.

Examples: Su, Mo, Tu, ... Fr, Sa

Gets the full name of the day of the week.

Examples: Sunday, Monday, ... Friday, Saturday

Year

Get the year, but just the last two letters.

Examples: 70, 71, ... 29, 30

Get the year.

Examples: 1970, 1971, ... 2018, ... 9999, ...

Quarter of the Year

Get the numeric value for the quarter of the year.

Examples: 1, 2, 3, 4

Get the numeric value for the quarter of the year, with a suffix.

Examples: 1st, 2nd, 3rd, 4th

Week of the Year

Get the numeric value for the week of the year.

Examples: 1, 2, 3, ... 51, 52

Get the numeric value for the week of the year, with a suffix at the end.

Examples: 1st, 2nd, 3rd, ... 51st, 52nd

Get the numeric value for the week of the year, fixed to two places.

Examples: 01, 02, 03, ... 51, 52

AM / PM

Get the AM / PM value of the hour, in uppercase.

Examples: AM, PM

Get the AM / PM value of the hour, in uppercase.

Examples: am, pm

Hour

Get the hour of the 24-hour day.

Examples: 0, 1, 2, ... 22, 23

Get the hour of the 24-hour day, fixed to two places.

Examples: 00, 01, 02, ... 22, 23

Get the hour of the 12-hour day.

Examples: 0, 1, 2, ... 11, 12

Get the hour of the 12-hour day, fixed to two places.

Examples: 00, 01, 02, ... 11, 12

Get the hour of the 24-hour day, starting from one.

Examples: 1, 2, ... 23, 24

Get the hour of the 24-hour day, starting from one, fixed to two places.

Examples: 01, 02, ... 23, 24

Minute

Get the minute of the hour.

Examples: 0, 1, 2, ... 58, 59

Get the minute of the hour, fixed to two places.

Examples: 00, 01, 02, ... 58, 59

Second

Get the second of the minute.

Examples: 0, 1, 2, ... 58, 59

Get the second of the minute, fixed to two places.

Examples: 00, 01, 02, ... 58, 59

Millisecond

Get the milliseconds of the second.

Examples: 0, 1, 2, ... 998, 999

Get the milliseconds of the second, fixed to three places.

Examples: 000, 001, 002, ... 998, 999

Other Stuff

text : String -> Token

Represent a string value

formatter : Zone -> Posix -> String
formatter =
    DateFormat.format
        [ DateFormat.hourMilitaryFixed
        , DateFormat.text ":"
        , DateFormat.minuteFixed
        ]

When given a Zone and Posix, this will return something like "23:15" or "04:43"