[][src]Struct ck3save::Ck3Date

pub struct Ck3Date { /* fields omitted */ }

Struct specialized to parsing, formatting, and manipulating dates in CK3

A date in CK3 does not follow any traditional calendar and instead views the world on simpler terms: that every year should be treated as a non-leap year.

Implementations

impl Ck3Date[src]

pub fn new(year: u16, month: u8, day: u8) -> Option<Self>[src]

Create a new CK3 date from year, month, and day parts

Will return None if the date does not exist

use ck3save::Ck3Date;
assert_eq!(Ck3Date::new(1444, 11, 11), Ck3Date::parse_from_str("1444.11.11"));
assert_eq!(Ck3Date::new(800, 5, 3), Ck3Date::parse_from_str("800.5.3"));
assert!(Ck3Date::new(800, 0, 3).is_none());
assert!(Ck3Date::new(800, 1, 0).is_none());
assert!(Ck3Date::new(800, 13, 1).is_none());
assert!(Ck3Date::new(800, 12, 32).is_none());
assert!(Ck3Date::new(2020, 2, 29).is_none());

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

Year of the date

use ck3save::Ck3Date;
let date = Ck3Date::parse_from_str("1445.02.03").expect("to parse date");
assert_eq!(date.year(), 1445);

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

Month of the date

use ck3save::Ck3Date;
let date = Ck3Date::parse_from_str("1445.02.03").expect("to parse date");
assert_eq!(date.month(), 2);

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

Day of the date

use ck3save::Ck3Date;
let date = Ck3Date::parse_from_str("1445.02.03").expect("to parse date");
assert_eq!(date.day(), 3);

pub fn parse_from_str<T: AsRef<str>>(s: T) -> Option<Self>[src]

Parses a string and returns a new Ck3Date if valid.

use ck3save::Ck3Date;
let date = Ck3Date::parse_from_str("1444.11.11").expect("to parse date");
assert_eq!(date.year(), 1444);
assert_eq!(date.month(), 11);
assert_eq!(date.day(), 11);

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

pub fn days_until(&self, other: &Ck3Date) -> i32[src]

pub fn add_days(&self, days: i32) -> Ck3Date[src]

pub fn from_i32(s: i32) -> Option<Self>[src]

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

Formats an CK3 date in the ISO 8601 format: YYYY-MM-DD

use ck3save::Ck3Date;
let date = Ck3Date::parse_from_str("1400.1.2").expect("to parse date");
assert_eq!(date.iso_8601(), String::from("1400-01-02"));

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

Formats an CK3 date in the CK3 format: Y.M.D

use ck3save::Ck3Date;
let date = Ck3Date::parse_from_str("1400.1.2").expect("to parse date");
let end_date = date.add_days(30);
assert_eq!(end_date.ck3_fmt(), String::from("1400.2.1"));

Trait Implementations

impl Clone for Ck3Date[src]

impl Copy for Ck3Date[src]

impl Debug for Ck3Date[src]

impl<'de> Deserialize<'de> for Ck3Date[src]

impl Eq for Ck3Date[src]

impl Ord for Ck3Date[src]

impl PartialEq<Ck3Date> for Ck3Date[src]

impl PartialOrd<Ck3Date> for Ck3Date[src]

impl Serialize for Ck3Date[src]

impl StructuralEq for Ck3Date[src]

impl StructuralPartialEq for Ck3Date[src]

Auto Trait Implementations

impl RefUnwindSafe for Ck3Date

impl Send for Ck3Date

impl Sync for Ck3Date

impl Unpin for Ck3Date

impl UnwindSafe for Ck3Date

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> DeserializeOwned for T where
    T: for<'de> Deserialize<'de>, 
[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, 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.