justinmimbs/elm-date-extra/1.0.1

NOTE: this package is not compatible with Elm 0.19.1

Date.Math

Functions for working with dates as numeric quantities.

Dates as Atomic Values

equal : Date -> Date -> Bool

Test equality of two dates.

compare : Date -> Date -> Order

Compare two dates. This can be used as the compare function for List.sortWith.

sortedDates = List.sortWith Date.compare unsortedDates
isBetween : Date -> Date -> Date -> Bool

Test if a date is within a given range, inclusive of the range values. The expression Date.isBetween a b x tests if x is between a and b.

clamp : Date -> Date -> Date -> Date

Clamp a date within a given range.

Dates as Composite Values

= Millisecond
| Second
| Minute
| Hour
| Day
| Month
| Year
| Quarter
| Week
| Monday
| Tuesday
| Wednesday
| Thursday
| Friday
| Saturday
| Sunday

Represents an interval of time.

equalBy : Interval -> Date -> Date -> Bool

Test if two dates fall within the same interval.

dec31 = Date.fromCalendarDate 1999 Dec 31
jan1 = Date.fromCalendarDate 2000 Jan 1


Date.equalBy Month dec31 jan1 -- False
Date.equalBy Week  dec31 jan1 -- True
floor : Interval -> Date -> Date

Round down a date to the beginning of the closest interval. The resulting date will be less than or equal to the one provided.

Date.floor Hour (Date.fromParts 1999 Dec 31 23 59 59 999)
-- <31 December 1999, 23:00>
ceiling : Interval -> Date -> Date

Round up a date to the beginning of the closest interval. The resulting date will be greater than or equal to the one provided.

Date.ceiling Monday (Date.fromParts 1999 Dec 31 23 59 59 999)
-- <3 January 2000>
add : Interval -> Int -> Date -> Date

Add a number of whole intervals to a date.

Date.add Week 2 (Date.fromParts 2007 Mar 15 11 55 0 0)
-- <29 March 2007, 11:55>

When adding Month, Quarter, or Year intervals, day values are clamped at the end of the month if necessary.

Date.add Month 1 (Date.fromParts 2000 Jan 31 0 0 0 0)
-- <29 February 2000>
diff : Interval -> Date -> Date -> Int

Find the difference, as a number of whole intervals, between two dates.

Date.diff Month
  (Date.fromParts 2007 Mar 15 11 55 0 0)
  (Date.fromParts 2007 Sep 1 0 0 0 0)
-- 5
range : Interval -> Int -> Date -> Date -> List Date

Create a list of dates, at rounded intervals, increasing by a step value, between two dates. The list will start at or after the first date, and end before the second date.

Date.range Day 2
  (Date.fromParts 2007 Mar 15 11 55 0 0)
  (Date.fromParts 2007 Mar 22 0 0 0 0)
-- [<16 March 2007>, <18 March 2007>, <20 March 2007>]