StaticfromCreates a new CborDate from the given JavaScript Date.
This method creates a new CborDate instance by wrapping a
JavaScript Date.
A Date instance to wrap
A new CborDate instance
StaticfromCreates a new CborDate from year, month, and day components.
This method creates a new CborDate with the time set to 00:00:00 UTC.
The year component (e.g., 2023)
The month component (1-12)
The day component (1-31)
A new CborDate instance
StaticfromCreates a new CborDate from year, month, day, hour, minute, and second
components.
The year component (e.g., 2023)
The month component (1-12)
The day component (1-31)
The hour component (0-23)
The minute component (0-59)
The second component (0-59)
A new CborDate instance
StaticfromCreates a new CborDate from seconds since (or before) the Unix epoch.
This method creates a new CborDate representing the specified number of
seconds since the Unix epoch (1970-01-01T00:00:00Z). Negative values
represent times before the epoch.
Seconds from the Unix epoch (positive or negative), which can include a fractional part for sub-second precision
A new CborDate instance
StaticfromCreates a new CborDate from a string containing an ISO-8601 (RFC-3339)
date (with or without time).
This method parses a string representation of a date or date-time in
ISO-8601/RFC-3339 format and creates a new CborDate instance. It
supports both full date-time strings (e.g., "2023-02-08T15:30:45Z")
and date-only strings (e.g., "2023-02-08").
A string containing a date or date-time in ISO-8601/RFC-3339 format
A new CborDate instance if parsing succeeds
StaticnowCreates a new CborDate containing the current date and time.
A new CborDate instance representing the current UTC date and time
StaticwithCreates a new CborDate containing the current date and time plus the given
duration.
The duration in milliseconds to add to the current time
A new CborDate instance representing the current UTC date and time plus
the duration
Returns the CborDate as the number of seconds since the Unix epoch.
This method converts the date to a floating-point number representing the number of seconds since the Unix epoch (1970-01-01T00:00:00Z). Negative values represent times before the epoch. The fractional part represents sub-second precision.
Seconds since the Unix epoch as a number
Add seconds to this date.
Seconds to add (can be fractional)
New CborDate instance
Subtract seconds from this date.
Seconds to subtract (can be fractional)
New CborDate instance
Get the difference in seconds between this date and another.
Other CborDate to compare with
Difference in seconds (this - other)
Implementation of the CborTagged interface for CborDate.
This implementation specifies that CborDate values are tagged with CBOR tag 1,
which is the standard CBOR tag for date/time values represented as seconds
since the Unix epoch per RFC 8949.
A vector containing tag 1
Implementation of the CborTaggedEncodable interface for CborDate.
Converts this CborDate to an untagged CBOR value.
The date is converted to a numeric value representing the number of seconds since the Unix epoch. This value may be an integer or a floating-point number, depending on whether the date has fractional seconds.
A CBOR value representing the timestamp
Implementation of the CborTaggedDecodable interface for CborDate.
Creates a CborDate from an untagged CBOR value.
The CBOR value must be a numeric value (integer or floating-point) representing the number of seconds since the Unix epoch.
The untagged CBOR value
This CborDate instance (mutated)
StaticfromStaticfromImplementation of the toString method for CborDate.
This implementation provides a string representation of a CborDate in ISO-8601
format. For dates with time exactly at midnight (00:00:00), only the date
part is shown. For other times, a full date-time string is shown.
String representation in ISO-8601 format
// A date at midnight will display as just the date
const date = CborDate.fromYmd(2023, 2, 8);
// Returns "2023-02-08"
console.log(date.toString());
// A date with time will display as date and time
const date2 = CborDate.fromYmdHms(2023, 2, 8, 15, 30, 45);
// Returns "2023-02-08T15:30:45.000Z"
console.log(date2.toString());
Compare two dates for equality.
Other CborDate to compare
true if dates represent the same moment in time
Compare two dates.
Other CborDate to compare
-1 if this < other, 0 if equal, 1 if this > other
Convert to JSON (returns ISO 8601 string).
ISO 8601 string
A CBOR-friendly representation of a date and time.
The
CborDatetype provides a wrapper around JavaScript's nativeDatethat supports encoding and decoding to/from CBOR with tag 1, following the CBOR date/time standard specified in RFC 8949.When encoded to CBOR, dates are represented as tag 1 followed by a numeric value representing the number of seconds since (or before) the Unix epoch (1970-01-01T00:00:00Z). The numeric value can be a positive or negative integer, or a floating-point value for dates with fractional seconds.
Features
CborTagged,CborTaggedEncodable, andCborTaggedDecodableinterfacesExample