mirror of
https://github.com/chronotope/chrono.git
synced 2025-10-02 07:21:41 +00:00
Add an example to Weekday
This commit is contained in:
parent
35eaac3446
commit
e51430f3e1
@ -8,6 +8,26 @@ use rkyv::{Archive, Deserialize, Serialize};
|
||||
/// The order of the days of week depends on the context.
|
||||
/// (This is why this type does *not* implement `PartialOrd` or `Ord` traits.)
|
||||
/// One should prefer `*_from_monday` or `*_from_sunday` methods to get the correct result.
|
||||
///
|
||||
/// # Example
|
||||
/// ```
|
||||
/// use chrono::Weekday;
|
||||
/// use num_traits::cast::FromPrimitive;
|
||||
///
|
||||
/// let monday = "Monday".parse::<Weekday>().unwrap();
|
||||
/// assert_eq!(monday, Weekday::Mon);
|
||||
///
|
||||
/// let sunday = Weekday::from_u8(6).unwrap();
|
||||
/// assert_eq!(sunday, Weekday::Sun);
|
||||
///
|
||||
/// assert_eq!(sunday.num_days_from_monday(), 6); // starts counting with Monday = 0
|
||||
/// assert_eq!(sunday.number_from_monday(), 7); // starts counting with Monday = 1
|
||||
/// assert_eq!(sunday.num_days_from_sunday(), 0); // starts counting with Sunday = 0
|
||||
/// assert_eq!(sunday.number_from_sunday(), 1); // starts counting with Sunday = 1
|
||||
///
|
||||
/// assert_eq!(sunday.succ(), monday);
|
||||
/// assert_eq!(sunday.pred(), Weekday::Sat);
|
||||
/// ```
|
||||
#[derive(PartialEq, Eq, Copy, Clone, Debug, Hash)]
|
||||
#[cfg_attr(feature = "rustc-serialize", derive(RustcEncodable, RustcDecodable))]
|
||||
#[cfg_attr(feature = "rkyv", derive(Archive, Deserialize, Serialize))]
|
||||
@ -110,7 +130,7 @@ impl Weekday {
|
||||
|
||||
/// Returns a day-of-week number starting from the parameter `day` (D) = 0.
|
||||
///
|
||||
/// `w`: | `D` | `D+1` | `D+2` | `D+3` | `D+4` | `D+5` | `D+6`
|
||||
/// `w`: | `D` | `D+1` | `D+2` | `D+3` | `D+4` | `D+5` | `D+6`
|
||||
/// --------------------------- | ----- | ----- | ----- | ----- | ----- | ----- | -----
|
||||
/// `w.num_days_from(wd)`: | 0 | 1 | 2 | 3 | 4 | 5 | 6
|
||||
#[inline]
|
||||
|
Loading…
x
Reference in New Issue
Block a user