pub enum Month {
    January,
    February,
    March,
    April,
    May,
    June,
    July,
    August,
    September,
    October,
    November,
    December,
}
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 num_traits::FromPrimitive;
use chrono::prelude::*;
let date = Utc.ymd(2019, 10, 28).and_hms(9, 10, 11);
// `2019-10-28T09:10:11Z`
let month = Month::from_u32(date.month());
assert_eq!(month, Some(Month::October))

Or from a Month to an integer usable by dates

let month = Month::January;
let dt = Utc.ymd(2019, month.number_from_month(), 28).and_hms(9, 10, 11);
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

January

February

February

March

March

April

April

May

May

June

June

July

July

August

August

September

September

October

October

November

November

December

December

Implementations

The next month.

m:JanuaryFebruary...December
m.succ():FebruaryMarch...January

The previous month.

m:JanuaryFebruary...December
m.succ():DecemberJanuary...November

Returns a month-of-year number starting from January = 1.

m:JanuaryFebruary...December
m.number_from_month():12...12

Get the name of the month

use chrono::Month;

assert_eq!(Month::January.name(), "January")

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns an Option 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)

Converts an i64 to return an optional value of this type. If the value cannot be represented by this type, then None is returned. Read more

Converts an u32 to return an optional value of this type. If the value cannot be represented by this type, then None is returned. Read more

Converts an isize to return an optional value of this type. If the value cannot be represented by this type, then None is returned. Read more

Converts an i8 to return an optional value of this type. If the value cannot be represented by this type, then None is returned. Read more

Converts an i16 to return an optional value of this type. If the value cannot be represented by this type, then None is returned. Read more

Converts an i32 to return an optional value of this type. If the value cannot be represented by this type, then None is returned. Read more

Converts an i128 to return an optional value of this type. If the value cannot be represented by this type, then None is returned. Read more

Converts a usize to return an optional value of this type. If the value cannot be represented by this type, then None is returned. Read more

Converts an u8 to return an optional value of this type. If the value cannot be represented by this type, then None is returned. Read more

Converts an u16 to return an optional value of this type. If the value cannot be represented by this type, then None is returned. Read more

Converts an u128 to return an optional value of this type. If the value cannot be represented by this type, then None is returned. Read more

Converts a f32 to return an optional value of this type. If the value cannot be represented by this type, then None is returned. Read more

Converts a f64 to return an optional value of this type. If the value cannot be represented by this type, then None is returned. Read more

Parsing a str into a Month uses the format %W.

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());

The associated error which can be returned from parsing.

Parses a string s to return a value of this type. Read more

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait. Read more

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait. Read more

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s. Read more

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s. Read more

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait. Read more

Use this to cast from one trait object type to another. Read more

Use this to upcast a trait to one of its supertraits. Read more

Use this to cast from one trait object type to another. This method is more customizable than the dyn_cast method. Here you can also specify the “source” trait from which the cast is defined. This can for example allow using casts from a supertrait of the current trait object. Read more

Use this to cast from one trait object type to another. With this method the type parameter is a config type that uniquely specifies which cast should be preformed. Read more

Compare self to key and return true if they are equal.

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Should always be Self

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more