pub struct YearWeek { /* private fields */ }
Expand description

A week date consisting of a year and a week number.

Examples

use whatwg_datetime::{parse_week, YearWeek};

assert_eq!(parse_week("2011-W47"), YearWeek::new_opt(2011, 47));

Implementations§

source§

impl YearWeek

source

pub fn new_opt(year: i32, week: u32) -> Option<Self>

Creates a new YearWeek from a year and a week number.

This asserts that the year is greater than 0 and that the week number is in the valid range for the year. Specifically, the week number must be between 1 and the number of weeks in the year, inclusive.

The number of weeks in a year is described by the algorithm in [WHATWG HTML Standard § 2.3.5.8 Weeks][whatwg-html-weeks].

Examples
use whatwg_datetime::YearWeek;

assert!(YearWeek::new_opt(2004, 53).is_some());
assert!(YearWeek::new_opt(2011, 47).is_some());
assert!(YearWeek::new_opt(2011, 53).is_none()); // 2011 only has 52 weeks
assert!(YearWeek::new_opt(1952, 0).is_none()); // Week number must be at least 1
assert!(YearWeek::new_opt(0, 1).is_none()); // Year number must be greater than 0
source

pub const fn year(&self) -> i32

A year component. This is a number greater than 0.

Examples
use whatwg_datetime::YearWeek;

let year_week = YearWeek::new_opt(2004, 53).unwrap();
assert_eq!(year_week.year(), 2004);
source

pub const fn week(&self) -> u32

A week component. This is a number between 1 and the number of weeks in the year, inclusive.

Examples
use whatwg_datetime::YearWeek;

let year_week = YearWeek::new_opt(2004, 53).unwrap();
assert_eq!(year_week.week(), 53);

Trait Implementations§

source§

impl Clone for YearWeek

source§

fn clone(&self) -> YearWeek

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 YearWeek

source§

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

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

impl PartialEq<YearWeek> for YearWeek

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Copy for YearWeek

source§

impl Eq for YearWeek

source§

impl StructuralEq for YearWeek

source§

impl StructuralPartialEq for YearWeek

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. 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 Twhere 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> ToOwned for Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.