Skip to content

aivi.date ​

Calendar dates, times, and day-of-week types.

aivi.date provides structured date and time types with named positional fields, day-of-week enumeration, Eq / Ord support for Date, ISO 8601 formatting, and a DateDelta domain for day-level arithmetic.

Import ​

aivi
use aivi.date (
    Year
    Month
    Day
    Hour
    Minute
    Second
    Date
    TimeOfDay
    DateTime
    ZonedDateTime
    DayOfWeek
    DateDelta
    Monday
    Tuesday
    Wednesday
    Thursday
    Friday
    Saturday
    Sunday
    getYear
    getMonth
    getDay
    getHour
    getMinute
    getSecond
    getDate
    getTime
    getDateTime
    getZone
    isLeapYear
    daysInFeb
    daysInMonth
    dateToIso
    timeToIso
    dateTimeToIso
    zonedToIso
    dayOfWeekName
    dayOfWeekShort
    dayOfWeekIndex
    toDateTime
    toZoned
    midnight
    epoch
)

Types ​

Wrapper aliases ​

NameDefinitionDescription
YearIntCalendar year
MonthIntMonth number (1–12)
DayIntDay of month (1–31)
HourIntHour (0–23)
MinuteIntMinute (0–59)
SecondIntSecond (0–59)

Product types ​

aivi
use aivi.date (
    Day
    Hour
    Minute
    Month
    Second
    Year
)

type Date =
  Date year:Year month:Month day:Day

type TimeOfDay =
  TimeOfDay hour:Hour minute:Minute second:Second

type DateTime =
  DateTime date:Date time:TimeOfDay

type ZonedDateTime =
  ZonedDateTime dateTime:DateTime zone:Text

Construction is positional:

aivi
value today = Date 2024 6 15
value noon = TimeOfDay 12 0 0
value now = DateTime today noon
value utcNow = ZonedDateTime now "+00:00"

DayOfWeek ​

aivi
type DayOfWeek =
  | Monday
  | Tuesday
  | Wednesday
  | Thursday
  | Friday
  | Saturday
  | Sunday

DateDelta domain ​

DateDelta wraps an Int representing a number of days.

aivi
domain DateDelta over Int
LiteralExampleDescription
dy7dyDays
wk2wkWeeks
MemberTypeDescription
daysInt → DateDeltaWrap a day count
(+)DateDelta → DateDelta → DateDeltaAdd deltas
(-)DateDelta → DateDelta → DateDeltaSubtract deltas
(*)DateDelta → Int → DateDeltaScale a delta
(<)DateDelta → DateDelta → BoolCompare deltas

Accessors ​

FunctionTypeDescription
getYearDate → YearExtract the year
getMonthDate → MonthExtract the month
getDayDate → DayExtract the day
getHourTimeOfDay → HourExtract the hour
getMinuteTimeOfDay → MinuteExtract the minute
getSecondTimeOfDay → SecondExtract the second
getDateDateTime → DateExtract the date part
getTimeDateTime → TimeOfDayExtract the time part
getDateTimeZonedDateTime → DateTimeExtract the date-time
getZoneZonedDateTime → TextExtract the timezone

Calendar helpers ​

FunctionTypeDescription
isLeapYearYear → BoolGregorian leap year test
daysInFebYear → Day28 or 29 depending on leap year
daysInMonthMonth → Year → DayNumber of days in a given month

Formatting ​

Formatting assumes valid date/time components and uses the supplied zone text without timezone conversion.

FunctionTypeDescription
dateToIsoDate → Text"2024-06-15"
timeToIsoTimeOfDay → Text"14:30:00"
dateTimeToIsoDateTime → Text"2024-06-15T14:30:00"
zonedToIsoZonedDateTime → Text"2024-06-15T14:30:00+00:00"

Comparison ​

Date provides Eq and Ord, so ordinary comparison operators work directly:

aivi
use aivi.date (epoch)

value sameEpoch : Bool = epoch == epoch
value ordered : Bool = epoch <= epoch

Constructors ​

FunctionTypeDescription
toDateTimeDate → TimeOfDay → DateTimeCombine date and time
toZonedDateTime → Text → ZonedDateTimeAttach timezone

Constants ​

ValueTypeDescription
midnightTimeOfDayTimeOfDay 0 0 0
epochDateDate 1970 1 1

DayOfWeek helpers ​

FunctionTypeDescription
dayOfWeekNameDayOfWeek → TextFull name: "Monday"
dayOfWeekShortDayOfWeek → TextShort name: "Mon"
dayOfWeekIndexDayOfWeek → IntISO index: Monday=1 … Sunday=7

Example ​

aivi
use aivi.date (
    Date
    DateTime
    TimeOfDay
    ZonedDateTime
    dateToIso
    dateTimeToIso
    isLeapYear
    daysInMonth
    epoch
    midnight
    toDateTime
    toZoned
)

value label = dateToIso epoch
value feb = daysInMonth 2 2024
value meeting = toDateTime epoch midnight
value utcMeeting = toZoned meeting "+00:00"

Notes ​

  • Date uses Eq / Ord instances for comparison rather than bespoke comparison helpers.
  • All types are purely structural — no runtime intrinsics are needed for construction, accessors, formatting, or lexicographic Date comparison.
  • DateDelta is a domain over Int. Its operator implementations are provided by the runtime, following the same pattern as aivi.duration.Duration.
  • Month and day values are not range-checked at the type level. Date 2024 13 32 is syntactically valid but semantically meaningless.

Additional constructors ​

DateTime date time combines a Date and TimeOfDay. ZonedDateTime dateTime zone attaches a textual zone to a date-time. The DayOfWeek constructors are Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, and Sunday.

(c) 2026 by Andreas Herd