DtObj Zig Reference Documentation

DtObj

Current Version: 11.6.1

Chilkat.DtObj

Represent a date/time as simple editable fields.

Chilkat.DtObj is a lightweight date/time value object used by Chilkat methods that need to pass or return individual date and time fields. It stores values such as year, month, day, hour, minute, and second, along with a flag indicating whether the value represents UTC or local time. It also provides a compact serialization format for saving and restoring the date/time value.

Simple date fields

Store and edit the year, month, day, hour, minute, and second as individual properties.

UTC or local time

Use the UTC flag to indicate whether the stored fields represent UTC or local time.

Struct tm compatibility

Use alternate month and year properties when working with struct tm-style date/time conventions.

Serialize and restore

Save and restore the object using Chilkat's compact internal serialized date/time representation.

Used by other classes

Pass DtObj values to Chilkat methods that require explicit date/time fields or return date/time information.

Small and focused

Use this class as a simple container rather than a full date/time calculation or timezone-conversion engine.

Common pattern: Create or receive a DtObj, set or read the individual date/time fields, check whether the value is UTC or local time, and pass the object to another Chilkat method. Use serialization only when the date/time value needs to be saved and restored in Chilkat's compact internal format.

Object Creation

// Add the package once:
//     zig fetch --save https://chilkatdownload.com/11.6.1/chilkat-zig-11.6.1.tar.gz
// and in build.zig:
//     const chilkat = b.dependency("chilkat", .{ .target = target, .optimize = optimize });
//     exe.root_module.addImport("chilkat", chilkat.module("chilkat"));
const chilkat = @import("chilkat");

// Once per process, before any other Chilkat call:
try chilkat.unlockBundle("Anything for 30-day trial");

const dt_obj = try chilkat.DtObj.init();
defer dt_obj.deinit();
pub fn init() Allocator.Error!DtObj

Creates the underlying native Chilkat object. DtObj is a one-pointer struct passed by value; copying it copies the handle (two names for one object). Returns error.OutOfMemory if the library could not allocate the object. Use an object from one thread at a time; it may be handed from one thread to another.

pub fn deinit(self: DtObj) void

Releases the native object. Call it exactly once per object (usually with defer); the handle is invalid afterwards. Objects returned by methods are owned by the caller too and are released the same way.

pub fn fromHandle(h: *chilkat.c.CkDtObj.HCkDtObj) DtObj

Wraps a handle obtained from the C API (chilkat.c.CkDtObj), taking ownership of it. The struct's handle field goes the other way, for anything the Zig API does not cover.

Errors and memory

Methods that can fail return an error union: a method whose only outcome is success or failure returns Error!void; a method producing a string returns (Error || Allocator.Error)![:0]u8; a method producing an object returns Error!T. chilkat.Error is error{ChilkatFailed}; the reason for a failure is in getLastErrorText, and the object remains usable. Properties never fail, and methods that answer a question (hasMember, isUnlocked, ...) return a plain bool.

String arguments are [:0]const u8 (UTF-8; string literals can be passed as is). String results are copies allocated with the allocator argument and owned by the caller, so they stay valid across later calls on the same object.

const text = dt_obj.someMethod(allocator, ...) catch |err| {
    const why = try dt_obj.getLastErrorText(allocator);
    defer allocator.free(why);
    std.debug.print("{s}\n", .{why});
    return err;
};
defer allocator.free(text);

Properties

Day
// read/write
pub fn getDay(self: DtObj) i32
pub fn setDay(self: DtObj, value: i32) void

The day of the month. The valid values for this member are 1 through 31.

top
DebugLogFilePath
// read/write
pub fn getDebugLogFilePath(self: DtObj, allocator: Allocator) Allocator.Error![:0]u8
pub fn setDebugLogFilePath(self: DtObj, value: [:0]const u8) void

If set to a file path, this property logs the LastErrorText of each Chilkat method or property call to the specified file. This logging helps identify the context and history of Chilkat calls leading up to any crash or hang, aiding in debugging.

Enabling the VerboseLogging property provides more detailed information. This property is mainly used for debugging rare instances where a Chilkat method call causes a hang or crash, which should generally not happen.

Possible causes of hangs include:

  • A timeout property set to 0, indicating an infinite timeout.
  • A hang occurring within an event callback in the application code.
  • An internal bug in the Chilkat code causing the hang.

More Information and Examples
top
Hour
// read/write
pub fn getHour(self: DtObj) i32
pub fn setHour(self: DtObj, value: i32) void

The hour. The valid values for this member are 0 through 23.

top
LastErrorHtml
// read-only
pub fn getLastErrorHtml(self: DtObj, allocator: Allocator) Allocator.Error![:0]u8

Provides HTML-formatted information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.

top
LastErrorText
// read-only
pub fn getLastErrorText(self: DtObj, allocator: Allocator) Allocator.Error![:0]u8

Provides plain text information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.

top
LastErrorXml
// read-only
pub fn getLastErrorXml(self: DtObj, allocator: Allocator) Allocator.Error![:0]u8

Provides XML-formatted information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.

top
LastMethodSuccess
// read/write
pub fn getLastMethodSuccess(self: DtObj) bool
pub fn setLastMethodSuccess(self: DtObj, value: bool) void

Indicates the success or failure of the most recent method call: true means success, false means failure. This property remains unchanged by property setters or getters. This method is present to address challenges in checking for null or Nothing returns in certain programming languages. Note: This property does not apply to methods that return integer values or to boolean-returning methods where the boolean does not indicate success or failure.

top
Minute
// read/write
pub fn getMinute(self: DtObj) i32
pub fn setMinute(self: DtObj, value: i32) void

The minute. The valid values for this member are 0 through 59.

top
Month
// read/write
pub fn getMonth(self: DtObj) i32
pub fn setMonth(self: DtObj, value: i32) void

The month. The valid values for this member are 1 through 12 where 1 = January and 12 = December.

top
Second
// read/write
pub fn getSecond(self: DtObj) i32
pub fn setSecond(self: DtObj, value: i32) void

The second. The valid values for this member are 0 through 59.

top
StructTmMonth
// read/write
pub fn getStructTmMonth(self: DtObj) i32
pub fn setStructTmMonth(self: DtObj, value: i32) void

The month. The valid values for this member are 0 through 11 where 0 = January and 11 = December.

top
StructTmYear
// read/write
pub fn getStructTmYear(self: DtObj) i32
pub fn setStructTmYear(self: DtObj, value: i32) void

The year represented as the number of years since 1900.

top
Utc
// read/write
pub fn getUtc(self: DtObj) bool
pub fn setUtc(self: DtObj, value: bool) void

true if this is a UTC time, otherwise false if this is a local time.

top
VerboseLogging
// read/write
pub fn getVerboseLogging(self: DtObj) bool
pub fn setVerboseLogging(self: DtObj, value: bool) void

If set to true, then the contents of LastErrorText (or LastErrorXml, or LastErrorHtml) may contain more verbose information. The default value is false. Verbose logging should only be used for debugging. The potentially large quantity of logged information may adversely affect peformance.

top
Version
// read-only
pub fn getVersion(self: DtObj, allocator: Allocator) Allocator.Error![:0]u8

Version of the component/library, such as "10.1.0"

More Information and Examples
top
Year
// read/write
pub fn getYear(self: DtObj) i32
pub fn setYear(self: DtObj, value: i32) void

The year, such as 2012.

top

Methods

DeSerialize
pub fn deSerialize(self: DtObj, serialized_dt_obj: [:0]const u8) void

Loads the date/time with a string having the format as produced by the Serialize method, which is a string of SPACE separated integers containing (in this order) year, month, day, hour, minutes, seconds, and a UTC flag having the value of 1/0.

top
Serialize
pub fn serialize(self: DtObj, allocator: Allocator) (Error || Allocator.Error)![:0]u8

Serializes the date/time to a us-ascii string that can be imported at a later time via the DeSerialize method. The format of the string returned by this method is not intended to match any published standard. It is formatted to a string with SPACE separated integers containing (in this order) year, month, day, hour, minutes, seconds, and a UTC flag having the value of 1/0.

Returns error.ChilkatFailed on failure; getLastErrorText explains why. The string is allocated with allocator and owned by the caller (defer allocator.free(s)).

top