#[non_exhaustive]pub struct WeekCalculator {
pub first_weekday: IsoWeekday,
pub min_week_days: u8,
}
Expand description
Calculator for week-of-month and week-of-year based on locale-specific configurations.
Fields (Non-exhaustive)
This struct is marked as non-exhaustive
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.
Implementations
sourceimpl WeekCalculator
impl WeekCalculator
sourcepub fn try_new_unstable<P>(
provider: &P,
locale: &DataLocale
) -> Result<WeekCalculator, CalendarError> where
P: DataProvider<WeekDataV1Marker>,
pub fn try_new_unstable<P>(
provider: &P,
locale: &DataLocale
) -> Result<WeekCalculator, CalendarError> where
P: DataProvider<WeekDataV1Marker>,
Creates a new WeekCalculator
from locale data.
sourcepub fn try_new_with_any_provider(
provider: &impl AnyProvider,
locale: &DataLocale
) -> Result<WeekCalculator, CalendarError>
pub fn try_new_with_any_provider(
provider: &impl AnyProvider,
locale: &DataLocale
) -> Result<WeekCalculator, CalendarError>
Creates a new instance using an AnyProvider
.
For details on the behavior of this function, see: Self::try_new_unstable
sourcepub fn try_new_with_buffer_provider(
provider: &impl BufferProvider,
locale: &DataLocale
) -> Result<WeekCalculator, CalendarError>
pub fn try_new_with_buffer_provider(
provider: &impl BufferProvider,
locale: &DataLocale
) -> Result<WeekCalculator, CalendarError>
✨ Enabled with the "serde"
feature.
Creates a new instance using a BufferProvider
.
For details on the behavior of this function, see: Self::try_new_unstable
sourcepub fn week_of_month(
&self,
day_of_month: DayOfMonth,
iso_weekday: IsoWeekday
) -> WeekOfMonth
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_unstable(
&icu_testdata::unstable(),
&icu_locid::locale!("en-GB").into(),
)
.expect("Data exists");
// Wednesday the 10th is in week 2:
assert_eq!(
WeekOfMonth(2),
week_calculator.week_of_month(DayOfMonth(10), IsoWeekday::Wednesday)
);
sourcepub fn week_of_year(
&self,
day_of_year_info: DayOfYearInfo,
iso_weekday: IsoWeekday
) -> Result<WeekOf, CalendarError>
pub fn week_of_year(
&self,
day_of_year_info: DayOfYearInfo,
iso_weekday: IsoWeekday
) -> Result<WeekOf, CalendarError>
Returns the week of year according to the weekday and DayOfYearInfo
.
Examples
use icu_calendar::types::{DayOfMonth, IsoWeekday};
use icu_calendar::week::{RelativeUnit, WeekCalculator, WeekOf};
use icu_calendar::Date;
let week_calculator = WeekCalculator::try_new_unstable(
&icu_testdata::unstable(),
&icu_locid::locale!("en-GB").into(),
)
.expect("Data exists");
let iso_date = Date::try_new_iso_date(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)
.unwrap()
);
Trait Implementations
sourceimpl Clone for WeekCalculator
impl Clone for WeekCalculator
sourcefn clone(&self) -> WeekCalculator
fn clone(&self) -> WeekCalculator
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl Debug for WeekCalculator
impl Debug for WeekCalculator
sourceimpl Default for WeekCalculator
impl Default for WeekCalculator
sourcefn default() -> WeekCalculator
fn default() -> WeekCalculator
Returns the “default value” for a type. Read more
sourceimpl<'_> From<&'_ WeekDataV1> for WeekCalculator
impl<'_> From<&'_ WeekDataV1> for WeekCalculator
sourcefn from(other: &WeekDataV1) -> WeekCalculator
fn from(other: &WeekDataV1) -> WeekCalculator
Converts to this type from the input type.
sourceimpl From<WeekDataV1> for WeekCalculator
impl From<WeekDataV1> for WeekCalculator
sourcefn from(other: WeekDataV1) -> WeekCalculator
fn from(other: WeekDataV1) -> WeekCalculator
Converts to this type from the input type.
impl Copy for WeekCalculator
Auto Trait Implementations
impl RefUnwindSafe for WeekCalculator
impl Send for WeekCalculator
impl Sync for WeekCalculator
impl Unpin for WeekCalculator
impl UnwindSafe for WeekCalculator
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<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