DtObj Rust 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

// Cargo.toml:
//     [dependencies]
//     chilkat = "11.6"

use chilkat::DtObj;

// Once per process, before any other Chilkat call:
chilkat::unlock_bundle("Anything for 30-day trial")?;  // shorthand for Global::new().unlock_bundle(..)

let dt_obj = DtObj::new();
// ... the native object is freed when `dt_obj` goes out of scope.
pub fn new() -> DtObj

Creates the underlying native Chilkat object (DtObj also implements Default). Every method takes &self, so the object never needs to be declared mut. A DtObj is Send but not Sync: it may be moved to another thread, but a reference to it cannot be shared between threads at the same time.

impl Drop for DtObj

The native object is freed when the DtObj is dropped — when it goes out of scope, or explicitly with drop(dt_obj). There is no Dispose method to call.

Errors

Methods that can fail return chilkat::Result<T>, which is Result<T, chilkat::Error>: a method whose only outcome is success or failure returns Result<()>, a method producing a string or an object returns Result<String> or Result<DtObj>. The error carries the object's LastErrorText at the time of the failure (Error::last_error_text), the class and method names, and implements std::error::Error, so ? works in any function returning chilkat::Result or a Box<dyn Error>. Properties never fail, and methods that answer a question (has_..., is_..., ...) return a plain bool.

match dt_obj.some_method(...) {
    Ok(value) => println!("{value:?}"),
    Err(e) => eprintln!("{}", e.last_error_text()),
}

Properties

Day
// read/write
pub fn day(&self) -> i32
pub fn set_day(&self, value: i32)

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

top
DebugLogFilePath
// read/write
pub fn debug_log_file_path(&self) -> String
pub fn set_debug_log_file_path(&self, value: &str)

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 hour(&self) -> i32
pub fn set_hour(&self, value: i32)

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

top
LastErrorHtml
// read-only
pub fn last_error_html(&self) -> String

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 last_error_text(&self) -> String

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 last_error_xml(&self) -> String

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 last_method_success(&self) -> bool
pub fn set_last_method_success(&self, value: bool)

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 minute(&self) -> i32
pub fn set_minute(&self, value: i32)

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

top
Month
// read/write
pub fn month(&self) -> i32
pub fn set_month(&self, value: i32)

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

top
Second
// read/write
pub fn second(&self) -> i32
pub fn set_second(&self, value: i32)

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

top
StructTmMonth
// read/write
pub fn struct_tm_month(&self) -> i32
pub fn set_struct_tm_month(&self, value: i32)

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

top
StructTmYear
// read/write
pub fn struct_tm_year(&self) -> i32
pub fn set_struct_tm_year(&self, value: i32)

The year represented as the number of years since 1900.

top
Utc
// read/write
pub fn utc(&self) -> bool
pub fn set_utc(&self, value: bool)

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

top
VerboseLogging
// read/write
pub fn verbose_logging(&self) -> bool
pub fn set_verbose_logging(&self, value: bool)

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 version(&self) -> String

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

More Information and Examples
top
Year
// read/write
pub fn year(&self) -> i32
pub fn set_year(&self, value: i32)

The year, such as 2012.

top

Methods

DeSerialize
pub fn de_serialize(&self, serialized_dt_obj: &str)

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) -> Result<String>

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 Err(chilkat::Error) on failure.

top