Eve Date and Time
Calendar Date
Date exists in Eve 0.0.8 and is validated by the tests. The structure in this section is the design of the type; Instant and DateTime come with the module time (level 5).In Eve, we represent calendar dates using a Date object that contains four fields: era, year, month, day. The field era is part of the design and is not in the validated version 0.4 of the type.
Date Structure
The Date type is defined as an object with the following fields:
era: Ordinal {BCE, CE}, the default is CEyear: Integer representing the year, 1 or more (there is no year 0)month: Integer representing the month (1-12)day: Integer representing the day of the month (1-31)
Note: Dates before the Common Era have the era BCE. A comparison puts every BCE date before every CE date.
Date Literals
A date is created in two ways: from a string, using the method parse() with a format constant, or from an object literal with a type hint. The format constants are YMD, DMY and MDY:
YMDformat: "YYYY/MM/DD"DMYformat: "DD/MM/YYYY"MDYformat: "MM/DD/YYYY"
Note: A string may end with an era label: CE, AD, BCE or BC. If it is omitted, the era is CE.
Example Usage
#date format demo
primary aspect date_demo is
process main is
new date1 := "2023/06/15".parse(YMD); ** June 15, 2023 CE
new date2 := "30/11/753 BCE".parse(DMY); ** November 30, 753 BCE
new date3 := "07/04/1776 AD".parse(MDY); ** July 4, 1776 AD
new date4 := "01/01/2000".parse(DMY); ** January 1, 2000 CE
** Date comparisons
expect date3 > date2; ** 1776 AD is after 753 BCE
expect date1 > date3; ** 2023 CE is after 1776 AD
expect date4 > date3; ** 2000 is after 1776
** Access individual fields
print "Year of date1: {date1.year}";
print "Month of date2: {date2.month}";
print "Era of date2: {date2.era}";
** Create a new date
new custom_date = {era: CE, year: 1066, month: 10, day: 14} :Date;
print custom_date; ** {era: CE, year: 1066, month: 10, day: 14}
** Format a date for printing (one direction)
print date1 as YMD; ** 2023/06/15
return;
end date_demo;
Additional Methods
The Date object provides various methods for manipulation and querying:
is_bce(): Returns True if the era is BCE, False otherwiseto_julian(): Converts the date to Julian Day Numberfrom_julian(jdn): Creates a date from a Julian Day Numberadd_days(n): Returns a new Date object n days after this datesubtract_days(n): Returns a new Date object n days before this datedays_between(other_date): Calculates days between two dates
Time & Duration
We use Time or Duration data types. These are primitive types not nullable.
Time
A Time is created from a string using the method parse() with a format constant. The constants T12 and T24 represent the standard time formats:
- Constant: T12 = "hh:mm:ssxx, 999ms"
- Constant: T24 = "hh:mm:ss, 999ms"
hh: hours, 00..23 in T24 and 01..12 in T12
mm: minutes, 00..59
ss: seconds, 00..59
xx: can be: (am/pm)
999ms: milliseconds
Example:
# time demo
primary aspect time_demo is
process main is
** define 3 variable of same type
new time1, time2, time3 :Time;
** alter variables using method parse(), the format is expected
let time1 := "00:23:59, 0ms".parse(T24);
new time2 := "23:59:59, 999ms".parse(T24);
new time3 := "11:59:59pm, 10ms".parse(T12);
** check time
expect time1.h == 0;
expect time1.m == 23;
expect time1.s == 59;
expect time2.ms == 999;
expect time3.ms == 10;
expect time3.t == pm;
return;
end time_demo;
Duration
Duration is an object with the fields year, days, hours, min, sec and ms. Internally it is stored as a signed 64-bit number of milliseconds. The field min means minutes: the name is written in full to avoid confusion with months.
- A Duration literal is an object literal:
{year:34, days:365, hours:4, min:30, sec:26, ms:444}. - The fields you omit are zero.
- The range is -2^63 .. 2^63-1 milliseconds.
Example
# duration demo
primary aspect duration_demo is
process main is
** define 3 variable of same type
new d1 = {ms: 10} :Duration; ** 10 millisec
new d2 = {sec: 1} :Duration; ** 1000 millisec
new d3 = {min: 1} :Duration; ** 60000 millisec
** create duration from string
new d4 := Duration("01:01:01");
** check time
print d3; ** 60000ms
print d4; ** 3661000ms
return;
end duration_demo;
Instant and DateTime (level 5)
The data layer adds two types of the module time, for the columns of a database and the fields of a file (version 0.4):
| Type | Meaning | Written as |
|---|---|---|
Instant | a point in time in UTC (not a "timestamp") | 2026-10-10T08:00:00Z |
DateTime | a date and a time with a zone (not a "local time") | ISO 8601 with its offset, 2026-10-10T10:00:00+02:00 |
print Instant.epoch; ** 1970-01-01T00:00:00Z
new t := Instant.parse("2026-10-10T08:00:00Z");
expect t > Instant.epoch;
print Instant.parse("yesterday"); ** the error parse (code 15)
Printing an Instant always gives the canonical form: ISO 8601, UTC, the letter Z, and no fraction when the fraction is zero. The same form is written in CSV and JSON files and in database columns (timestamptz, ISO text in SQLite). Date, Time and Duration are written in ISO form too. See Files and ETL.
Time zones
A zone is a name of the IANA database (Europe/Bucharest, America/New_York), Z, or a fixed offset (+05:30). The database is a file of the Eve installation, lib/meta/meta.db, and it is the only source of the zone rules: nothing about a zone is written in the program or in the virtual machine, so a new release of the database changes the zones without a new eve.exe. time.zone(name) makes a Zone, time.at_zone(instant, zone) shows an instant in a zone, time.make(date, time, zone) makes a DateTime from a wall clock time (a time the clock skips moves forward by the jump, a time it shows twice is the first one), and time.local_zone!() is the zone of the machine; on Windows it is the zone that the Unicode CLDR gives to the Windows name of the zone (Eastern Standard Time is America/New_York). The module zone of lib/meta gives the details: zone.offset, zone.abbreviation, zone.is_dst and zone.names.
new base := Instant.parse("2026-03-29T00:59:59Z");
new z := time.zone("Europe/Bucharest");
print time.at_zone(base, z); ** 2026-03-29T02:59:59+02:00
print time.at_zone(base + 1s, z); ** 2026-03-29T04:00:00+03:00: the clock jumped
print time.offset_of(time.at_zone(base + 1s, z)); ** PT3H
The rules of every zone are read once, into memory, as a table of spans: the instants where the offset changes, with the changes of the daylight rule expanded to the year 2100. A lookup is a binary search of about a tenth of a microsecond, so a script can ask for the offset of every line of a log. Beyond 2100 the rule of the zone, written in Eve, gives the answer, slower but with the same result.
Quick Format
For printing output using a format we use operator as that is the "quick format" operator. We can use system constant templates that are available for making different formats for different data types. For other values use string interpolation ({name % format}).
The operator as works in one direction only: it formats a value into a string. The other direction is a method of String: "15:30:00, 0ms".parse(T24). The argument of parse() is the format that is expected.
Date Format
Eve has constants to define the date format:
| Constant | Value |
|---|---|
| YMD | YYYY/MM/DD |
| DMY | DD/MM/YYYY |
| MDY | MM/DD/YYYY |
Time Format
Eve has constants to define the time format:
| Constant | Value |
|---|---|
| T24 | hh:mm:ss, 999ms |
| T12 | hh:mm:ssxx, 999ms (xx is am or pm) |
Numeric Format
Eve can print comma "," for decimal numbers but also can print dot.
| Constant | Value |
|---|---|
| EUR | ,. |
| USA | ., |
Read next: Control Flow