Struct rbatis::TimeNative
source · [−]pub struct TimeNative {
pub inner: NaiveTime,
}
Expand description
TimeLocal Rust type Postgres type(s) chrono::NaiveTime TIME
Fields
inner: NaiveTime
Implementations
sourceimpl TimeNative
impl TimeNative
sourcepub fn now() -> TimeNative
pub fn now() -> TimeNative
Returns a [DateTime
] which corresponds to the current date and time.
Methods from Deref<Target = NaiveTime>
sourcepub fn overflowing_add_signed(&self, rhs: Duration) -> (NaiveTime, i64)
pub fn overflowing_add_signed(&self, rhs: Duration) -> (NaiveTime, i64)
Adds given Duration
to the current time,
and also returns the number of seconds
in the integral number of days ignored from the addition.
(We cannot return Duration
because it is subject to overflow or underflow.)
Example
use chrono::{Duration, NaiveTime};
let from_hms = NaiveTime::from_hms;
assert_eq!(from_hms(3, 4, 5).overflowing_add_signed(Duration::hours(11)),
(from_hms(14, 4, 5), 0));
assert_eq!(from_hms(3, 4, 5).overflowing_add_signed(Duration::hours(23)),
(from_hms(2, 4, 5), 86_400));
assert_eq!(from_hms(3, 4, 5).overflowing_add_signed(Duration::hours(-7)),
(from_hms(20, 4, 5), -86_400));
sourcepub fn overflowing_sub_signed(&self, rhs: Duration) -> (NaiveTime, i64)
pub fn overflowing_sub_signed(&self, rhs: Duration) -> (NaiveTime, i64)
Subtracts given Duration
from the current time,
and also returns the number of seconds
in the integral number of days ignored from the subtraction.
(We cannot return Duration
because it is subject to overflow or underflow.)
Example
use chrono::{Duration, NaiveTime};
let from_hms = NaiveTime::from_hms;
assert_eq!(from_hms(3, 4, 5).overflowing_sub_signed(Duration::hours(2)),
(from_hms(1, 4, 5), 0));
assert_eq!(from_hms(3, 4, 5).overflowing_sub_signed(Duration::hours(17)),
(from_hms(10, 4, 5), 86_400));
assert_eq!(from_hms(3, 4, 5).overflowing_sub_signed(Duration::hours(-22)),
(from_hms(1, 4, 5), -86_400));
sourcepub fn format_with_items<'a, I, B>(&self, items: I) -> DelayedFormat<I> where
I: Iterator<Item = B> + Clone,
B: Borrow<Item<'a>>,
pub fn format_with_items<'a, I, B>(&self, items: I) -> DelayedFormat<I> where
I: Iterator<Item = B> + Clone,
B: Borrow<Item<'a>>,
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::NaiveTime;
use chrono::format::strftime::StrftimeItems;
let fmt = StrftimeItems::new("%H:%M:%S");
let t = NaiveTime::from_hms(23, 56, 4);
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(&self, fmt: &'a str) -> DelayedFormat<StrftimeItems<'a>>
pub fn format(&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(23, 56, 4, 12_345_678);
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
sourceimpl Clone for TimeNative
impl Clone for TimeNative
sourcefn clone(&self) -> TimeNative
fn clone(&self) -> TimeNative
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl Debug for TimeNative
impl Debug for TimeNative
sourceimpl Deref for TimeNative
impl Deref for TimeNative
sourceimpl DerefMut for TimeNative
impl DerefMut for TimeNative
sourcefn deref_mut(&mut self) -> &mut <TimeNative as Deref>::Target
fn deref_mut(&mut self) -> &mut <TimeNative as Deref>::Target
Mutably dereferences the value.
sourceimpl<'de> Deserialize<'de> for TimeNative
impl<'de> Deserialize<'de> for TimeNative
sourcefn deserialize<D>(
deserializer: D
) -> Result<TimeNative, <D as Deserializer<'de>>::Error> where
D: Deserializer<'de>,
fn deserialize<D>(
deserializer: D
) -> Result<TimeNative, <D as Deserializer<'de>>::Error> where
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
sourceimpl Display for TimeNative
impl Display for TimeNative
sourceimpl<'_> From<&'_ NaiveTime> for TimeNative
impl<'_> From<&'_ NaiveTime> for TimeNative
sourcefn from(arg: &NaiveTime) -> TimeNative
fn from(arg: &NaiveTime) -> TimeNative
Converts to this type from the input type.
sourceimpl From<NaiveTime> for TimeNative
impl From<NaiveTime> for TimeNative
sourcefn from(arg: NaiveTime) -> TimeNative
fn from(arg: NaiveTime) -> TimeNative
Converts to this type from the input type.
sourceimpl Hash for TimeNative
impl Hash for TimeNative
sourceimpl Ord for TimeNative
impl Ord for TimeNative
sourceimpl PartialEq<TimeNative> for TimeNative
impl PartialEq<TimeNative> for TimeNative
sourcefn eq(&self, other: &TimeNative) -> bool
fn eq(&self, other: &TimeNative) -> bool
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
sourcefn ne(&self, other: &TimeNative) -> bool
fn ne(&self, other: &TimeNative) -> bool
This method tests for !=
.
sourceimpl PartialOrd<TimeNative> for TimeNative
impl PartialOrd<TimeNative> for TimeNative
sourcefn partial_cmp(&self, other: &TimeNative) -> Option<Ordering>
fn partial_cmp(&self, other: &TimeNative) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
sourceimpl Serialize for TimeNative
impl Serialize for TimeNative
sourcefn 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,
Serialize this value into the given Serde serializer. Read more
impl Copy for TimeNative
impl Eq for TimeNative
impl StructuralEq for TimeNative
impl StructuralPartialEq for TimeNative
Auto Trait Implementations
impl RefUnwindSafe for TimeNative
impl Send for TimeNative
impl Sync for TimeNative
impl Unpin for TimeNative
impl UnwindSafe for TimeNative
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<Q, K> Equivalent<K> for Q where
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Q where
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
sourcefn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to key
and return true
if they are equal.
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more