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, date comparison helpers, 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
    dateEq
    dateLt
    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
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
unwrapDateDelta → IntExtract the raw Int
(+)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
aivi
isLeapYear 2024         -- True
daysInMonth 2 2024      -- 29
daysInMonth 11 2024     -- 30

Formatting

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"
aivi
dateToIso (Date 2024 6 15)                              -- "2024-06-15"
dateTimeToIso (DateTime (Date 2024 6 15) (TimeOfDay 14 30 0))  -- "2024-06-15T14:30:00"

Comparison

FunctionTypeDescription
dateEqDate → Date → BoolStructural equality
dateLtDate → Date → BoolChronological less-than

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
    midnight
    toDateTime
    toZoned
)

value birthday = Date 1990 3 14
value label = dateToIso birthday                        -- "1990-03-14"
value feb = daysInMonth 2 2024                          -- 29

value meeting = toDateTime (Date 2024 12 25) midnight
value utcMeeting = toZoned meeting "+00:00"

Notes

  • All types are purely structural — no runtime intrinsics are needed for construction, accessors, or formatting.
  • 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.

AIVI Language Manual