[−][src]Struct imperator_save::ImperatorDate
Struct specialized to parsing, formatting, and manipulating dates in Imperator
A date in Imperator 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 ImperatorDate
[src]
pub fn new(year: u16, month: u8, day: u8) -> Option<Self>
[src]
Create a new Imperator date from year, month, and day parts
Will return None
if the date does not exist
use imperator_save::ImperatorDate; assert_eq!(ImperatorDate::new(1444, 11, 11), ImperatorDate::parse_from_str("1444.11.11")); assert_eq!(ImperatorDate::new(800, 5, 3), ImperatorDate::parse_from_str("800.5.3")); assert!(ImperatorDate::new(800, 0, 3).is_none()); assert!(ImperatorDate::new(800, 1, 0).is_none()); assert!(ImperatorDate::new(800, 13, 1).is_none()); assert!(ImperatorDate::new(800, 12, 32).is_none()); assert!(ImperatorDate::new(2020, 2, 29).is_none());
pub fn year(&self) -> u16
[src]
Year of the date
use imperator_save::ImperatorDate; let date = ImperatorDate::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 imperator_save::ImperatorDate; let date = ImperatorDate::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 imperator_save::ImperatorDate; let date = ImperatorDate::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 ImperatorDate if valid.
use imperator_save::ImperatorDate; let date = ImperatorDate::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: &ImperatorDate) -> i32
[src]
pub fn add_days(&self, days: i32) -> ImperatorDate
[src]
pub fn from_i32(s: i32) -> Option<Self>
[src]
pub fn iso_8601(&self) -> String
[src]
Formats an Imperator date in the ISO 8601 format: YYYY-MM-DD
use imperator_save::ImperatorDate; let date = ImperatorDate::parse_from_str("1400.1.2").expect("to parse date"); assert_eq!(date.iso_8601(), String::from("1400-01-02"));
pub fn imperator_fmt(&self) -> String
[src]
Formats an Imperator date in the Imperator format: Y.M.D
use imperator_save::ImperatorDate; let date = ImperatorDate::parse_from_str("1400.1.2").expect("to parse date"); let end_date = date.add_days(30); assert_eq!(end_date.imperator_fmt(), String::from("1400.2.1"));
Trait Implementations
impl Clone for ImperatorDate
[src]
fn clone(&self) -> ImperatorDate
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Copy for ImperatorDate
[src]
impl Debug for ImperatorDate
[src]
impl<'de> Deserialize<'de> for ImperatorDate
[src]
fn deserialize<D>(deserializer: D) -> Result<ImperatorDate, D::Error> where
D: Deserializer<'de>,
[src]
D: Deserializer<'de>,
impl Eq for ImperatorDate
[src]
impl Ord for ImperatorDate
[src]
fn cmp(&self, other: &ImperatorDate) -> Ordering
[src]
#[must_use]fn max(self, other: Self) -> Self
1.21.0[src]
#[must_use]fn min(self, other: Self) -> Self
1.21.0[src]
#[must_use]fn clamp(self, min: Self, max: Self) -> Self
[src]
impl PartialEq<ImperatorDate> for ImperatorDate
[src]
fn eq(&self, other: &ImperatorDate) -> bool
[src]
fn ne(&self, other: &ImperatorDate) -> bool
[src]
impl PartialOrd<ImperatorDate> for ImperatorDate
[src]
fn partial_cmp(&self, other: &ImperatorDate) -> Option<Ordering>
[src]
#[must_use]fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]fn le(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
impl Serialize for ImperatorDate
[src]
impl StructuralEq for ImperatorDate
[src]
impl StructuralPartialEq for ImperatorDate
[src]
Auto Trait Implementations
impl RefUnwindSafe for ImperatorDate
impl Send for ImperatorDate
impl Sync for ImperatorDate
impl Unpin for ImperatorDate
impl UnwindSafe for ImperatorDate
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> DeserializeOwned for T where
T: for<'de> Deserialize<'de>,
[src]
T: for<'de> Deserialize<'de>,
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,