--- layout: site.njk title: zul.DateTime ---
Simple (no leap seconds, UTC-only), DateTime, Date and Time types.
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.
{% highlight zig %}
fn initUTC(
year: i16,
month: u8,
day: u8,
hour: u8,
min: u8,
sec: u8,
micros: u32
) !DateTime
{% endhighlight %}
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).
Creates a DateTime. precision can be one of: .seconds,
.milliseconds or .microseconds.
Creates a DateTime for the current date and time.
Parses the string representation of a date + time. Currently, the only supported format is .rfc3339. Trying to parse a non-UTC date will result in an error.
Creates a new DateTime. unit can be one of .microseconds, .milliseconds, .seconds, .minutes, .hours or .days.
Returns the Date portion of the DateTime.
Returns the Time portion of the DateTime.
Returns number of .seconds, .milliseconds or .microseconds since unix epoch.
Compares two values.
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
day: u8
Creates a Date. This will fail if the date is invalid (e.g. Nov 31).
Returns true if the date is valid, false otherwise.
Parses the string representation of a date. Supported formats are .rfc3339 and .iso8601.
Compares two values.
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
Creates a Time. This will fail if the time is invalid (e.g. min == 62).
Returns true if the time is valid, false otherwise.
Parses the string representation of a time. Currently, the only supported format is .rfc3339.
Compares two values.