Struct Year

Source
pub struct Year(pub i64);
Expand description

A single year.

This is just a wrapper around i64 that performs year-related tests.

Tuple Fields§

§0: i64

Implementations§

Source§

impl Year

Source

pub fn is_leap_year(self) -> bool

Returns whether this year is a leap year.

§Examples
use datetime::Year;

assert_eq!(Year(2000).is_leap_year(), true);
assert_eq!(Year(1900).is_leap_year(), false);
Source

pub fn months<S: MonthSpan>(self, span: S) -> YearMonths

Returns an iterator over a continuous span of months in this year, returning year-month pairs.

This method takes one argument that can be of four different types, depending on the months you wish to iterate over:

  • The RangeFull type (such as ..), which iterates over every month;
  • The RangeFrom type (such as April ..), which iterates over the months starting from the month given;
  • The RangeTo type (such as .. June), which iterates over the months stopping at but not including the month given;
  • The Range type (such as April .. June), which iterates over the months starting from the left one and stopping at but not including the right one.
§Examples
use datetime::Year;
use datetime::Month::{April, June};

let year = Year(1999);
assert_eq!(year.months(..).count(), 12);
assert_eq!(year.months(April ..).count(), 9);
assert_eq!(year.months(April .. June).count(), 2);
assert_eq!(year.months(.. June).count(), 5);
Source

pub fn month(self, month: Month) -> YearMonth

Returns a year-month, pairing this year with the given month.

§Examples
use datetime::{Year, Month};

let expiry_date = Year(2017).month(Month::February);
assert_eq!(*expiry_date.year, 2017);
assert_eq!(expiry_date.month, Month::February);

Methods from Deref<Target = i64>§

1.43.0 · Source

pub const MIN: i64 = -9_223_372_036_854_775_808i64

1.43.0 · Source

pub const MAX: i64 = 9_223_372_036_854_775_807i64

1.53.0 · Source

pub const BITS: u32 = 64u32

Trait Implementations§

Source§

impl Clone for Year

Source§

fn clone(&self) -> Year

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Year

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Deref for Year

Source§

type Target = i64

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl PartialEq for Year

Source§

fn eq(&self, other: &Year) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for Year

Source§

impl StructuralPartialEq for Year

Auto Trait Implementations§

§

impl Freeze for Year

§

impl RefUnwindSafe for Year

§

impl Send for Year

§

impl Sync for Year

§

impl Unpin for Year

§

impl UnwindSafe for Year

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.