Simple (no leap seconds, UTC-only), DateTime, Date and Time types.
const dt = try zul.DateTime.parse("2028-11-05T23:29:10Z", .rfc3339);
const next_week = try dt.add(7, .days);
std.debug.assert(next_week.order(dt) == .gt);
std.debug.print("{d} == {s}", .{dt.unix(.milliseconds), dt});
zul.DateTime
is a very basic DateTime struct designed for the main purpose of allowing RFC3339 dates to be read and written. It is simply an i64
representing the number of microseconds since unix epoch (Jan 1 1970). It supports valus ranging from Jan 1, -4712 to Dec 31, 9999. It does not support leap seconds and only supports UTC timezones.
When serialized and parsed with JSON, or formatted using std.fmt
, the RFC3339 representation is used.
micros: i64
Microseconds since unix epoch. A negative value indicates a DateTime before Jan 1, 1970.
initUTC(...) !DateTime
fn initUTC(
year: i16,
month: u8,
day: u8,
hour: u8,
min: u8,
sec: u8,
micros: u32
) !DateTime
Creates a DateTime
. This will fail if the date is outside of the supported range (i.e. year
< -4712 or year
9999), or if the date is invalid (e.g. Nov 31).
zul.Date
represents a year, month and day. It is serialized and parsed to JSON or using std.fmt
using the YYYY-MM-DD
format (i.e. RFC3339).
year: i16
month: u8
1-based (i.e. Jan == 1)
day: u8
zul.Time
represents a hour, minute, second and microsecond. It is serialized and parsed to JSON or using std.fmt
using the HH:MM:SS[.000000]
format (i.e. RFC3339).
hour: u8
min: u8
sec: u8
micros: u32