Giter Site home page Giter Site logo

elm-date-format's Introduction

Format String for Elm

by Max Goldstein

Create format strings for dates in the Elm programming language.

Documentation

The module Date.Format exports format : String -> Date.Date -> String. The Date refers to Elm's standard Date library. The input String may contain any of the following directives, which will be expanded to parts of the date.

A directive consists of a percent (%) character, zero or more flags and a conversion specifier as follows.

%<flags><conversion>

Flags:

  • - - don't pad a numerical output
  • _ - use spaces for padding
  • 0 - use zeros for padding

Format directives:

  • %Y - 4 digit year
  • %y - 2 digit year
  • %m - Zero-padded month of year, e.g. "07" for July
  • %B - Full month name, e.g. "July"
  • %b - Abbreviated month name, e.g. "Jul"
  • %d - Zero-padded day of month, e.g "02"
  • %e - Space-padded day of month, e.g " 2"
  • %a - Day of week, abbreviated to three letters, e.g. "Wed"
  • %A - Day of week in full, e.g. "Wednesday"
  • %H - Hour of the day, 24-hour clock, zero-padded
  • %k - Hour of the day, 24-hour clock, space-padded
  • %I - Hour of the day, 12-hour clock, zero-padded
  • %l - (lower ell) Hour of the day, 12-hour clock, space-padded
  • %p - AM or PM
  • %P - am or pm
  • %M - Minute of the hour, zero-padded
  • %S - Second of the minute, zero-padded
  • %% - literal %

Localization

Date.Format also exports localFormat : Date.Local.Local -> String -> Date.Date -> String. This function allows to add a localization record as specified in Date.Local. It can be used to display local terms for week days, months, and AM or PM.

Contributing

Pull requests are welcome! Note that in addition to adding a new letter to the massive case statement, you'll also need to add it to the regex. Languages like Haskell, Python, and Ruby have very comprehensive format strings. (Luckily, they seem to agree on the encoding, which you should follow.) I've tried to add the most common formats, but if you want one added, send a PR (and add a passing test). To run the tests, run elm test (which you can install from the elm-test package).

elm-date-format's People

Contributors

mgold avatar huluk avatar julianjelfs avatar joshy avatar ghivert avatar lorenzo avatar pisys avatar ryanolsonx avatar seanhess avatar srolel avatar

Watchers

James Cloos avatar Andy avatar  avatar

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.