pub enum Month {
January = 0,
February = 1,
March = 2,
April = 3,
May = 4,
June = 5,
July = 6,
August = 7,
September = 8,
October = 9,
November = 10,
December = 11,
}Expand description
The month of the year.
This enum is just a convenience implementation. The month in dates created by DateLike objects does not return this enum.
It is possible to convert from a date to a month independently
use chrono::prelude::*;
let date = Utc.with_ymd_and_hms(2019, 10, 28, 9, 10, 11).unwrap();
// `2019-10-28T09:10:11Z`
let month = Month::try_from(u8::try_from(date.month()).unwrap()).ok();
assert_eq!(month, Some(Month::October))Or from a Month to an integer usable by dates
let month = Month::January;
let dt = Utc.with_ymd_and_hms(2019, month.number_from_month(), 28, 9, 10, 11).unwrap();
assert_eq!((dt.year(), dt.month(), dt.day()), (2019, 1, 28));Allows mapping from and to month, from 1-January to 12-December. Can be Serialized/Deserialized with serde
Variants§
January = 0
January
February = 1
February
March = 2
March
April = 3
April
May = 4
May
June = 5
June
July = 6
July
August = 7
August
September = 8
September
October = 9
October
November = 10
November
December = 11
December
Implementations§
Source§impl Month
impl Month
Sourcepub const fn succ(&self) -> Month
pub const fn succ(&self) -> Month
The next month.
m: | January | February | ... | December |
|---|---|---|---|---|
m.succ(): | February | March | ... | January |
Sourcepub const fn pred(&self) -> Month
pub const fn pred(&self) -> Month
The previous month.
m: | January | February | ... | December |
|---|---|---|---|---|
m.pred(): | December | January | ... | November |
Sourcepub const fn number_from_month(&self) -> u32
pub const fn number_from_month(&self) -> u32
Returns a month-of-year number starting from January = 1.
m: | January | February | ... | December |
|---|---|---|---|---|
m.number_from_month(): | 1 | 2 | ... | 12 |
Trait Implementations§
Source§impl<'arbitrary> Arbitrary<'arbitrary> for Month
impl<'arbitrary> Arbitrary<'arbitrary> for Month
Source§fn arbitrary(u: &mut Unstructured<'arbitrary>) -> Result<Self>
fn arbitrary(u: &mut Unstructured<'arbitrary>) -> Result<Self>
Self from the given unstructured data. Read moreSource§fn arbitrary_take_rest(u: Unstructured<'arbitrary>) -> Result<Self>
fn arbitrary_take_rest(u: Unstructured<'arbitrary>) -> Result<Self>
Self from the entirety of the given
unstructured data. Read moreSource§fn size_hint(depth: usize) -> (usize, Option<usize>)
fn size_hint(depth: usize) -> (usize, Option<usize>)
Unstructured this type
needs to construct itself. Read moreSource§fn try_size_hint(
depth: usize,
) -> Result<(usize, Option<usize>), MaxRecursionReached>
fn try_size_hint( depth: usize, ) -> Result<(usize, Option<usize>), MaxRecursionReached>
Unstructured this type
needs to construct itself. Read moreSource§impl Archive for Month
impl Archive for Month
Source§impl<'de> Deserialize<'de> for Month
Available on crate feature serde only.
impl<'de> Deserialize<'de> for Month
serde only.Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Source§impl FromPrimitive for Month
impl FromPrimitive for Month
Source§fn from_u64(n: u64) -> Option<Month>
fn from_u64(n: u64) -> Option<Month>
Returns an Option<Month> from a i64, assuming a 1-index, January = 1.
Month::from_i64(n: i64): | 1 | 2 | … | 12
—————————| –––––––––– | ——————— | … | —–
``: | Some(Month::January) | Some(Month::February) | … | Some(Month::December)
Source§fn from_i64(n: i64) -> Option<Month>
fn from_i64(n: i64) -> Option<Month>
i64 to return an optional value of this type. If the
value cannot be represented by this type, then None is returned.Source§fn from_u32(n: u32) -> Option<Month>
fn from_u32(n: u32) -> Option<Month>
u32 to return an optional value of this type. If the
value cannot be represented by this type, then None is returned.Source§fn from_isize(n: isize) -> Option<Self>
fn from_isize(n: isize) -> Option<Self>
isize to return an optional value of this type. If the
value cannot be represented by this type, then None is returned.Source§fn from_i8(n: i8) -> Option<Self>
fn from_i8(n: i8) -> Option<Self>
i8 to return an optional value of this type. If the
value cannot be represented by this type, then None is returned.Source§fn from_i16(n: i16) -> Option<Self>
fn from_i16(n: i16) -> Option<Self>
i16 to return an optional value of this type. If the
value cannot be represented by this type, then None is returned.Source§fn from_i32(n: i32) -> Option<Self>
fn from_i32(n: i32) -> Option<Self>
i32 to return an optional value of this type. If the
value cannot be represented by this type, then None is returned.Source§fn from_i128(n: i128) -> Option<Self>
fn from_i128(n: i128) -> Option<Self>
i128 to return an optional value of this type. If the
value cannot be represented by this type, then None is returned. Read moreSource§fn from_usize(n: usize) -> Option<Self>
fn from_usize(n: usize) -> Option<Self>
usize to return an optional value of this type. If the
value cannot be represented by this type, then None is returned.Source§fn from_u8(n: u8) -> Option<Self>
fn from_u8(n: u8) -> Option<Self>
u8 to return an optional value of this type. If the
value cannot be represented by this type, then None is returned.Source§fn from_u16(n: u16) -> Option<Self>
fn from_u16(n: u16) -> Option<Self>
u16 to return an optional value of this type. If the
value cannot be represented by this type, then None is returned.Source§fn from_u128(n: u128) -> Option<Self>
fn from_u128(n: u128) -> Option<Self>
u128 to return an optional value of this type. If the
value cannot be represented by this type, then None is returned. Read moreSource§impl FromStr for Month
Parsing a str into a Month uses the format %B.
impl FromStr for Month
Parsing a str into a Month uses the format %B.
§Example
use chrono::Month;
assert_eq!("January".parse::<Month>(), Ok(Month::January));
assert!("any day".parse::<Month>().is_err());The parsing is case-insensitive.
assert_eq!("fEbruARy".parse::<Month>(), Ok(Month::February));Only the shortest form (e.g. jan) and the longest form (e.g. january) is accepted.
assert!("septem".parse::<Month>().is_err());
assert!("Augustin".parse::<Month>().is_err());Source§impl Ord for Month
impl Ord for Month
Source§impl PartialEq<ArchivedMonth> for Month
impl PartialEq<ArchivedMonth> for Month
Source§impl PartialEq<Month> for ArchivedMonth
impl PartialEq<Month> for ArchivedMonth
Source§impl PartialOrd<ArchivedMonth> for Month
impl PartialOrd<ArchivedMonth> for Month
Source§impl PartialOrd<Month> for ArchivedMonth
impl PartialOrd<Month> for ArchivedMonth
Source§impl PartialOrd for Month
impl PartialOrd for Month
impl Copy for Month
impl Eq for Month
impl StructuralPartialEq for Month
Auto Trait Implementations§
impl Freeze for Month
impl RefUnwindSafe for Month
impl Send for Month
impl Sync for Month
impl Unpin for Month
impl UnwindSafe for Month
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
Source§impl<T> ArchiveUnsized for Twhere
T: Archive,
impl<T> ArchiveUnsized for Twhere
T: Archive,
Source§type Archived = <T as Archive>::Archived
type Archived = <T as Archive>::Archived
Archive, it may be unsized. Read more