pub struct TimeOfDay(/* private fields */);Expand description
A time of day, nanosecond precision.
Implementations§
Source§impl TimeOfDay
impl TimeOfDay
Sourcepub const fn from_nanos_since_midnight(nanos: u64) -> Result<TimeOfDay>
pub const fn from_nanos_since_midnight(nanos: u64) -> Result<TimeOfDay>
Build from nanoseconds since midnight; validates the day bound.
Sourcepub fn from_hms(hour: u32, minute: u32, second: u32) -> Result<TimeOfDay>
pub fn from_hms(hour: u32, minute: u32, second: u32) -> Result<TimeOfDay>
Build from hour/minute/second.
Sourcepub fn from_hms_milli(
hour: u32,
minute: u32,
second: u32,
milli: u32,
) -> Result<TimeOfDay>
pub fn from_hms_milli( hour: u32, minute: u32, second: u32, milli: u32, ) -> Result<TimeOfDay>
Build from hour/minute/second/millisecond.
Sourcepub fn from_hms_micro(
hour: u32,
minute: u32,
second: u32,
micro: u32,
) -> Result<TimeOfDay>
pub fn from_hms_micro( hour: u32, minute: u32, second: u32, micro: u32, ) -> Result<TimeOfDay>
Build from hour/minute/second/microsecond.
Sourcepub fn from_hms_nano(
hour: u32,
minute: u32,
second: u32,
nano: u32,
) -> Result<TimeOfDay>
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?
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 const fn nanos_since_midnight(self) -> u64
pub const fn nanos_since_midnight(self) -> u64
Nanoseconds since midnight.
Sourcepub const fn num_seconds_from_midnight(self) -> u32
pub const fn num_seconds_from_midnight(self) -> u32
Whole seconds since midnight (chrono’s Timelike::num_seconds_from_midnight).
Sourcepub fn with_minute(self, minute: u32) -> Result<TimeOfDay>
pub fn with_minute(self, minute: u32) -> Result<TimeOfDay>
Replace the minute.
Sourcepub fn with_second(self, second: u32) -> Result<TimeOfDay>
pub fn with_second(self, second: u32) -> Result<TimeOfDay>
Replace the second.
Sourcepub fn with_nanosecond(self, nano: u32) -> Result<TimeOfDay>
pub fn with_nanosecond(self, nano: u32) -> Result<TimeOfDay>
Replace the nanosecond within the second.
Sourcepub const fn nanosecond(self) -> u32
pub const fn nanosecond(self) -> u32
Nanosecond within the second (0..1e9).
Sourcepub const fn millisecond(self) -> u32
pub const fn millisecond(self) -> u32
Millisecond within the second (0..1000).
Sourcepub const fn microsecond(self) -> u32
pub const fn microsecond(self) -> u32
Microsecond within the second (0..1e6).
Sourcepub fn checked_add(self, delta: Duration) -> Result<TimeOfDay>
pub fn checked_add(self, delta: Duration) -> Result<TimeOfDay>
Checked addition that must stay inside the day.
Sourcepub fn checked_sub(self, delta: Duration) -> Result<TimeOfDay>
pub fn checked_sub(self, delta: Duration) -> Result<TimeOfDay>
Checked subtraction that must stay inside the day.
Sourcepub fn checked_add_signed(self, rhs: Duration) -> Result<TimeOfDay>
pub fn checked_add_signed(self, rhs: Duration) -> Result<TimeOfDay>
Alias for TimeOfDay::checked_add (chrono-compatible name).
Sourcepub fn checked_sub_signed(self, rhs: Duration) -> Result<TimeOfDay>
pub fn checked_sub_signed(self, rhs: Duration) -> Result<TimeOfDay>
Alias for TimeOfDay::checked_sub (chrono-compatible name).
Sourcepub fn overflowing_add(self, delta: Duration) -> (TimeOfDay, i64)
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.
Sourcepub fn signed_duration_since(self, earlier: TimeOfDay) -> Duration
pub fn signed_duration_since(self, earlier: TimeOfDay) -> Duration
Signed difference self - earlier (chrono-compatible name).
Sourcepub fn duration_since(self, earlier: TimeOfDay) -> Duration
pub fn duration_since(self, earlier: TimeOfDay) -> Duration
Signed difference self - earlier.
Sourcepub fn to_iso(self) -> String
Available on crate feature alloc only.
pub fn to_iso(self) -> String
alloc only.Strict ISO 8601 rendering (HH:MM:SS[.fffffffff]).
This method allocates. The allocator-free equivalent is
TimeOfDay::write_iso.
Sourcepub fn write_iso(self, out: &mut [u8]) -> Result<usize>
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.
Sourcepub fn from_iso(s: &str) -> Result<TimeOfDay>
pub fn from_iso(s: &str) -> Result<TimeOfDay>
Parse a strict ISO 8601 time of day (HH:MM:SS, optional fraction).
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("%H:%M:%S%.f").
The %-directive set is documented on crate::Ticks::format.
This method allocates. The allocator-free equivalent is
TimeOfDay::write_format.
Trait Implementations§
impl Copy for TimeOfDay
impl Eq for TimeOfDay
Source§impl<'de> NsonDeserialize<'de> for TimeOfDay
Available on crate feature serde only.
impl<'de> NsonDeserialize<'de> for TimeOfDay
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 TimeOfDay
Available on crate feature serde only.
impl NsonSchema for TimeOfDay
serde only.Source§const SCHEMA: TypeSchema = TypeSchema::Str
const SCHEMA: TypeSchema = TypeSchema::Str
Source§impl NsonSerialize for TimeOfDay
Available on crate feature serde only.
impl NsonSerialize for TimeOfDay
serde only.