[][src]Struct koyomi::Date

pub struct Date { /* fields omitted */ }

日付

カレンダーのベースとなる構造体。 文字列または(年, 月, 日)から生成する。

Methods

impl Date[src]

pub fn parse(fmt: &str) -> KoyomiResult<Self>[src]

文字列からオブジェクトを生成する 文字列は Y-m-dY/m/d 形式のみ受け付ける

Examples

use koyomi::Date;

let date = Date::parse("2018-01-01");
assert!(date.is_ok());

let date = Date::parse("2018/01/01");
assert!(date.is_ok());

let date = Date::parse("2018-01-32");
assert!(date.is_err());

pub fn from_ymd(year: i32, month: u32, day: u32) -> KoyomiResult<Self>[src]

年月日からオブジェクトを生成する

Examples

use koyomi::Date;

let date = Date::from_ymd(2018, 1, 1);
assert!(date.is_ok());

let date = Date::from_ymd(2018, 13, 1);
assert!(date.is_err());

pub fn day(&self) -> u32[src]

「日」を返す

Examples

use koyomi::Date;

let date = Date::from_ymd(2018, 1, 31).unwrap();
assert_eq!(date.day(), 31);

pub fn era(&self) -> Option<Era>[src]

「元号」を返す

Examples

use koyomi::Date;

let date = Date::from_ymd(2018, 1, 1).unwrap();
assert_eq!(date.era().unwrap().name(), "平成");

pub fn holiday(&self) -> Option<String>[src]

「祝祭日」を返す

Examples

use koyomi::Date;

let date = Date::from_ymd(2018, 1, 1).unwrap();
assert_eq!(date.holiday().unwrap(), "元日");

let date = Date::from_ymd(2018, 1, 2).unwrap();
assert_eq!(date.holiday(), None);

pub fn month(&self) -> u32[src]

「月」を返す

Examples

use koyomi::Date;

let date = Date::from_ymd(2018, 12, 1).unwrap();
assert_eq!(date.month(), 12);

pub fn num_days(&self, date: &Date) -> i64[src]

日付間の期間が何日あるかを返す

Examples

use koyomi::Date;

let from = Date::from_ymd(2018, 1, 1).unwrap();
let until = Date::from_ymd(2018, 12, 31).unwrap();
assert_eq!(until.num_days(&from), 364);

// うるう年
let from = Date::from_ymd(2016, 1, 1).unwrap();
let until = Date::from_ymd(2016, 12, 31).unwrap();
assert_eq!(until.num_days(&from), 365);

pub fn to_string(&self) -> String[src]

日付の文字列表現を返す フォーマットは Y-m-d 形式となる

Examples

use koyomi::Date;

let date = Date::from_ymd(2018, 1, 1).unwrap();
assert_eq!(date.to_string(), "2018-01-01");

pub fn tomorrow(&self) -> KoyomiResult<Self>[src]

翌日の日付を返す

Examples

use koyomi::Date;

let date = Date::from_ymd(2018, 1, 1).unwrap();
let tomorrow = date.tomorrow();
assert_eq!(tomorrow.unwrap().to_string(), "2018-01-02");

pub fn weekday(&self) -> &Weekday[src]

「曜日」を返す

Examples

use koyomi::{Date, Weekday};

let date = Date::from_ymd(2018, 1, 1).unwrap();
assert_eq!(date.weekday(), &Weekday::Monday);

pub fn year(&self) -> i32[src]

「年」を返す

Examples

use koyomi::Date;

let date = Date::from_ymd(2018, 1, 1).unwrap();
assert_eq!(date.year(), 2018);

pub fn yesterday(&self) -> KoyomiResult<Self>[src]

前日の日付を返す

Examples

use koyomi::Date;

let date = Date::from_ymd(2018, 1, 1).unwrap();
let yesterday = date.yesterday();
assert_eq!(yesterday.unwrap().to_string(), "2017-12-31");

Trait Implementations

impl Clone for Date[src]

impl Debug for Date[src]

impl Display for Date[src]

impl Eq for Date[src]

impl Ord for Date[src]

fn cmp(&self, other: &Date) -> Ordering[src]

日付オブジェクト同士を比較可能にする

impl PartialEq<Date> for Date[src]

impl PartialOrd<Date> for Date[src]

fn partial_cmp(&self, other: &Date) -> Option<Ordering>[src]

日付オブジェクト同士を比較可能にする

impl StructuralEq for Date[src]

impl StructuralPartialEq for Date[src]

Auto Trait Implementations

impl RefUnwindSafe for Date

impl Send for Date

impl Sync for Date

impl Unpin for Date

impl UnwindSafe for Date

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.