pub struct NaiveWeek { /* private fields */ }
Expand description
Implementations§
Source§impl NaiveWeek
impl NaiveWeek
Sourcepub const fn first_day(&self) -> NaiveDate
pub const fn first_day(&self) -> NaiveDate
Returns a date representing the first day of the week.
§Panics
Panics if the first day of the week happens to fall just out of range of NaiveDate
(more than ca. 262,000 years away from common era).
§Examples
use chrono::{NaiveDate, Weekday};
let date = NaiveDate::from_ymd_opt(2022, 4, 18).unwrap();
let week = date.week(Weekday::Mon);
assert!(week.first_day() <= date);
Sourcepub const fn checked_first_day(&self) -> Option<NaiveDate>
pub const fn checked_first_day(&self) -> Option<NaiveDate>
Returns a date representing the first day of the week or
None
if the date is out of NaiveDate
’s range
(more than ca. 262,000 years away from common era).
§Examples
use chrono::{NaiveDate, Weekday};
let date = NaiveDate::MIN;
let week = date.week(Weekday::Mon);
if let Some(first_day) = week.checked_first_day() {
assert!(first_day == date);
} else {
// error handling code
return;
};
Sourcepub const fn last_day(&self) -> NaiveDate
pub const fn last_day(&self) -> NaiveDate
Returns a date representing the last day of the week.
§Panics
Panics if the last day of the week happens to fall just out of range of NaiveDate
(more than ca. 262,000 years away from common era).
§Examples
use chrono::{NaiveDate, Weekday};
let date = NaiveDate::from_ymd_opt(2022, 4, 18).unwrap();
let week = date.week(Weekday::Mon);
assert!(week.last_day() >= date);
Sourcepub const fn checked_last_day(&self) -> Option<NaiveDate>
pub const fn checked_last_day(&self) -> Option<NaiveDate>
Returns a date representing the last day of the week or
None
if the date is out of NaiveDate
’s range
(more than ca. 262,000 years away from common era).
§Examples
use chrono::{NaiveDate, Weekday};
let date = NaiveDate::MAX;
let week = date.week(Weekday::Mon);
if let Some(last_day) = week.checked_last_day() {
assert!(last_day == date);
} else {
// error handling code
return;
};
Sourcepub const fn days(&self) -> RangeInclusive<NaiveDate> ⓘ
pub const fn days(&self) -> RangeInclusive<NaiveDate> ⓘ
Returns a RangeInclusive<T>
representing the whole week bounded by
first_day and last_day functions.
§Panics
Panics if the either the first or last day of the week happens to fall just out of range of
NaiveDate
(more than ca. 262,000 years away from common era).
§Examples
use chrono::{NaiveDate, Weekday};
let date = NaiveDate::from_ymd_opt(2022, 4, 18).unwrap();
let week = date.week(Weekday::Mon);
let days = week.days();
assert!(days.contains(&date));
Sourcepub const fn checked_days(&self) -> Option<RangeInclusive<NaiveDate>>
pub const fn checked_days(&self) -> Option<RangeInclusive<NaiveDate>>
Returns an Option<RangeInclusive<T>>
representing the whole week bounded by
checked_first_day and
checked_last_day functions.
Returns None
if either of the boundaries are out of NaiveDate
’s range
(more than ca. 262,000 years away from common era).
§Examples
use chrono::{NaiveDate, Weekday};
let date = NaiveDate::MAX;
let week = date.week(Weekday::Mon);
let _days = match week.checked_days() {
Some(d) => d,
None => {
// error handling code
return;
}
};
Trait Implementations§
impl Copy for NaiveWeek
impl Eq for NaiveWeek
impl StructuralPartialEq for NaiveWeek
Auto Trait Implementations§
impl Freeze for NaiveWeek
impl RefUnwindSafe for NaiveWeek
impl Send for NaiveWeek
impl Sync for NaiveWeek
impl Unpin for NaiveWeek
impl UnwindSafe for NaiveWeek
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
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