Skip to content

Dates and time

Kova has two types for the calendar, without any import:

  • Date: a day, 2026-10-23;
  • DateTime: a day and a time to the second, 2026-10-23 14:05:09, in local wall-clock time.

Both are small values, copied like numbers, compared with = and <, shown as above, and usable as Map keys. They go from year 1 to year 9999, in the Gregorian calendar.

WrittenGives
Date.year(2026) month(10) day(23)that day
DateTime.year(2026) month(10) day(23) hour(14) minute(5)that minute (second(…) may follow)
Date.todaytoday, on this computer’s clock and time zone
DateTime.nownow, to the second
"2026-10-23".to_datea Date?: none if the text is not a date that exists
"2026-10-23 14:05:09".to_datetimea DateTime?

A date that does not exist (February 30, month 13) is refused by the compiler when it is written with numbers, and stops the program when it comes from variables. A text that may be wrong goes through to_date, which gives none instead.

MethodGives
d.year, d.month, d.day -> Intits parts (month from 1 to 12).
t.hour, t.minute, t.second -> Inton a DateTime.
t.date -> Datethe day of a DateTime.
d.weekday -> WeekdayMonday, Tuesday, … Sunday.
d.to_string -> String2026-10-23, or 2026-10-23 14:05:09.

Weekday is an enum, so a match on it must handle every day:

fn main {
let d := Date.year(2026) month(10) day(23)
print(d.weekday)
match d.weekday {
.Saturday, .Sunday => print("weekend")
_ => print("work")
}
}
Friday
work
MethodGives
d.plus_days(n: Int)n days later (earlier if n is negative).
d.plus_months(n: Int)n months later; a day past the end of the month becomes its last day (January 31 + 1 month is February 28 or 29).
t.plus_hours(n), t.plus_minutes(n), t.plus_seconds(n)on a DateTime.
a.days_until(b: Date) -> Intthe number of days from a to b (negative if b is before).
a.seconds_until(b: DateTime) -> Intthe number of seconds from a to b.
fn main {
let start := Date.year(2024) month(1) day(31)
print(start.plus_months(1))
print(start.plus_days(30))
let christmas := Date.year(2026) month(12) day(25)
print(Date.year(2026) month(10) day(23).days_until(christmas))
let t := DateTime.year(2026) month(10) day(23) hour(23) minute(30)
print(t.plus_minutes(90))
}
2024-02-29
2024-03-01
63
2026-10-24 01:00:00

A DateTime is a wall-clock time without a time zone: adding hours never jumps over a change to or from summer time. Date.today and DateTime.now read the computer’s zone (TZ, or the system’s setting).

FunctionGives
system.clock -> Floatthe seconds since 1970, with a fraction: for measuring how long something takes.
system.sleep(seconds: Float)waits that long.
import system
fn main {
let start: Float := system.clock
system.sleep(0.1)
print(system.clock - start >= 0.05)
}
true