Abstract
A simple date library. Inspired by code from LexiFi.
This library does not handle any ancient calendars or anything like that. It's designed for simplicity (and thereby speed).
The implementation is by a module which is immediately opened. The intent is to make the type of dates abstract.
Synopsis
local module type date = {
| |||||||||||||||||||||||||||||||||||
open (... : date) |
Description
- ↑local module type date
- ↑type date
A date.
- ↑val add_days: date -> i32 -> date
Add days to date.
- ↑val sub_days: date -> i32 -> date
Subtract days from date.
- ↑val add_months: date -> i32 -> date
Add months to date. If necessary, will truncate the day-number to the end of the new month.
- ↑val diff_dates: date -> date -> f64
The time from the first date to the second, in fractions of a 365-day year.
- ↑val triple_of_date: date -> (i32, i32, i32)
Convert a date to a triple of (year,month,day). Months and days are 1-indexed (technically, so are years, but nobody is surprised by that). The time is assumed to be 12:00 that day.
- ↑val date_of_triple: (i32, i32, i32) -> date
The inverse of
triple_of_date
. The result is undefined if the triple does not describe a valid date.- ↑val check_date: (i32, i32, i32) -> bool
True if the given triple encodes a valid (year,month,day)-date.
- ↑val same_date: date -> date -> bool
Are two dates the same?
- ↑val earliest: date -> date -> date
The earliest of the two given dates.
- ↑val latest: date -> date -> date
The latest of the two given dates.