Skip to content

fluidfractal/date

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

80 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

date

This Elm package provides a simple Date type for working with dates without times or zones.

Installation

elm install justinmimbs/date

Overview

Examples

These examples are only meant to give a feel for the library; see the docs for the full API.

Create a date and format it

import Date
import Time exposing (Month(..))

Date.fromCalendarDate 2018 Sep 26
    |> Date.format "EEEE, MMMM ddd, yyyy"
    == "Wednesday, September 26th, 2018"

Find the next Saturday after a date

import Date exposing (Interval(..), Unit(..))
import Time exposing (Month(..))

Date.fromCalendarDate 2018 Sep 26
    |> Date.floor Saturday
    |> Date.add Weeks 1
    |> Date.toIsoString
    == "2018-09-29"

List the third Thursday of the month for six months of a year

import Date exposing (Date, Interval(..), Unit(..))

start : Date
start =
    Date.fromOrdinalDate 2019 1

thirdThursday : Date -> Date
thirdThursday date =
    date |> Date.add Weeks 2 |> Date.ceiling Thursday

Date.range Month 1 start (start |> Date.add Months 6)
    |> List.map thirdThursday
    |> List.map Date.toIsoString
    == [ "2019-01-17"
       , "2019-02-21"
       , "2019-03-21"
       , "2019-04-18"
       , "2019-05-16"
       , "2019-06-20"
       ]

Packages

No packages published

Languages

  • Elm 100.0%