pub struct CustomWeek { /* private fields */ }
Expand description
Custom week implementation.
PartialOrd and Ord are not implemented, because we do not have a natural ordering for weeks with different specifications.
Week start could be recalculated from year, week and specification: it is only stored by convenience for succ
, pred
, and contains
functions.
Implementations§
Source§impl CustomWeek
impl CustomWeek
pub fn year(&self) -> i32
pub fn week(&self) -> u32
pub fn week_start(&self) -> NaiveDate
pub fn specification(&self) -> WeekSpecification
Sourcepub fn succ(&self) -> CustomWeek
pub fn succ(&self) -> CustomWeek
The next week according to the same specification.
Sourcepub fn pred(&self) -> CustomWeek
pub fn pred(&self) -> CustomWeek
The previous week according to the same specification.
Sourcepub fn contains(&self, date: NaiveDate) -> bool
pub fn contains(&self, date: NaiveDate) -> bool
Verify if the given date is in the current week.
Sourcepub fn format(&self, fmt: &str) -> String
pub fn format(&self, fmt: &str) -> String
Very naive week formatting
Formatters are inspired by chrono::format::strftime
.
Spec. | Example | Description |
---|---|---|
DATE SPECIFIERS: | ||
%Y | 2001 | The week year, zero-padded to 4 digits. |
%C | 20 | The week year divided by 100, zero-padded to 2 digits. |
%y | 01 | The week year modulo 100, zero-padded to 2 digits. |
%W | 27 | Week number, zero-padded to 2 digits. |
—–– | ––––– | –––––––––––––––––––––––––––– |
use chrono::NaiveDate;
use chrono_ext::{WeekSpecification, CustomWeek};
let french_theater_week: WeekSpecification = WeekSpecification::french_theater_week();
let french_theater_dow_2016_53 = NaiveDate::from_ymd(2017, 1, 3);
let week = french_theater_week.week_from_date(french_theater_dow_2016_53);
assert_eq!("Year 2016", week.format("Year %Y"));
assert_eq!("Year 2016", week.format("Year %C%y"));
assert_eq!("Week 53", week.format("Week %W"));
assert_eq!("S1653", week.format("S%y%W"));
Trait Implementations§
Source§impl Clone for CustomWeek
impl Clone for CustomWeek
Source§fn clone(&self) -> CustomWeek
fn clone(&self) -> CustomWeek
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Debug for CustomWeek
impl Debug for CustomWeek
Source§impl PartialEq for CustomWeek
impl PartialEq for CustomWeek
impl Eq for CustomWeek
impl StructuralPartialEq for CustomWeek
Auto Trait Implementations§
impl Freeze for CustomWeek
impl RefUnwindSafe for CustomWeek
impl Send for CustomWeek
impl Sync for CustomWeek
impl Unpin for CustomWeek
impl UnwindSafe for CustomWeek
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more