Skip to main content

TimeOfDay

Struct TimeOfDay 

Source
pub struct TimeOfDay(/* private fields */);
Expand description

A time of day, nanosecond precision.

Implementations§

Source§

impl TimeOfDay

Source

pub const MIDNIGHT: TimeOfDay

00:00:00.000000000.

Source

pub const NOON: TimeOfDay

12:00:00.000000000.

Source

pub const MAX: TimeOfDay

23:59:59.999999999.

Source

pub const fn from_nanos_since_midnight(nanos: u64) -> Result<TimeOfDay>

Build from nanoseconds since midnight; validates the day bound.

Source

pub fn from_hms(hour: u32, minute: u32, second: u32) -> Result<TimeOfDay>

Build from hour/minute/second.

Source

pub fn from_hms_milli( hour: u32, minute: u32, second: u32, milli: u32, ) -> Result<TimeOfDay>

Build from hour/minute/second/millisecond.

Source

pub fn from_hms_micro( hour: u32, minute: u32, second: u32, micro: u32, ) -> Result<TimeOfDay>

Build from hour/minute/second/microsecond.

Source

pub fn from_hms_nano( hour: u32, minute: u32, second: u32, nano: u32, ) -> Result<TimeOfDay>

Build from hour/minute/second/nanosecond.

Examples found in repository?
examples/bench.rs (line 29)
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}
Source

pub const fn nanos_since_midnight(self) -> u64

Nanoseconds since midnight.

Source

pub const fn num_seconds_from_midnight(self) -> u32

Whole seconds since midnight (chrono’s Timelike::num_seconds_from_midnight).

Source

pub fn with_hour(self, hour: u32) -> Result<TimeOfDay>

Replace the hour.

Source

pub fn with_minute(self, minute: u32) -> Result<TimeOfDay>

Replace the minute.

Source

pub fn with_second(self, second: u32) -> Result<TimeOfDay>

Replace the second.

Source

pub fn with_nanosecond(self, nano: u32) -> Result<TimeOfDay>

Replace the nanosecond within the second.

Source

pub const fn hour(self) -> u32

Hour (0..24).

Source

pub const fn minute(self) -> u32

Minute (0..60).

Source

pub const fn second(self) -> u32

Second (0..60).

Source

pub const fn nanosecond(self) -> u32

Nanosecond within the second (0..1e9).

Source

pub const fn millisecond(self) -> u32

Millisecond within the second (0..1000).

Source

pub const fn microsecond(self) -> u32

Microsecond within the second (0..1e6).

Source

pub const fn parts(self) -> (u32, u32, u32, u32)

(hour, minute, second, nanosecond).

Source

pub fn checked_add(self, delta: Duration) -> Result<TimeOfDay>

Checked addition that must stay inside the day.

Source

pub fn checked_sub(self, delta: Duration) -> Result<TimeOfDay>

Checked subtraction that must stay inside the day.

Source

pub fn checked_add_signed(self, rhs: Duration) -> Result<TimeOfDay>

Alias for TimeOfDay::checked_add (chrono-compatible name).

Source

pub fn checked_sub_signed(self, rhs: Duration) -> Result<TimeOfDay>

Alias for TimeOfDay::checked_sub (chrono-compatible name).

Source

pub fn overflowing_add(self, delta: Duration) -> (TimeOfDay, i64)

Addition with a whole-day carry instead of an error.

Returns (time_in_day, whole_days_carried). The arithmetic saturates and the carry clamps at i64 bounds for absurdly large durations, so no input can overflow or panic.

Source

pub fn signed_duration_since(self, earlier: TimeOfDay) -> Duration

Signed difference self - earlier (chrono-compatible name).

Source

pub fn duration_since(self, earlier: TimeOfDay) -> Duration

Signed difference self - earlier.

Source

pub fn to_iso(self) -> String

Available on crate feature alloc only.

Strict ISO 8601 rendering (HH:MM:SS[.fffffffff]).

This method allocates. The allocator-free equivalent is TimeOfDay::write_iso.

Source

pub fn write_iso(self, out: &mut [u8]) -> Result<usize>

Strict ISO 8601 rendering into a caller-owned buffer (allocator-free).

Returns the number of bytes written; a 16-byte buffer is always large enough.

Source

pub fn from_iso(s: &str) -> Result<TimeOfDay>

Parse a strict ISO 8601 time of day (HH:MM:SS, optional fraction).

Source

pub fn format(self, fmt: &str) -> Result<String>

Available on crate feature alloc only.

strftime-style rendering, e.g. t.format("%H:%M:%S%.f").

The %-directive set is documented on crate::Ticks::format.

This method allocates. The allocator-free equivalent is TimeOfDay::write_format.

Source

pub fn write_format(self, fmt: &str, out: &mut [u8]) -> Result<usize>

strftime-style rendering into a caller-owned buffer (allocator-free).

Source

pub fn parse_from_str(s: &str, fmt: &str) -> Result<TimeOfDay>

Parse with a strftime-style format string (chrono’s NaiveTime::parse_from_str).

Trait Implementations§

Source§

impl Clone for TimeOfDay

Source§

fn clone(&self) -> TimeOfDay

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for TimeOfDay

Source§

impl Debug for TimeOfDay

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for TimeOfDay

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for TimeOfDay

Source§

impl FromStr for TimeOfDay

Source§

type Err = Error

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<TimeOfDay>

Parses a string s to return a value of this type. Read more
Source§

impl Hash for TimeOfDay

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<'de> NsonDeserialize<'de> for TimeOfDay

Available on crate feature serde only.
Source§

fn nextdecode_into<D: FormatDecoder<'de>>( dec: &mut D, out: &mut DecodeSlot<Self>, ) -> Result<(), D::Error>

Decode into out. Read more
Source§

fn expecting() -> &'static str

Human-readable description of the value this type decodes from. Read more
Source§

fn nextdecode<D>( decoder: &mut D, ) -> Result<Self, <D as FormatDecoder<'de>>::Error>
where D: FormatDecoder<'de>,

Decode and return a value.
Source§

impl NsonSchema for TimeOfDay

Available on crate feature serde only.
Source§

const SCHEMA: TypeSchema = TypeSchema::Str

The compile-time structural description.
Source§

impl NsonSerialize for TimeOfDay

Available on crate feature serde only.
Source§

fn nextencode<E: FormatEncoder>(&self, enc: &mut E) -> Result<(), E::Error>

Next-encode self into encoder. Read more
Source§

impl Ord for TimeOfDay

Source§

fn cmp(&self, other: &TimeOfDay) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

fn clamp_to<R>(self, range: R) -> Self
where Self: Sized, R: ClampBounds<Self>,

🔬This is a nightly-only experimental API. (clamp_to)
Restrict a value to a certain range. Read more
Source§

impl PartialEq for TimeOfDay

Source§

fn eq(&self, other: &TimeOfDay) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialOrd for TimeOfDay

Source§

fn partial_cmp(&self, other: &TimeOfDay) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl StructuralPartialEq for TimeOfDay

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.