pub struct TimeUtc {
pub inner: NaiveTime,
}
Fields§
§inner: NaiveTime
Implementations§
Methods from Deref<Target = NaiveTime>§
pub const MIN: NaiveTime
Sourcepub fn overflowing_add_signed(&self, rhs: TimeDelta) -> (NaiveTime, i64)
pub fn overflowing_add_signed(&self, rhs: TimeDelta) -> (NaiveTime, i64)
Adds given TimeDelta
to the current time, and also returns the number of seconds
in the integral number of days ignored from the addition.
§Example
use chrono::{NaiveTime, TimeDelta};
let from_hms = |h, m, s| NaiveTime::from_hms_opt(h, m, s).unwrap();
assert_eq!(
from_hms(3, 4, 5).overflowing_add_signed(TimeDelta::try_hours(11).unwrap()),
(from_hms(14, 4, 5), 0)
);
assert_eq!(
from_hms(3, 4, 5).overflowing_add_signed(TimeDelta::try_hours(23).unwrap()),
(from_hms(2, 4, 5), 86_400)
);
assert_eq!(
from_hms(3, 4, 5).overflowing_add_signed(TimeDelta::try_hours(-7).unwrap()),
(from_hms(20, 4, 5), -86_400)
);
Sourcepub fn overflowing_sub_signed(&self, rhs: TimeDelta) -> (NaiveTime, i64)
pub fn overflowing_sub_signed(&self, rhs: TimeDelta) -> (NaiveTime, i64)
Subtracts given TimeDelta
from the current time, and also returns the number of seconds
in the integral number of days ignored from the subtraction.
§Example
use chrono::{NaiveTime, TimeDelta};
let from_hms = |h, m, s| NaiveTime::from_hms_opt(h, m, s).unwrap();
assert_eq!(
from_hms(3, 4, 5).overflowing_sub_signed(TimeDelta::try_hours(2).unwrap()),
(from_hms(1, 4, 5), 0)
);
assert_eq!(
from_hms(3, 4, 5).overflowing_sub_signed(TimeDelta::try_hours(17).unwrap()),
(from_hms(10, 4, 5), 86_400)
);
assert_eq!(
from_hms(3, 4, 5).overflowing_sub_signed(TimeDelta::try_hours(-22).unwrap()),
(from_hms(1, 4, 5), -86_400)
);
Sourcepub fn format_with_items<'a, I, B>(&self, items: I) -> DelayedFormat<I>
pub fn format_with_items<'a, I, B>(&self, items: I) -> DelayedFormat<I>
Formats the time with the specified formatting items.
Otherwise it is the same as the ordinary format
method.
The Iterator
of items should be Clone
able,
since the resulting DelayedFormat
value may be formatted multiple times.
§Example
use chrono::format::strftime::StrftimeItems;
use chrono::NaiveTime;
let fmt = StrftimeItems::new("%H:%M:%S");
let t = NaiveTime::from_hms_opt(23, 56, 4).unwrap();
assert_eq!(t.format_with_items(fmt.clone()).to_string(), "23:56:04");
assert_eq!(t.format("%H:%M:%S").to_string(), "23:56:04");
The resulting DelayedFormat
can be formatted directly via the Display
trait.
assert_eq!(format!("{}", t.format_with_items(fmt)), "23:56:04");
Sourcepub fn format<'a>(&self, fmt: &'a str) -> DelayedFormat<StrftimeItems<'a>>
pub fn format<'a>(&self, fmt: &'a str) -> DelayedFormat<StrftimeItems<'a>>
Formats the time with the specified format string.
See the format::strftime
module
on the supported escape sequences.
This returns a DelayedFormat
,
which gets converted to a string only when actual formatting happens.
You may use the to_string
method to get a String
,
or just feed it into print!
and other formatting macros.
(In this way it avoids the redundant memory allocation.)
A wrong format string does not issue an error immediately.
Rather, converting or formatting the DelayedFormat
fails.
You are recommended to immediately use DelayedFormat
for this reason.
§Example
use chrono::NaiveTime;
let t = NaiveTime::from_hms_nano_opt(23, 56, 4, 12_345_678).unwrap();
assert_eq!(t.format("%H:%M:%S").to_string(), "23:56:04");
assert_eq!(t.format("%H:%M:%S%.6f").to_string(), "23:56:04.012345");
assert_eq!(t.format("%-I:%M %p").to_string(), "11:56 PM");
The resulting DelayedFormat
can be formatted directly via the Display
trait.
assert_eq!(format!("{}", t.format("%H:%M:%S")), "23:56:04");
assert_eq!(format!("{}", t.format("%H:%M:%S%.6f")), "23:56:04.012345");
assert_eq!(format!("{}", t.format("%-I:%M %p")), "11:56 PM");
Trait Implementations§
Source§impl<'de> Deserialize<'de> for TimeUtc
impl<'de> Deserialize<'de> for TimeUtc
Source§fn deserialize<D>(
deserializer: D,
) -> Result<TimeUtc, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>(
deserializer: D,
) -> Result<TimeUtc, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
Source§impl Ord for TimeUtc
impl Ord for TimeUtc
Source§impl PartialOrd for TimeUtc
impl PartialOrd for TimeUtc
Source§impl Serialize for TimeUtc
impl Serialize for TimeUtc
Source§fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
impl Copy for TimeUtc
impl Eq for TimeUtc
impl StructuralPartialEq for TimeUtc
Auto Trait Implementations§
impl Freeze for TimeUtc
impl RefUnwindSafe for TimeUtc
impl Send for TimeUtc
impl Sync for TimeUtc
impl Unpin for TimeUtc
impl UnwindSafe for TimeUtc
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CallHasher for T
impl<T> CallHasher for T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more