Keyboard shortcuts

Press or to navigate between chapters

Press ? to show this help

Press Esc to hide this help

WeekImpl

Fully qualified path: chrono::week::WeekImpl

pub impl WeekImpl of WeekTrait;

Impl functions

new

Create a new NaiveWeek

Fully qualified path: chrono::week::WeekImpl::new

fn new(date: Date, start: Weekday) -> Week

first_day

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);

Fully qualified path: chrono::week::WeekImpl::first_day

fn first_day(self: @Week) -> Date

checked_first_day

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;
};

Fully qualified path: chrono::week::WeekImpl::checked_first_day

fn checked_first_day(self: Week) -> Option<Date>

last_day

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);

Fully qualified path: chrono::week::WeekImpl::last_day

fn last_day(self: @Week) -> Date

checked_last_day

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;
};

Fully qualified path: chrono::week::WeekImpl::checked_last_day

fn checked_last_day(self: @Week) -> Option<Date>

days

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));

Fully qualified path: chrono::week::WeekImpl::days

fn days(self: @Week) -> RangeInclusive<Date>

checked_days

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;
    }
};

Fully qualified path: chrono::week::WeekImpl::checked_days

fn checked_days(self: @Week) -> Option<RangeInclusive<Date>>