Struct koyomi::Date [−][src]
pub struct Date { /* fields omitted */ }
日付
カレンダーのベースとなる構造体。 文字列または(年, 月, 日)から生成する。
Implementations
impl Date
[src]
impl Date
[src]pub fn parse(fmt: &str) -> KoyomiResult<Self>
[src]
文字列からオブジェクトを生成する
文字列は Y-m-d
か Y/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 PartialOrd<Date> for Date
[src]
impl PartialOrd<Date> for Date
[src]fn partial_cmp(&self, other: &Date) -> Option<Ordering>
[src]
日付オブジェクト同士を比較可能にする
#[must_use]pub fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]
pub fn lt(&self, other: &Rhs) -> bool#[must_use]pub fn le(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]
pub fn le(&self, other: &Rhs) -> bool#[must_use]pub fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]
pub fn gt(&self, other: &Rhs) -> bool#[must_use]pub fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]
pub fn ge(&self, other: &Rhs) -> boolimpl StructuralEq for Date
[src]
impl StructuralEq for Date
[src]impl StructuralPartialEq for Date
[src]
impl StructuralPartialEq for Date
[src]Auto Trait Implementations
impl RefUnwindSafe for Date
impl RefUnwindSafe for Date
impl UnwindSafe for Date
impl UnwindSafe for Date