Struct NaiveWeek

struct NaiveWeek { ... }

A week represented by a NaiveDate and a Weekday which is the first day of the week.

Implementations

impl NaiveWeek

const fn first_day(self: &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);
const fn checked_first_day(self: &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;
};
const fn last_day(self: &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);
const fn checked_last_day(self: &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;
};
const fn days(self: &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));
const fn checked_days(self: &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;
    }
};

impl Clone for NaiveWeek

fn clone(self: &Self) -> NaiveWeek

impl Copy for NaiveWeek

impl Debug for NaiveWeek

fn fmt(self: &Self, f: &mut $crate::fmt::Formatter<'_>) -> $crate::fmt::Result

impl Eq for NaiveWeek

impl Freeze for NaiveWeek

impl Hash for NaiveWeek

fn hash<__H: $crate::hash::Hasher>(self: &Self, state: &mut __H)

impl PartialEq for NaiveWeek

fn eq(self: &Self, other: &NaiveWeek) -> bool

impl RefUnwindSafe for NaiveWeek

impl Send for NaiveWeek

impl StructuralPartialEq for NaiveWeek

impl Sync for NaiveWeek

impl Unpin for NaiveWeek

impl UnwindSafe for NaiveWeek

impl<T> Any for NaiveWeek

fn type_id(self: &Self) -> TypeId

impl<T> Borrow for NaiveWeek

fn borrow(self: &Self) -> &T

impl<T> BorrowMut for NaiveWeek

fn borrow_mut(self: &mut Self) -> &mut T

impl<T> CloneToUninit for NaiveWeek

unsafe fn clone_to_uninit(self: &Self, dest: *mut u8)

impl<T> From for NaiveWeek

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> ToOwned for NaiveWeek

fn to_owned(self: &Self) -> T
fn clone_into(self: &Self, target: &mut T)

impl<T, U> Into for NaiveWeek

fn into(self: Self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

impl<T, U> TryFrom for NaiveWeek

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

impl<T, U> TryInto for NaiveWeek

fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>