pub struct TimeNative {
pub inner: NaiveTime,
}
Expand description
TimeLocal Rust type Postgres type(s) chrono::NaiveTime TIME
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 Clone for TimeNative
impl Clone for TimeNative
Source§fn clone(&self) -> TimeNative
fn clone(&self) -> TimeNative
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for TimeNative
impl Debug for TimeNative
Source§impl DerefMut for TimeNative
impl DerefMut for TimeNative
Source§impl<'de> Deserialize<'de> for TimeNative
impl<'de> Deserialize<'de> for TimeNative
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Source§impl Display for TimeNative
impl Display for TimeNative
Source§impl From<&NaiveTime> for TimeNative
impl From<&NaiveTime> for TimeNative
Source§impl From<NaiveTime> for TimeNative
impl From<NaiveTime> for TimeNative
Source§impl Hash for TimeNative
impl Hash for TimeNative
Source§impl Ord for TimeNative
impl Ord for TimeNative
Source§fn cmp(&self, other: &TimeNative) -> Ordering
fn cmp(&self, other: &TimeNative) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialEq for TimeNative
impl PartialEq for TimeNative
Source§impl PartialOrd for TimeNative
impl PartialOrd for TimeNative
Source§impl Serialize for TimeNative
impl Serialize for TimeNative
Source§impl Deref for TimeNative
impl Deref for TimeNative
impl Copy for TimeNative
impl Eq for TimeNative
impl StructuralPartialEq for TimeNative
Auto Trait Implementations§
impl Freeze for TimeNative
impl RefUnwindSafe for TimeNative
impl Send for TimeNative
impl Sync for TimeNative
impl Unpin for TimeNative
impl UnwindSafe for TimeNative
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