Skip to content

Commit

Permalink
Add example to Weekday::num_days_from_monday
Browse files Browse the repository at this point in the history
  • Loading branch information
pitdicker committed Aug 3, 2023
1 parent 2e2374f commit b63601d
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/weekday.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,19 @@ impl Weekday {
/// `w`: | `Mon` | `Tue` | `Wed` | `Thu` | `Fri` | `Sat` | `Sun`
/// --------------------------- | ----- | ----- | ----- | ----- | ----- | ----- | -----
/// `w.num_days_from_monday()`: | 0 | 1 | 2 | 3 | 4 | 5 | 6
///
/// # Example
///
#[cfg_attr(not(feature = "clock"), doc = "```ignore")]
#[cfg_attr(feature = "clock", doc = "```rust")]
/// # use chrono::{Local, Datelike};
/// // MTWRFSU is occasionally used as a single-letter abbreviation of the weekdays.
/// // Use `num_days_from_monday` to index into the array.
/// const MTWRFSU: [char; 7] = ['M', 'T', 'W', 'R', 'F', 'S', 'U'];
///
/// let today = Local::now().weekday();
/// println!("{}", MTWRFSU[today.num_days_from_monday() as usize]);
/// ```
#[inline]
pub const fn num_days_from_monday(&self) -> u32 {
self.num_days_from(Weekday::Mon)
Expand Down

0 comments on commit b63601d

Please sign in to comment.