pub struct Ticks(/* private fields */);Expand description
A signed 128-bit nanosecond instant since 1970-01-01T00:00:00Z.
Implementations§
Source§impl Ticks
impl Ticks
Sourcepub const fn from_unix_nanos(nanos: i128) -> Ticks
pub const fn from_unix_nanos(nanos: i128) -> Ticks
Build an instant from raw nanoseconds since the Unix epoch.
Sourcepub const fn from_unix_seconds(seconds: i64, nanos: u32) -> Result<Ticks>
pub const fn from_unix_seconds(seconds: i64, nanos: u32) -> Result<Ticks>
Build an instant from whole seconds plus sub-second nanoseconds.
nanos must be in 0..1_000_000_000.
Sourcepub fn from_timestamp(seconds: i64, nanos: u32) -> Result<Ticks>
pub fn from_timestamp(seconds: i64, nanos: u32) -> Result<Ticks>
Build from a Unix timestamp (chrono’s DateTime::from_timestamp).
nanos must be in 0..1_000_000_000.
Sourcepub fn from_timestamp_millis(millis: i64) -> Result<Ticks>
pub fn from_timestamp_millis(millis: i64) -> Result<Ticks>
Build from a Unix millisecond timestamp.
Sourcepub fn from_timestamp_micros(micros: i64) -> Result<Ticks>
pub fn from_timestamp_micros(micros: i64) -> Result<Ticks>
Build from a Unix microsecond timestamp.
Sourcepub const fn from_timestamp_nanos(nanos: i128) -> Ticks
pub const fn from_timestamp_nanos(nanos: i128) -> Ticks
Build from a Unix nanosecond timestamp.
Sourcepub fn timestamp(self) -> Result<i64>
pub fn timestamp(self) -> Result<i64>
Whole seconds since the epoch, flooring (the mathematically correct
Unix time; chrono truncates toward zero for pre-epoch instants).
Sourcepub fn timestamp_millis(self) -> Result<i64>
pub fn timestamp_millis(self) -> Result<i64>
Whole milliseconds since the epoch, flooring.
Sourcepub fn timestamp_micros(self) -> Result<i64>
pub fn timestamp_micros(self) -> Result<i64>
Whole microseconds since the epoch, flooring.
Sourcepub fn timestamp_nanos(self) -> Result<i64>
pub fn timestamp_nanos(self) -> Result<i64>
Nanoseconds since the epoch as i64; fails beyond the i64 range.
Sourcepub const fn as_unix_nanos(self) -> i128
pub const fn as_unix_nanos(self) -> i128
Raw nanoseconds since the Unix epoch.
Sourcepub fn to_unix_seconds(self) -> Result<(i64, u32)>
pub fn to_unix_seconds(self) -> Result<(i64, u32)>
Decompose into whole seconds (floor) and sub-second nanoseconds.
The (i64 seconds, u32 nanoseconds) pair is the same shape that
chrono, time and rustix build instants from — a pure numeric
accessor, with no dependency on any of those crates. Fails only for
instants whose day count exceeds i64, i.e. roughly outside ±2.9
billion years.
Examples found in repository?
27fn main() {
28 let d = Date::from_ymd(2024, 6, 15).unwrap();
29 let t = TimeOfDay::from_hms_nano(8, 30, 0, 123_456_789).unwrap();
30 let dt = CivilDateTime::new(d, t);
31 let ticks = Ticks::from_rfc3339("2024-06-15T08:30:00.123456789Z").unwrap();
32 let span = Duration::from_nanos(123_456_789_123);
33 let mut out = [0u8; 64];
34
35 bench("date civil projection (parts)", 1_000_000, || {
36 black_box(black_box(d).parts());
37 });
38 bench("date weekday", 1_000_000, || {
39 black_box(black_box(d).weekday());
40 });
41 bench("ticks -> civil utc", 1_000_000, || {
42 let _ = black_box(black_box(ticks).to_civil_utc());
43 });
44 bench("ticks -> unix seconds", 1_000_000, || {
45 let _ = black_box(black_box(ticks).to_unix_seconds());
46 });
47 bench("civil -> ticks utc", 1_000_000, || {
48 let _ = black_box(black_box(dt).to_ticks_utc());
49 });
50 bench("ticks checked_add duration", 1_000_000, || {
51 let _ = black_box(black_box(ticks).checked_add(black_box(span)));
52 });
53 bench("parse RFC 3339", 200_000, || {
54 let _ = black_box(Ticks::from_rfc3339("2024-06-15T08:30:00.123456789Z"));
55 });
56 bench("format RFC 3339 (buffer)", 200_000, || {
57 let _ = black_box(black_box(ticks).write_rfc3339(&mut out, tzcraft::FractionDigits::Auto));
58 });
59 bench("format strftime (buffer)", 200_000, || {
60 let _ = black_box(black_box(ticks).write_format("%Y-%m-%d %H:%M:%S%.f", &mut out));
61 });
62 bench("parse ISO 8601 duration", 200_000, || {
63 let _ = black_box(Duration::from_iso8601("P1DT2H3M4.5S"));
64 });
65}Sourcepub fn to_timespec(self) -> Result<(i64, i64)>
pub fn to_timespec(self) -> Result<(i64, i64)>
POSIX-timespec-shaped decomposition: (seconds, nanoseconds) as
signed 64-bit values (the same layout as struct timespec on Unix,
and therefore the shape rustix’s Timespec uses).
Fails only when the whole-second count exceeds i64 (≈ ±292 billion
years); the nanosecond component is always in 0..1_000_000_000.
Sourcepub fn from_timespec(seconds: i64, nanos: i64) -> Result<Ticks>
pub fn from_timespec(seconds: i64, nanos: i64) -> Result<Ticks>
Build from a POSIX-timespec-shaped (seconds, nanoseconds) pair.
nanos must be in 0..1_000_000_000; any other value is rejected
(POSIX timespec normalization is not silently applied).
Sourcepub fn now() -> Result<Ticks>
Available on crate feature std only.
pub fn now() -> Result<Ticks>
std only.The current wall-clock instant (requires the std feature).
Sourcepub fn to_std_time(self) -> Result<SystemTime>
Available on crate feature std only.
pub fn to_std_time(self) -> Result<SystemTime>
std only.Convert to a std::time::SystemTime (requires the std feature).
Fails for instants before the Unix epoch (unrepresentable).
Sourcepub fn checked_add(self, delta: Duration) -> Result<Ticks>
pub fn checked_add(self, delta: Duration) -> Result<Ticks>
Checked addition of a signed duration.
Examples found in repository?
27fn main() {
28 let d = Date::from_ymd(2024, 6, 15).unwrap();
29 let t = TimeOfDay::from_hms_nano(8, 30, 0, 123_456_789).unwrap();
30 let dt = CivilDateTime::new(d, t);
31 let ticks = Ticks::from_rfc3339("2024-06-15T08:30:00.123456789Z").unwrap();
32 let span = Duration::from_nanos(123_456_789_123);
33 let mut out = [0u8; 64];
34
35 bench("date civil projection (parts)", 1_000_000, || {
36 black_box(black_box(d).parts());
37 });
38 bench("date weekday", 1_000_000, || {
39 black_box(black_box(d).weekday());
40 });
41 bench("ticks -> civil utc", 1_000_000, || {
42 let _ = black_box(black_box(ticks).to_civil_utc());
43 });
44 bench("ticks -> unix seconds", 1_000_000, || {
45 let _ = black_box(black_box(ticks).to_unix_seconds());
46 });
47 bench("civil -> ticks utc", 1_000_000, || {
48 let _ = black_box(black_box(dt).to_ticks_utc());
49 });
50 bench("ticks checked_add duration", 1_000_000, || {
51 let _ = black_box(black_box(ticks).checked_add(black_box(span)));
52 });
53 bench("parse RFC 3339", 200_000, || {
54 let _ = black_box(Ticks::from_rfc3339("2024-06-15T08:30:00.123456789Z"));
55 });
56 bench("format RFC 3339 (buffer)", 200_000, || {
57 let _ = black_box(black_box(ticks).write_rfc3339(&mut out, tzcraft::FractionDigits::Auto));
58 });
59 bench("format strftime (buffer)", 200_000, || {
60 let _ = black_box(black_box(ticks).write_format("%Y-%m-%d %H:%M:%S%.f", &mut out));
61 });
62 bench("parse ISO 8601 duration", 200_000, || {
63 let _ = black_box(Duration::from_iso8601("P1DT2H3M4.5S"));
64 });
65}Sourcepub fn checked_sub(self, delta: Duration) -> Result<Ticks>
pub fn checked_sub(self, delta: Duration) -> Result<Ticks>
Checked subtraction of a signed duration.
Sourcepub fn checked_add_signed(self, rhs: Duration) -> Result<Ticks>
pub fn checked_add_signed(self, rhs: Duration) -> Result<Ticks>
Alias for Ticks::checked_add (chrono-compatible name).
Sourcepub fn checked_sub_signed(self, rhs: Duration) -> Result<Ticks>
pub fn checked_sub_signed(self, rhs: Duration) -> Result<Ticks>
Alias for Ticks::checked_sub (chrono-compatible name).
Sourcepub fn checked_add_days(self, days: Days) -> Result<Ticks>
pub fn checked_add_days(self, days: Days) -> Result<Ticks>
Checked day offset.
Sourcepub fn checked_sub_days(self, days: Days) -> Result<Ticks>
pub fn checked_sub_days(self, days: Days) -> Result<Ticks>
Checked day offset in the negative direction.
Sourcepub fn saturating_add(self, delta: Duration) -> Ticks
pub fn saturating_add(self, delta: Duration) -> Ticks
Saturating addition of a signed duration.
Sourcepub fn saturating_sub(self, delta: Duration) -> Ticks
pub fn saturating_sub(self, delta: Duration) -> Ticks
Saturating subtraction of a signed duration.
Sourcepub fn duration_since(self, earlier: Ticks) -> Duration
pub fn duration_since(self, earlier: Ticks) -> Duration
The signed duration between earlier and self.
Saturates at the representable boundary instead of overflowing:
MAX - MIN would wrap in release and panic in debug.
Sourcepub fn checked_add_months(self, months: Months) -> Result<Ticks>
pub fn checked_add_months(self, months: Months) -> Result<Ticks>
Calendar-aware month stepping on the UTC civil projection.
The day is clamped to the end of the target month
(2023-01-31 + 1 month = 2023-02-28).
Sourcepub fn checked_sub_months(self, months: Months) -> Result<Ticks>
pub fn checked_sub_months(self, months: Months) -> Result<Ticks>
Calendar-aware month stepping in the negative direction.
Sourcepub fn checked_add_years(self, years: i32) -> Result<Ticks>
pub fn checked_add_years(self, years: i32) -> Result<Ticks>
Calendar-aware year stepping (see Ticks::checked_add_months).
Sourcepub fn to_civil_utc(self) -> Result<CivilDateTime>
pub fn to_civil_utc(self) -> Result<CivilDateTime>
The UTC civil projection (date, time-of-day).
Fails only for instants whose day count exceeds i64.
Examples found in repository?
27fn main() {
28 let d = Date::from_ymd(2024, 6, 15).unwrap();
29 let t = TimeOfDay::from_hms_nano(8, 30, 0, 123_456_789).unwrap();
30 let dt = CivilDateTime::new(d, t);
31 let ticks = Ticks::from_rfc3339("2024-06-15T08:30:00.123456789Z").unwrap();
32 let span = Duration::from_nanos(123_456_789_123);
33 let mut out = [0u8; 64];
34
35 bench("date civil projection (parts)", 1_000_000, || {
36 black_box(black_box(d).parts());
37 });
38 bench("date weekday", 1_000_000, || {
39 black_box(black_box(d).weekday());
40 });
41 bench("ticks -> civil utc", 1_000_000, || {
42 let _ = black_box(black_box(ticks).to_civil_utc());
43 });
44 bench("ticks -> unix seconds", 1_000_000, || {
45 let _ = black_box(black_box(ticks).to_unix_seconds());
46 });
47 bench("civil -> ticks utc", 1_000_000, || {
48 let _ = black_box(black_box(dt).to_ticks_utc());
49 });
50 bench("ticks checked_add duration", 1_000_000, || {
51 let _ = black_box(black_box(ticks).checked_add(black_box(span)));
52 });
53 bench("parse RFC 3339", 200_000, || {
54 let _ = black_box(Ticks::from_rfc3339("2024-06-15T08:30:00.123456789Z"));
55 });
56 bench("format RFC 3339 (buffer)", 200_000, || {
57 let _ = black_box(black_box(ticks).write_rfc3339(&mut out, tzcraft::FractionDigits::Auto));
58 });
59 bench("format strftime (buffer)", 200_000, || {
60 let _ = black_box(black_box(ticks).write_format("%Y-%m-%d %H:%M:%S%.f", &mut out));
61 });
62 bench("parse ISO 8601 duration", 200_000, || {
63 let _ = black_box(Duration::from_iso8601("P1DT2H3M4.5S"));
64 });
65}Sourcepub fn weekday_utc(self) -> Result<Weekday>
pub fn weekday_utc(self) -> Result<Weekday>
The UTC weekday.
Sourcepub fn to_rfc3339(self, fraction: FractionDigits) -> String
Available on crate feature alloc only.
pub fn to_rfc3339(self, fraction: FractionDigits) -> String
alloc only.RFC 3339 rendering with the requested fractional-second precision.
The canonical form carries the Z designator. Instants beyond the
civil i64 day range (≈ ±2.9 billion years) fall back to a raw
nanosecond count followed by s.
This method allocates. The allocator-free equivalent is
Ticks::write_rfc3339.
Sourcepub fn write_rfc3339(
self,
out: &mut [u8],
fraction: FractionDigits,
) -> Result<usize>
pub fn write_rfc3339( self, out: &mut [u8], fraction: FractionDigits, ) -> Result<usize>
RFC 3339 rendering into a caller-owned buffer (allocator-free).
Returns the number of bytes written. A 64-byte buffer is always large
enough; Error::buffer_overflow is returned when it is not.
Examples found in repository?
27fn main() {
28 let d = Date::from_ymd(2024, 6, 15).unwrap();
29 let t = TimeOfDay::from_hms_nano(8, 30, 0, 123_456_789).unwrap();
30 let dt = CivilDateTime::new(d, t);
31 let ticks = Ticks::from_rfc3339("2024-06-15T08:30:00.123456789Z").unwrap();
32 let span = Duration::from_nanos(123_456_789_123);
33 let mut out = [0u8; 64];
34
35 bench("date civil projection (parts)", 1_000_000, || {
36 black_box(black_box(d).parts());
37 });
38 bench("date weekday", 1_000_000, || {
39 black_box(black_box(d).weekday());
40 });
41 bench("ticks -> civil utc", 1_000_000, || {
42 let _ = black_box(black_box(ticks).to_civil_utc());
43 });
44 bench("ticks -> unix seconds", 1_000_000, || {
45 let _ = black_box(black_box(ticks).to_unix_seconds());
46 });
47 bench("civil -> ticks utc", 1_000_000, || {
48 let _ = black_box(black_box(dt).to_ticks_utc());
49 });
50 bench("ticks checked_add duration", 1_000_000, || {
51 let _ = black_box(black_box(ticks).checked_add(black_box(span)));
52 });
53 bench("parse RFC 3339", 200_000, || {
54 let _ = black_box(Ticks::from_rfc3339("2024-06-15T08:30:00.123456789Z"));
55 });
56 bench("format RFC 3339 (buffer)", 200_000, || {
57 let _ = black_box(black_box(ticks).write_rfc3339(&mut out, tzcraft::FractionDigits::Auto));
58 });
59 bench("format strftime (buffer)", 200_000, || {
60 let _ = black_box(black_box(ticks).write_format("%Y-%m-%d %H:%M:%S%.f", &mut out));
61 });
62 bench("parse ISO 8601 duration", 200_000, || {
63 let _ = black_box(Duration::from_iso8601("P1DT2H3M4.5S"));
64 });
65}Sourcepub fn from_rfc3339(s: &str) -> Result<Ticks>
pub fn from_rfc3339(s: &str) -> Result<Ticks>
Parse a full RFC 3339 timestamp, normalizing to UTC.
Accepts T/t/space separators, fractional seconds of 1..9 digits,
and offsets in Z, ±HH:MM, ±HHMM or ±HH form.
Examples found in repository?
27fn main() {
28 let d = Date::from_ymd(2024, 6, 15).unwrap();
29 let t = TimeOfDay::from_hms_nano(8, 30, 0, 123_456_789).unwrap();
30 let dt = CivilDateTime::new(d, t);
31 let ticks = Ticks::from_rfc3339("2024-06-15T08:30:00.123456789Z").unwrap();
32 let span = Duration::from_nanos(123_456_789_123);
33 let mut out = [0u8; 64];
34
35 bench("date civil projection (parts)", 1_000_000, || {
36 black_box(black_box(d).parts());
37 });
38 bench("date weekday", 1_000_000, || {
39 black_box(black_box(d).weekday());
40 });
41 bench("ticks -> civil utc", 1_000_000, || {
42 let _ = black_box(black_box(ticks).to_civil_utc());
43 });
44 bench("ticks -> unix seconds", 1_000_000, || {
45 let _ = black_box(black_box(ticks).to_unix_seconds());
46 });
47 bench("civil -> ticks utc", 1_000_000, || {
48 let _ = black_box(black_box(dt).to_ticks_utc());
49 });
50 bench("ticks checked_add duration", 1_000_000, || {
51 let _ = black_box(black_box(ticks).checked_add(black_box(span)));
52 });
53 bench("parse RFC 3339", 200_000, || {
54 let _ = black_box(Ticks::from_rfc3339("2024-06-15T08:30:00.123456789Z"));
55 });
56 bench("format RFC 3339 (buffer)", 200_000, || {
57 let _ = black_box(black_box(ticks).write_rfc3339(&mut out, tzcraft::FractionDigits::Auto));
58 });
59 bench("format strftime (buffer)", 200_000, || {
60 let _ = black_box(black_box(ticks).write_format("%Y-%m-%d %H:%M:%S%.f", &mut out));
61 });
62 bench("parse ISO 8601 duration", 200_000, || {
63 let _ = black_box(Duration::from_iso8601("P1DT2H3M4.5S"));
64 });
65}Sourcepub fn format(self, fmt: &str) -> Result<String>
Available on crate feature alloc only.
pub fn format(self, fmt: &str) -> Result<String>
alloc only.strftime-style rendering, e.g. t.format("%Y-%m-%d %H:%M:%S %z").
The civil parts are UTC and the offset designator is Z. Supported
directives: %Y %y %C %m %d %e %j %H %I %k %l %M %S %f %.f %.3f %p %P %a %A %b %h %B %G %g %V %u %w %U %W %z %:z %Z %s %F %D %x %R %T %X %r %+ %n %t %%, plus the %-/%_/%0 padding modifiers.
This method allocates. The allocator-free equivalent is
Ticks::write_format.
Sourcepub fn write_format(self, fmt: &str, out: &mut [u8]) -> Result<usize>
pub fn write_format(self, fmt: &str, out: &mut [u8]) -> Result<usize>
strftime-style rendering into a caller-owned buffer (allocator-free).
Examples found in repository?
27fn main() {
28 let d = Date::from_ymd(2024, 6, 15).unwrap();
29 let t = TimeOfDay::from_hms_nano(8, 30, 0, 123_456_789).unwrap();
30 let dt = CivilDateTime::new(d, t);
31 let ticks = Ticks::from_rfc3339("2024-06-15T08:30:00.123456789Z").unwrap();
32 let span = Duration::from_nanos(123_456_789_123);
33 let mut out = [0u8; 64];
34
35 bench("date civil projection (parts)", 1_000_000, || {
36 black_box(black_box(d).parts());
37 });
38 bench("date weekday", 1_000_000, || {
39 black_box(black_box(d).weekday());
40 });
41 bench("ticks -> civil utc", 1_000_000, || {
42 let _ = black_box(black_box(ticks).to_civil_utc());
43 });
44 bench("ticks -> unix seconds", 1_000_000, || {
45 let _ = black_box(black_box(ticks).to_unix_seconds());
46 });
47 bench("civil -> ticks utc", 1_000_000, || {
48 let _ = black_box(black_box(dt).to_ticks_utc());
49 });
50 bench("ticks checked_add duration", 1_000_000, || {
51 let _ = black_box(black_box(ticks).checked_add(black_box(span)));
52 });
53 bench("parse RFC 3339", 200_000, || {
54 let _ = black_box(Ticks::from_rfc3339("2024-06-15T08:30:00.123456789Z"));
55 });
56 bench("format RFC 3339 (buffer)", 200_000, || {
57 let _ = black_box(black_box(ticks).write_rfc3339(&mut out, tzcraft::FractionDigits::Auto));
58 });
59 bench("format strftime (buffer)", 200_000, || {
60 let _ = black_box(black_box(ticks).write_format("%Y-%m-%d %H:%M:%S%.f", &mut out));
61 });
62 bench("parse ISO 8601 duration", 200_000, || {
63 let _ = black_box(Duration::from_iso8601("P1DT2H3M4.5S"));
64 });
65}Sourcepub fn parse_from_str(s: &str, fmt: &str) -> Result<Ticks>
pub fn parse_from_str(s: &str, fmt: &str) -> Result<Ticks>
Parse with a strftime-style format string (chrono’s
DateTime::parse_from_str); the civil path requires a timezone offset.
Sourcepub fn to_rfc2822(self) -> String
Available on crate feature alloc only.
pub fn to_rfc2822(self) -> String
alloc only.RFC 2822 rendering in UTC (email / HTTP header dates).
This method allocates. The allocator-free equivalent is
Ticks::write_rfc2822.
Sourcepub fn write_rfc2822(self, out: &mut [u8]) -> Result<usize>
pub fn write_rfc2822(self, out: &mut [u8]) -> Result<usize>
RFC 2822 rendering into a caller-owned buffer (allocator-free).
Sourcepub fn from_rfc2822(s: &str) -> Result<Ticks>
pub fn from_rfc2822(s: &str) -> Result<Ticks>
Parse an RFC 2822 date-time, normalizing to UTC.
Trait Implementations§
impl Copy for Ticks
impl Eq for Ticks
Source§impl<'de> NsonDeserialize<'de> for Ticks
Available on crate feature serde only.
impl<'de> NsonDeserialize<'de> for Ticks
serde only.Source§fn nextdecode_into<D: FormatDecoder<'de>>(
dec: &mut D,
out: &mut DecodeSlot<Self>,
) -> Result<(), D::Error>
fn nextdecode_into<D: FormatDecoder<'de>>( dec: &mut D, out: &mut DecodeSlot<Self>, ) -> Result<(), D::Error>
out. Read moreSource§fn expecting() -> &'static str
fn expecting() -> &'static str
Source§fn nextdecode<D>(
decoder: &mut D,
) -> Result<Self, <D as FormatDecoder<'de>>::Error>where
D: FormatDecoder<'de>,
fn nextdecode<D>(
decoder: &mut D,
) -> Result<Self, <D as FormatDecoder<'de>>::Error>where
D: FormatDecoder<'de>,
Source§impl NsonSchema for Ticks
Available on crate feature serde only.
impl NsonSchema for Ticks
serde only.Source§const SCHEMA: TypeSchema = TypeSchema::Str
const SCHEMA: TypeSchema = TypeSchema::Str
Source§impl NsonSerialize for Ticks
Available on crate feature serde only.
impl NsonSerialize for Ticks
serde only.