Debug label: Object.prototype.toString reports [object CborDate].
The date as the number of seconds since the Unix epoch
(1970-01-01T00:00:00Z), as a floating-point number. Negative values
represent times before the epoch; the fractional part is sub-second
precision.
This is the reference's timestamp(): whole seconds plus nanoseconds
over 10⁹, computed in f64, and it is the value that goes on the wire.
StaticcodecStaticfromCreates a new CborDate from the given JavaScript Date.
A Date instance
A new CborDate instance
StaticfromCreates a new CborDate from year, month, and day components, at
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 the Unix epoch
(1970-01-01T00:00:00Z); negative values are before the epoch.
The value is split as the reference's from_timestamp splits it: whole
seconds by truncation toward zero, then the fraction in nanoseconds
(truncated, never negative), so -1.5 is the instant -1 and
1.0000000001 is 1. NaN is the epoch, as the reference's saturating
cast makes it.
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).
Accepts exactly what the reference's Date::from_string accepts:
2023-02-08T15:30:45Z, …45.123456789+05:30),
with T, t or a space between date and time, up to nine fraction
digits kept (further digits are ignored), Z/z or an offset within
±23:59, and the :60 leap second (read as second 59 plus one second,
as chrono represents it).%Y-%m-%d form: one to
four year digits or a signed year of any length (-0001-01-01,
+12023-02-08), one- or two-digit month and day, with whitespace
allowed before each number (2023-2-8, 2023-02-08).The fraction is kept exactly as nanoseconds, so a decimal fraction
encodes to the same bytes on both sides (timestamp(): whole seconds
plus nanoseconds over 10⁹) and a leap second still displays as :60.
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
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)
The CBOR tags for CborDate: tag 1, the RFC 8949 epoch-based date/time.
The tag carries whatever name the global tags store has for 1 at the
time of the call (tags_for_values in the reference): date once
registerStandardTags() has run, otherwise none. That name is what a
WrongTag error prints as the expected tag.
An array containing tag 1
Converts this CborDate to its untagged CBOR content: the epoch-seconds
numeric value. It may be an integer or a floating-point number,
depending on whether the date has fractional seconds.
A CBOR value representing the timestamp
The ToCbor protocol: dates encode as their tagged form.
Creates a CborDate from an untagged CBOR value, which must be a number
(integer or floating-point) of seconds since the Unix epoch. The static
CborDate.fromUntaggedCbor is the usual entry point; this instance form
exists for the CborTagged protocol and returns a new instance.
The untagged CBOR value
The decoded date
StaticfromStaticfromThe date in ISO-8601 format: only the date part when the time is exactly
midnight (00:00:00), otherwise a date-time to the second with Z.
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:45Z"
console.log(date2.toString());
Compare two dates for equality: the same whole seconds and the same
nanoseconds (chrono's PartialEq). A leap second 23:59:60 is a
different instant from the following 00:00:00, although both encode
to the same wire value.
Other CborDate to compare
true if dates represent the same moment in time
Compare two dates: by whole seconds, then by nanoseconds (chrono's
Ord, so a leap second sorts after :59.999999999 and before the next
:00).
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 UTC date and time, encoded as CBOR tag 1 (RFC 8949 epoch-based date/time).
The instant is held as whole seconds since the Unix epoch plus nanoseconds. On the wire it is tag 1 followed by the seconds since (or before) 1970-01-01T00:00:00Z: an integer for whole seconds, a float otherwise. Implements the
CborTaggedinterface and theToCborprotocol.Example