pub struct DateUtc {
pub inner: NaiveDate,
}
Fields
inner: NaiveDate
Implementations
Methods from Deref<Target = NaiveDate>
sourcepub fn and_time(&self, time: NaiveTime) -> NaiveDateTime
pub fn and_time(&self, time: NaiveTime) -> NaiveDateTime
Makes a new NaiveDateTime
from the current date and given NaiveTime
.
Example
use chrono::{NaiveDate, NaiveTime, NaiveDateTime};
let d = NaiveDate::from_ymd(2015, 6, 3);
let t = NaiveTime::from_hms_milli(12, 34, 56, 789);
let dt: NaiveDateTime = d.and_time(t);
assert_eq!(dt.date(), d);
assert_eq!(dt.time(), t);
sourcepub fn and_hms(&self, hour: u32, min: u32, sec: u32) -> NaiveDateTime
pub fn and_hms(&self, hour: u32, min: u32, sec: u32) -> NaiveDateTime
Makes a new NaiveDateTime
from the current date, hour, minute and second.
No leap second is allowed here;
use NaiveDate::and_hms_*
methods with a subsecond parameter instead.
Panics on invalid hour, minute and/or second.
Example
use chrono::{NaiveDate, NaiveDateTime, Datelike, Timelike, Weekday};
let d = NaiveDate::from_ymd(2015, 6, 3);
let dt: NaiveDateTime = d.and_hms(12, 34, 56);
assert_eq!(dt.year(), 2015);
assert_eq!(dt.weekday(), Weekday::Wed);
assert_eq!(dt.second(), 56);
sourcepub fn and_hms_opt(
&self,
hour: u32,
min: u32,
sec: u32
) -> Option<NaiveDateTime>
pub fn and_hms_opt(
&self,
hour: u32,
min: u32,
sec: u32
) -> Option<NaiveDateTime>
Makes a new NaiveDateTime
from the current date, hour, minute and second.
No leap second is allowed here;
use NaiveDate::and_hms_*_opt
methods with a subsecond parameter instead.
Returns None
on invalid hour, minute and/or second.
Example
use chrono::NaiveDate;
let d = NaiveDate::from_ymd(2015, 6, 3);
assert!(d.and_hms_opt(12, 34, 56).is_some());
assert!(d.and_hms_opt(12, 34, 60).is_none()); // use `and_hms_milli_opt` instead
assert!(d.and_hms_opt(12, 60, 56).is_none());
assert!(d.and_hms_opt(24, 34, 56).is_none());
sourcepub fn and_hms_milli(
&self,
hour: u32,
min: u32,
sec: u32,
milli: u32
) -> NaiveDateTime
pub fn and_hms_milli(
&self,
hour: u32,
min: u32,
sec: u32,
milli: u32
) -> NaiveDateTime
Makes a new NaiveDateTime
from the current date, hour, minute, second and millisecond.
The millisecond part can exceed 1,000 in order to represent the leap second.
Panics on invalid hour, minute, second and/or millisecond.
Example
use chrono::{NaiveDate, NaiveDateTime, Datelike, Timelike, Weekday};
let d = NaiveDate::from_ymd(2015, 6, 3);
let dt: NaiveDateTime = d.and_hms_milli(12, 34, 56, 789);
assert_eq!(dt.year(), 2015);
assert_eq!(dt.weekday(), Weekday::Wed);
assert_eq!(dt.second(), 56);
assert_eq!(dt.nanosecond(), 789_000_000);
sourcepub fn and_hms_milli_opt(
&self,
hour: u32,
min: u32,
sec: u32,
milli: u32
) -> Option<NaiveDateTime>
pub fn and_hms_milli_opt(
&self,
hour: u32,
min: u32,
sec: u32,
milli: u32
) -> Option<NaiveDateTime>
Makes a new NaiveDateTime
from the current date, hour, minute, second and millisecond.
The millisecond part can exceed 1,000 in order to represent the leap second.
Returns None
on invalid hour, minute, second and/or millisecond.
Example
use chrono::NaiveDate;
let d = NaiveDate::from_ymd(2015, 6, 3);
assert!(d.and_hms_milli_opt(12, 34, 56, 789).is_some());
assert!(d.and_hms_milli_opt(12, 34, 59, 1_789).is_some()); // leap second
assert!(d.and_hms_milli_opt(12, 34, 59, 2_789).is_none());
assert!(d.and_hms_milli_opt(12, 34, 60, 789).is_none());
assert!(d.and_hms_milli_opt(12, 60, 56, 789).is_none());
assert!(d.and_hms_milli_opt(24, 34, 56, 789).is_none());
sourcepub fn and_hms_micro(
&self,
hour: u32,
min: u32,
sec: u32,
micro: u32
) -> NaiveDateTime
pub fn and_hms_micro(
&self,
hour: u32,
min: u32,
sec: u32,
micro: u32
) -> NaiveDateTime
Makes a new NaiveDateTime
from the current date, hour, minute, second and microsecond.
The microsecond part can exceed 1,000,000 in order to represent the leap second.
Panics on invalid hour, minute, second and/or microsecond.
Example
use chrono::{NaiveDate, NaiveDateTime, Datelike, Timelike, Weekday};
let d = NaiveDate::from_ymd(2015, 6, 3);
let dt: NaiveDateTime = d.and_hms_micro(12, 34, 56, 789_012);
assert_eq!(dt.year(), 2015);
assert_eq!(dt.weekday(), Weekday::Wed);
assert_eq!(dt.second(), 56);
assert_eq!(dt.nanosecond(), 789_012_000);
sourcepub fn and_hms_micro_opt(
&self,
hour: u32,
min: u32,
sec: u32,
micro: u32
) -> Option<NaiveDateTime>
pub fn and_hms_micro_opt(
&self,
hour: u32,
min: u32,
sec: u32,
micro: u32
) -> Option<NaiveDateTime>
Makes a new NaiveDateTime
from the current date, hour, minute, second and microsecond.
The microsecond part can exceed 1,000,000 in order to represent the leap second.
Returns None
on invalid hour, minute, second and/or microsecond.
Example
use chrono::NaiveDate;
let d = NaiveDate::from_ymd(2015, 6, 3);
assert!(d.and_hms_micro_opt(12, 34, 56, 789_012).is_some());
assert!(d.and_hms_micro_opt(12, 34, 59, 1_789_012).is_some()); // leap second
assert!(d.and_hms_micro_opt(12, 34, 59, 2_789_012).is_none());
assert!(d.and_hms_micro_opt(12, 34, 60, 789_012).is_none());
assert!(d.and_hms_micro_opt(12, 60, 56, 789_012).is_none());
assert!(d.and_hms_micro_opt(24, 34, 56, 789_012).is_none());
sourcepub fn and_hms_nano(
&self,
hour: u32,
min: u32,
sec: u32,
nano: u32
) -> NaiveDateTime
pub fn and_hms_nano(
&self,
hour: u32,
min: u32,
sec: u32,
nano: u32
) -> NaiveDateTime
Makes a new NaiveDateTime
from the current date, hour, minute, second and nanosecond.
The nanosecond part can exceed 1,000,000,000 in order to represent the leap second.
Panics on invalid hour, minute, second and/or nanosecond.
Example
use chrono::{NaiveDate, NaiveDateTime, Datelike, Timelike, Weekday};
let d = NaiveDate::from_ymd(2015, 6, 3);
let dt: NaiveDateTime = d.and_hms_nano(12, 34, 56, 789_012_345);
assert_eq!(dt.year(), 2015);
assert_eq!(dt.weekday(), Weekday::Wed);
assert_eq!(dt.second(), 56);
assert_eq!(dt.nanosecond(), 789_012_345);
sourcepub fn and_hms_nano_opt(
&self,
hour: u32,
min: u32,
sec: u32,
nano: u32
) -> Option<NaiveDateTime>
pub fn and_hms_nano_opt(
&self,
hour: u32,
min: u32,
sec: u32,
nano: u32
) -> Option<NaiveDateTime>
Makes a new NaiveDateTime
from the current date, hour, minute, second and nanosecond.
The nanosecond part can exceed 1,000,000,000 in order to represent the leap second.
Returns None
on invalid hour, minute, second and/or nanosecond.
Example
use chrono::NaiveDate;
let d = NaiveDate::from_ymd(2015, 6, 3);
assert!(d.and_hms_nano_opt(12, 34, 56, 789_012_345).is_some());
assert!(d.and_hms_nano_opt(12, 34, 59, 1_789_012_345).is_some()); // leap second
assert!(d.and_hms_nano_opt(12, 34, 59, 2_789_012_345).is_none());
assert!(d.and_hms_nano_opt(12, 34, 60, 789_012_345).is_none());
assert!(d.and_hms_nano_opt(12, 60, 56, 789_012_345).is_none());
assert!(d.and_hms_nano_opt(24, 34, 56, 789_012_345).is_none());
sourcepub fn succ(&self) -> NaiveDate
pub fn succ(&self) -> NaiveDate
Makes a new NaiveDate
for the next calendar date.
Panics when self
is the last representable date.
Example
use chrono::NaiveDate;
assert_eq!(NaiveDate::from_ymd(2015, 6, 3).succ(), NaiveDate::from_ymd(2015, 6, 4));
assert_eq!(NaiveDate::from_ymd(2015, 6, 30).succ(), NaiveDate::from_ymd(2015, 7, 1));
assert_eq!(NaiveDate::from_ymd(2015, 12, 31).succ(), NaiveDate::from_ymd(2016, 1, 1));
sourcepub fn succ_opt(&self) -> Option<NaiveDate>
pub fn succ_opt(&self) -> Option<NaiveDate>
Makes a new NaiveDate
for the next calendar date.
Returns None
when self
is the last representable date.
Example
use chrono::NaiveDate;
use chrono::naive::MAX_DATE;
assert_eq!(NaiveDate::from_ymd(2015, 6, 3).succ_opt(),
Some(NaiveDate::from_ymd(2015, 6, 4)));
assert_eq!(MAX_DATE.succ_opt(), None);
sourcepub fn pred(&self) -> NaiveDate
pub fn pred(&self) -> NaiveDate
Makes a new NaiveDate
for the previous calendar date.
Panics when self
is the first representable date.
Example
use chrono::NaiveDate;
assert_eq!(NaiveDate::from_ymd(2015, 6, 3).pred(), NaiveDate::from_ymd(2015, 6, 2));
assert_eq!(NaiveDate::from_ymd(2015, 6, 1).pred(), NaiveDate::from_ymd(2015, 5, 31));
assert_eq!(NaiveDate::from_ymd(2015, 1, 1).pred(), NaiveDate::from_ymd(2014, 12, 31));
sourcepub fn pred_opt(&self) -> Option<NaiveDate>
pub fn pred_opt(&self) -> Option<NaiveDate>
Makes a new NaiveDate
for the previous calendar date.
Returns None
when self
is the first representable date.
Example
use chrono::NaiveDate;
use chrono::naive::MIN_DATE;
assert_eq!(NaiveDate::from_ymd(2015, 6, 3).pred_opt(),
Some(NaiveDate::from_ymd(2015, 6, 2)));
assert_eq!(MIN_DATE.pred_opt(), None);
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 date 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::NaiveDate;
use chrono::format::strftime::StrftimeItems;
let fmt = StrftimeItems::new("%Y-%m-%d");
let d = NaiveDate::from_ymd(2015, 9, 5);
assert_eq!(d.format_with_items(fmt.clone()).to_string(), "2015-09-05");
assert_eq!(d.format("%Y-%m-%d").to_string(), "2015-09-05");
The resulting DelayedFormat
can be formatted directly via the Display
trait.
assert_eq!(format!("{}", d.format_with_items(fmt)), "2015-09-05");
sourcepub fn format(&self, fmt: &'a str) -> DelayedFormat<StrftimeItems<'a>>
pub fn format(&self, fmt: &'a str) -> DelayedFormat<StrftimeItems<'a>>
Formats the date 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::NaiveDate;
let d = NaiveDate::from_ymd(2015, 9, 5);
assert_eq!(d.format("%Y-%m-%d").to_string(), "2015-09-05");
assert_eq!(d.format("%A, %-d %B, %C%y").to_string(), "Saturday, 5 September, 2015");
The resulting DelayedFormat
can be formatted directly via the Display
trait.
assert_eq!(format!("{}", d.format("%Y-%m-%d")), "2015-09-05");
assert_eq!(format!("{}", d.format("%A, %-d %B, %C%y")), "Saturday, 5 September, 2015");
sourcepub fn iter_days(&self) -> NaiveDateDaysIterator
pub fn iter_days(&self) -> NaiveDateDaysIterator
Returns an iterator that steps by days until the last representable date.
Example
let expected = [
NaiveDate::from_ymd(2016, 2, 27),
NaiveDate::from_ymd(2016, 2, 28),
NaiveDate::from_ymd(2016, 2, 29),
NaiveDate::from_ymd(2016, 3, 1),
];
let mut count = 0;
for (idx, d) in NaiveDate::from_ymd(2016, 2, 27).iter_days().take(4).enumerate() {
assert_eq!(d, expected[idx]);
count += 1;
}
assert_eq!(count, 4);
sourcepub fn iter_weeks(&self) -> NaiveDateWeeksIterator
pub fn iter_weeks(&self) -> NaiveDateWeeksIterator
Returns an iterator that steps by weeks until the last representable date.
Example
let expected = [
NaiveDate::from_ymd(2016, 2, 27),
NaiveDate::from_ymd(2016, 3, 5),
NaiveDate::from_ymd(2016, 3, 12),
NaiveDate::from_ymd(2016, 3, 19),
];
let mut count = 0;
for (idx, d) in NaiveDate::from_ymd(2016, 2, 27).iter_weeks().take(4).enumerate() {
assert_eq!(d, expected[idx]);
count += 1;
}
assert_eq!(count, 4);
Trait Implementations
sourceimpl<'de> Deserialize<'de> for DateUtc
impl<'de> Deserialize<'de> for DateUtc
sourcefn deserialize<D>(
deserializer: D
) -> Result<DateUtc, <D as Deserializer<'de>>::Error> where
D: Deserializer<'de>,
fn deserialize<D>(
deserializer: D
) -> Result<DateUtc, <D as Deserializer<'de>>::Error> where
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
sourceimpl Ord for DateUtc
impl Ord for DateUtc
sourceimpl PartialOrd<DateUtc> for DateUtc
impl PartialOrd<DateUtc> for DateUtc
sourcefn partial_cmp(&self, other: &DateUtc) -> Option<Ordering>
fn partial_cmp(&self, other: &DateUtc) -> 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 DateUtc
impl Serialize for DateUtc
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 DateUtc
impl Eq for DateUtc
impl StructuralEq for DateUtc
impl StructuralPartialEq for DateUtc
Auto Trait Implementations
impl RefUnwindSafe for DateUtc
impl Send for DateUtc
impl Sync for DateUtc
impl Unpin for DateUtc
impl UnwindSafe for DateUtc
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