CkDateTime React Native Reference Documentation

CkDateTime

Current Version: 11.6.1

CkDateTime represents a date/time value and provides conversion methods for common date/time formats, including .NET DateTime, DateTime ticks, RFC 822, RFC 3339 / ISO 8601-style timestamps, Unix time, DOS date/time, OLE DATE, NTP time, ULID timestamps, and Chilkat DtObj. It also supports date arithmetic, age/expiration checks, serialization, and local/UTC conversion.

For an extended overview, see CkDateTime Class Overview

Object Creation

// npm install @chilkat/react-native react-native-nitro-modules
// (React Native 0.76+ with the New Architecture; then `pod install` for iOS.  The Chilkat
//  native library is downloaded and verified during the native build -- see the package README.)

import { Chilkat, CkDateTime } from '@chilkat/react-native'

// Once per app start, before any other Chilkat call:
Chilkat.unlockBundle('Anything for 30-day trial')   // shorthand for new Global().unlockBundle(..)

const dateTime = new CkDateTime()
// ... the native object is released when `dateTime` is garbage collected, or now with dateTime.dispose()
new CkDateTime()

Creates the underlying native Chilkat object. CkDateTime is a Nitro Module HybridObject: use it from the JavaScript thread only (it cannot be passed to a Worklet or another runtime). Every member is synchronous and blocks the JavaScript thread until Chilkat returns; a method that can take a while also exists as a ...Async twin returning a Promise, which runs the same call on a native worker thread so the UI keeps rendering. While such a call is pending, every other call on this object throws, except abort() and assigning onPercentDone / onProgressInfo.

dispose(): void

Releases the native object immediately instead of waiting for garbage collection (useful for a large BinData or an open socket). Calling it more than once is harmless; any other use of the object afterwards throws. An object with a pending ...Async call cannot be disposed until the promise settles.

Errors

A method that can fail throws a plain Error: a method whose only outcome is success or failure returns void and throws on failure; a method producing a string or an object returns it and throws where Chilkat would have returned null. The error's message is "Class.method(...): reason", where the reason is the last informative line of the object's lastErrorText, which holds the full Chilkat log of the failed call. A ...Async twin rejects its promise with the same Error instead of throwing. Properties never throw, and methods that answer a question (has..., is..., ...) return a plain boolean.

try {
  dateTime.someMethod(...)
} catch (e) {
  console.log((e as Error).message)   // CkDateTime.someMethod(...): <reason>
  console.log(dateTime.lastErrorText)   // the full Chilkat log of the failed call
}

// The same call without blocking the JavaScript thread:
try {
  await dateTime.someMethodAsync(...)
} catch (e) {
  console.log((e as Error).message)   // CkDateTime.someMethodAsync: <reason>
}

Properties

DebugLogFilePath
// read/write
debugLogFilePath: string

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
IsDst
// read-only
readonly isDst: number

This is the Daylight Saving Time flag. It can have one of three possible values: 1, 0, or -1. It has the value 1 if Daylight Saving Time is in effect, 0 if Daylight Saving Time is not in effect, and -1 if the information is not available.

Note: This is NOT the DST for the current system time. It is the DST that was in effect at the date value contained in this object.

top
LastErrorHtml
// read-only
readonly lastErrorHtml: 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
readonly lastErrorText: 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
readonly lastErrorXml: 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
lastMethodSuccess: boolean

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
UtcOffset
// read-only
readonly utcOffset: number

For the current system's timezone, returns the number of seconds offset from UTC for this date/time. The offset includes daylight savings adjustment. Local timezones west of UTC return a negative offset.

top
VerboseLogging
// read/write
verboseLogging: boolean

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
readonly version: string

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

More Information and Examples
top

Methods

AddDays
addDays(numDays: number): void

Adds an integer number of days to the date/time. To subtract days, pass a negative integer.

Returns normally on success; throws an Error on failure.

top
AddSeconds
addSeconds(numSeconds: number): void
Introduced in version 9.5.0.65

Adds an integer number of seconds to the date/time. To subtract seconds, pass a negative integer.

Returns normally on success; throws an Error on failure.

More Information and Examples
top
DeSerialize
deSerialize(serializedDateTime: string): 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
DiffSeconds
diffSeconds(dateTimeArg: CkDateTime): number
Introduced in version 9.5.0.65

Returns the difference in seconds between the dateTimeArg and this date/time. The value returned is this object's date/time - dateTimeArg's date/time. For example, if the returned value is positive, then this object's date/time is more recent than dateTimeArg's date/time. If the return value is negative, then this object's date/time is older than dateTimeArg's date/time.

top
ExpiresWithin
expiresWithin(n: number, units: string): boolean
Introduced in version 9.5.0.67

Returns true if the date/time is within n seconds/minutes/hours/days of the current system date/time. Otherwise returns false. The units can be seconds, minutes, hours, or days (plural or singular).

top
GetAsDateTimeTicks
getAsDateTimeTicks(bLocal: boolean): number

Returns the date/time as a 64-bit integer .NET DateTime value.

bLocal indicates whether a local or UTC time is returned.

This is a date and time expressed in the number of 100-nanosecond intervals that have elapsed since January 1, 0001 at 00:00:00.000 in the Gregorian calendar.

The DateTime value type represents dates and times with values ranging from 12:00:00 midnight, January 1, 0001 Anno Domini (Common Era) through 11:59:59 P.M., December 31, 9999 A.D. (C.E.).

Time values are measured in 100-nanosecond units called ticks, and a particular date is the number of ticks since 12:00 midnight, January 1, 0001 A.D. (C.E.) in the GregorianCalendar calendar (excluding ticks that would be added by leap seconds). For example, a ticks value of 31241376000000000L represents the date, Friday, January 01, 0100 12:00:00 midnight. A DateTime value is always expressed in the context of an explicit or default calendar.

top
GetAsDosDate
getAsDosDate(bLocal: boolean): number

Returns the date/time as a 32-bit DOS date/time bitmask.

bLocal indicates whether a local or UTC time is returned.

The DOS date/time format is a bitmask:


			   24                16                 8                 0
	    +-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+
	    |Y|Y|Y|Y|Y|Y|Y|M| |M|M|M|D|D|D|D|D| |h|h|h|h|h|m|m|m| |m|m|m|s|s|s|s|s|
	    +-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+
	     \___________/\________/\_________/ \________/\____________/\_________/
		 year        month       day      hour       minute        second

The year is stored as an offset from 1980. Seconds are stored in two-second increments. (So if the second value is 15, it actually represents 30 seconds.)

top
GetAsIso8601
getAsIso8601(formatStr: string, bLocal: boolean): string
Introduced in version 9.5.0.65

Returns the date/time in a compatible ISO 8601 format according to the format specified in formatStr.. Examples of ISO 8601 formats include the following:

    YYYY-MM-DD

    YYYY-MM-DDThh:mmTZD

    YYYY-MM-DDThh:mm:ssTZD

    YYYY-MM-DDThh:mm:ss:sssTZD
For the date portion of these formats, YYYY is a four-digit year representation, MM is a two-digit month, and DD is a two-digit day. For the time portion, hh is the hour in 24-hour notation, mm is the two-digit minutes, ss is the two-digit seconds, and sss is the 3-digit milliseconds. A time designator T separates the date and time portions of the string, while a time zone designator TZD specifies a time zone (UTC).

bLocal indicates whether a local or UTC time is returned.

Throws an Error on failure (where the description says null is returned, the method throws instead).

More Information and Examples
top
GetAsOleDate
getAsOleDate(bLocal: boolean): number

Returns the date/time in a Windows OLE DATE format.

bLocal indicates whether a local or UTC time is returned.

The OLE automation date format is a floating point value, counting days since midnight 30 December 1899. Hours and minutes are represented as fractional days.

top
GetAsRfc822
getAsRfc822(bLocal: boolean): string

Returns the date/time as an RFC822 formatted string. (An RFC822 format string is what is found in the Date header field of an email, such as Wed, 18 Oct 2017 09:08:21 GMT.)

bLocal indicates whether a local or UTC time is returned.

Throws an Error on failure (where the description says null is returned, the method throws instead).

top
GetAsTimestamp
getAsTimestamp(bLocal: boolean): string
Introduced in version 9.5.0.58

Returns the date/time as an RFC 3339 formatted string, such as 1990-12-31T23:59:60Z. (This is an ISO 8061 format like the following: YYYY-MM-DDThh:mm:ssTZD)

bLocal indicates whether a local or UTC time is returned.

Throws an Error on failure (where the description says null is returned, the method throws instead).

top
GetAsUnixTime
getAsUnixTime(bLocal: boolean): number

Returns the date/time as a Unix time value, which is the number of seconds elapsed since 00:00:00 UTC on January 1, 1970.

bLocal indicates whether the date/time returned is local or UTC.

top
GetAsUnixTime64
getAsUnixTime64(bLocal: boolean): number

The same as GetUnixTime, except returns the date/time as a 64-bit integer.

bLocal indicates whether a local or UTC time is returned.

Note: 64-bit integers are needed after Jan 19, 2038. The Y2038 problem happens because some systems store Unix time as a signed 32-bit number of seconds since Jan 1, 1970. This number runs out on Jan 19, 2038, causing the time to wrap around to a date in 1901.

top
GetAsUnixTimeDbl
getAsUnixTimeDbl(bLocal: boolean): number

The same as GetUnixTime, except returns the date/time as a double.

bLocal indicates whether a local or UTC time is returned.

top
GetAsUnixTimeStr
getAsUnixTimeStr(bLocal: boolean): string
Introduced in version 9.5.0.65

Returns the time in Unix format (in seconds since the epoch: 00:00:00 UTC on 1 January 1970).

bLocal indicates whether the date/time returned is local or UTC.

Throws an Error on failure (where the description says null is returned, the method throws instead).

More Information and Examples
top
OlderThan
olderThan(n: number, units: string): boolean
Introduced in version 9.5.0.67

Returns true if the date/time is older than the current system date/time by n seconds/minutes/hours/days. Otherwise returns false. The units can be seconds, minutes, hours, or days (plural or singular).

top
Serialize
serialize(): 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 or 0.

Throws an Error on failure (where the description says null is returned, the method throws instead).

top
SetFromCurrentSystemTime
setFromCurrentSystemTime(): void

Sets the date/time from the current system time.

Returns normally on success; throws an Error on failure.

top
SetFromDateTimeTicks
setFromDateTimeTicks(bLocal: boolean, ticks: number): void

Sets the date/time from a .NET DateTime value represented in ticks. See GetAsDateTimeTicks for more information.

bLocal indicates whether the passed in date/time is local or UTC.

Returns normally on success; throws an Error on failure.

top
SetFromDosDate
setFromDosDate(bLocal: boolean, t: number): void

Sets the date/time from a 32-bit DOS date/time bitmask. See GetAsDosDate for more information.

Returns normally on success; throws an Error on failure.

top
SetFromDtObj
setFromDtObj(dt: DtObj): void
Introduced in version 9.5.0.47

Sets the date/time from a Chilkat Dt object.

Returns normally on success; throws an Error on failure.

top
SetFromNtpServer
setFromNtpServer(jsonStr: string): void
Introduced in version 9.5.0.96

Sets the date/time by sending a query to an NTP server.

Returns normally on success; throws an Error on failure.

More Information and Examples
top
SetFromNtpTime
setFromNtpTime(ntpSeconds: number): void
Introduced in version 9.5.0.50

Sets the date/time from a 32-bit NTP time value. ntpSeconds is the number of seconds since 00:00 (midnight) 1 January 1900 GMT.

Returns normally on success; throws an Error on failure.

top
SetFromOleDate
setFromOleDate(bLocal: boolean, dt: number): void

Sets the date/time from a Windows OLE DATE value.

bLocal indicates whether the passed in date/time is local or UTC.

Note: This method was not working correctly. The problem was discovered just after releasing v9.5.0.65. It will be fixed in the next version update.

Returns normally on success; throws an Error on failure.

top
SetFromRfc822
setFromRfc822(rfc822Str: string): void

Sets the date/time from an RFC822 date/time formatted string. Here are some examples of RFC822 formatted date/times:

Tue, 15 Nov 2022 22:00:58 +0000
Tue, 15 Nov 2022 20:21:50 +0100
Tue, 01 Nov 2022 18:09:41 -0600

Returns normally on success; throws an Error on failure.

top
SetFromTimestamp
setFromTimestamp(timestamp: string): void
Introduced in version 9.5.0.58

Sets the date/time from an RFC 3339 timestamp format. (such as 1990-12-31T23:59:60Z:)

(This is an ISO 8061 format like the following: YYYY-MM-DDThh:mm:ssTZD)

Note: Starting in v9.5.0.77, strings formatted as YYMMDDhhmmssZ, such as 181221132225Z, can also be passed to this method.

Returns normally on success; throws an Error on failure.

top
SetFromUlid
setFromUlid(bLocal: boolean, ulid: string): void
Introduced in version 9.5.0.94

Sets this object's date/time using the timestamp embedded in the ulid. If the ulid was not a valid ULID, returns false and the date/time is not set. bLocal indicates whether the ulid uses a local time or UTC time.

Returns normally on success; throws an Error on failure.

More Information and Examples
top
SetFromUnixTime
setFromUnixTime(bLocal: boolean, t: number): void

Sets the date/time from a UNIX time value.

bLocal indicates whether the passed in date/time is local or UTC.

Returns normally on success; throws an Error on failure.

top
SetFromUnixTime64
setFromUnixTime64(bLocal: boolean, t: number): void

The same as SetFromUnixTime, except that it uses a 64-bit integer to solve the Y2038 problem.

bLocal indicates whether the passed in date/time is local or UTC.

Note: 64-bit integers are needed after Jan 19, 2038. The Y2038 problem happens because some systems store Unix time as a signed 32-bit number of seconds since Jan 1, 1970. This number runs out on Jan 19, 2038, causing the time to wrap around to a date in 1901.

Returns normally on success; throws an Error on failure.

top
SetFromUnixTimeDbl
setFromUnixTimeDbl(bLocal: boolean, d: number): void

The same as SetFromUnixTime, except that it uses a double to solve the Y2038 problem. (See GetAsUnixTime for more information about Y2038).

bLocal indicates whether the passed in date/time is local or UTC.

Returns normally on success; throws an Error on failure.

top
ToDtObj
toDtObj(bLocal: boolean, dtObj: DtObj): void
Introduced in version 11.0.0

Copies the date/time to the dtObj. Gets the date/time in the local time if bLocal is true, or GMT if bLocal is false.

top
UlidGenerate
ulidGenerate(bLocal: boolean): string
Introduced in version 9.5.0.94

Generates and returns a new ULID using this object's date/time value. bLocal indicates whether to use local time or UTC time.

Throws an Error on failure (where the description says null is returned, the method throws instead).

More Information and Examples
top
UlidIncrement
ulidIncrement(ulid: StringBuilder): void
Introduced in version 9.5.0.94

Increments the ULID that is passed in ulid.

Returns normally on success; throws an Error on failure.

More Information and Examples
top
UlidValidate
ulidValidate(ulid: string): void
Introduced in version 9.5.0.94

Validates the ulid. Returns true if the ulid is valid, otherwise returns false.

Returns normally on success; throws an Error on failure.

More Information and Examples
top