Date

← Reference
Io

IoObject wrapper around the plain-C Date struct (a timeval plus a timezone). All real calendar math — year/month/day/hour/minute/second decomposition, strftime-style formatting, strptime-style parsing, UTC/local/zone conversion — lives in Date.c and PortableStrptime.c; this file just bridges Io message sends to those C routines, manages lifecycle (tag, clone, free, compare), and handles arithmetic with IoDuration (Date + Duration -> Date, Date - Date -> Duration). A "format" slot on the proto holds the default strftime pattern ("%Y-%m-%d %H:%M:%S %Z") that asString falls back to when no explicit format argument is supplied.

IoDate_compare(self, date)

Tag compareFunc. Delegates to Date_compare for Date-vs-Date (which ultimately compares timevals) and falls back to the default object compare for cross-type comparisons so ordered collections still get a total order.

IoDate_free(self)

Tag freeFunc. Releases the heap-allocated C Date struct; the IoObject header is reclaimed by the collector.

IoDate_new(state)

Clones the registered proto. Returned Date carries whatever time value the proto currently holds; callers typically follow up with Date_now or one of the fromX methods to stamp a specific value.

IoDate_newTag(state)

Builds the Date tag, wiring clone / free / compare function pointers. No markFunc is needed since the C Date payload holds no IoObject references — it is a pure timeval + timezone record.

IoDate_newWithLocalTime_(state, t)

Factory taking a broken-down struct tm in local time. Date_fromLocalTime_ reassembles the timeval and timezone so the resulting IoDate matches the calendar fields supplied.

IoDate_newWithTime_(state, t)

Factory taking a POSIX time_t (seconds since the epoch). Routes through Date_fromTime_ which populates the embedded timeval's tv_sec and zeroes tv_usec.

IoDate_newWithTimeval_(state, tv)

Factory taking a struct timeval directly, preserving microsecond precision that IoDate_newWithTime_ drops. Used where sub-second accuracy matters (benchmarks, high-resolution timestamps).

IoDate_proto(state)

Creates the Date proto, installs its method table (accessors, zone conversions, serialization, arithmetic operators, printing), attaches the tag from IoDate_newTag, and seeds the "format" slot with the default strftime pattern. Registered on the VM state under protoId so IoDate_new / IoDate_newWithTime_ / IoDate_newWithLocalTime_ can clone it.

IoDate_rawClone(proto)

Tag cloneFunc. Allocates a fresh C Date struct on the new clone and copies the proto's timeval/timezone via Date_copy_, so every IoDate owns its own time state rather than aliasing the proto's.