Struct icu_calendar::week::WeekCalculator

source ·
#[non_exhaustive]
pub struct WeekCalculator { pub first_weekday: IsoWeekday, pub min_week_days: u8, pub weekend: Option<WeekdaySet>, }
Expand description

Calculator for week-of-month and week-of-year based on locale-specific configurations.

Note that things get subtly tricky for weeks that straddle the boundary between two years: different locales may consider them as belonging to the preceding or succeeding year based on where exactly the week gets split. While this struct can be populated by values supplied by the programmer, we do recommend using one of the constructors to get locale data.

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§first_weekday: IsoWeekday

The first day of a week.

§min_week_days: u8

For a given week, the minimum number of that week’s days present in a given month or year for the week to be considered part of that month or year.

§weekend: Option<WeekdaySet>

The set of weekend days, if available

Implementations§

source§

impl WeekCalculator

source

pub fn try_new(locale: &DataLocale) -> Result<Self, DataError>

Creates a new WeekCalculator from compiled data.

Enabled with the compiled_data Cargo feature.

📚 Help choosing a constructor

source

pub fn try_new_with_any_provider( provider: &(impl AnyProvider + ?Sized), locale: &DataLocale, ) -> Result<Self, DataError>

A version of [Self :: try_new] that uses custom data provided by an AnyProvider.

📚 Help choosing a constructor

source

pub fn try_new_with_buffer_provider( provider: &(impl BufferProvider + ?Sized), locale: &DataLocale, ) -> Result<Self, DataError>

A version of [Self :: try_new] that uses custom data provided by a BufferProvider.

Enabled with the serde feature.

📚 Help choosing a constructor

source

pub fn try_new_unstable<P>( provider: &P, locale: &DataLocale, ) -> Result<Self, DataError>
where P: DataProvider<WeekDataV2Marker> + ?Sized,

A version of Self::try_new that uses custom data provided by a DataProvider.

📚 Help choosing a constructor

⚠️ The bounds on provider may change over time, including in SemVer minor releases.
source

pub fn week_of_month( &self, day_of_month: DayOfMonth, iso_weekday: IsoWeekday, ) -> WeekOfMonth

Returns the week of month according to a calendar with min_week_days = 1.

This is different from what the UTS35 spec describes 1 but the latter is missing a month of week-of-month field so following the spec would result in inconsistencies (e.g. in the ISO calendar 2021-01-01 is the last week of December but ‘MMMMW’ would have it formatted as ‘week 5 of January’).

§Examples
use icu::calendar::types::{DayOfMonth, IsoWeekday, WeekOfMonth};
use icu::calendar::week::WeekCalculator;

let week_calculator =
    WeekCalculator::try_new(&icu::locale::locale!("und-GB").into())
        .expect("locale should be present");

// Wednesday the 10th is in week 2:
assert_eq!(
    WeekOfMonth(2),
    week_calculator.week_of_month(DayOfMonth(10), IsoWeekday::Wednesday)
);
source

pub fn week_of_year( &self, day_of_year_info: DayOfYearInfo, iso_weekday: IsoWeekday, ) -> WeekOf

Returns the week of year according to the weekday and DayOfYearInfo.

§Examples
use icu::calendar::types::IsoWeekday;
use icu::calendar::week::{RelativeUnit, WeekCalculator, WeekOf};
use icu::calendar::Date;

let week_calculator =
    WeekCalculator::try_new(&icu::locale::locale!("und-GB").into())
        .expect("locale should be present");

let iso_date = Date::try_new_iso(2022, 8, 26).unwrap();

// Friday August 26 is in week 34 of year 2022:
assert_eq!(
    WeekOf {
        unit: RelativeUnit::Current,
        week: 34
    },
    week_calculator
        .week_of_year(iso_date.day_of_year_info(), IsoWeekday::Friday)
);
source

pub fn weekend(&self) -> impl Iterator<Item = IsoWeekday>

Weekdays that are part of the ‘weekend’, for calendar purposes. Days may not be contiguous, and order is based off the first weekday.

Trait Implementations§

source§

impl Clone for WeekCalculator

source§

fn clone(&self) -> WeekCalculator

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for WeekCalculator

source§

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

Formats the value using the given formatter. Read more
source§

impl Default for WeekCalculator

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl Copy for WeekCalculator

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

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

source§

impl<T> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
source§

impl<T> ToOwned for T
where T: Clone,

source§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

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

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

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

Performs the conversion.
§

impl<T> ErasedDestructor for T
where T: 'static,

§

impl<T> MaybeSendSync for T
where T: Send + Sync,