[−][src]Struct jomini::common::Date
Struct specialized to parsing, formatting, and manipulating dates in games
A game date 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 Date
[src]
pub fn new(year: u16, month: u8, day: u8) -> Option<Self>
[src]
Create a new date from year, month, and day parts
Will return None
if the date does not exist
use jomini::common::Date; assert_eq!(Date::new(1444, 11, 11), Date::parse_from_str("1444.11.11")); assert_eq!(Date::new(800, 5, 3), Date::parse_from_str("800.5.3")); assert!(Date::new(800, 0, 3).is_none()); assert!(Date::new(800, 1, 0).is_none()); assert!(Date::new(800, 13, 1).is_none()); assert!(Date::new(800, 12, 32).is_none()); assert!(Date::new(2020, 2, 29).is_none());
pub fn year(&self) -> u16
[src]
Year of the date
use jomini::common::Date; let date = Date::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 jomini::common::Date; let date = Date::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 jomini::common::Date; let date = Date::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 Date if valid.
use jomini::common::Date; let date = Date::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_until(&self, other: &Date) -> i32
[src]
Returns the number of days between two dates
use jomini::common::Date; let date = Date::parse_from_str("1400.1.2").unwrap(); let date2 = Date::parse_from_str("1400.1.3").unwrap(); let date3 = Date::parse_from_str("1401.1.2").unwrap(); let date4 = Date::parse_from_str("1401.12.31").unwrap(); assert_eq!(1, date.days_until(&date2)); assert_eq!(365, date.days_until(&date3)); assert_eq!(728, date.days_until(&date4)); assert_eq!(-728, date4.days_until(&date));
pub fn add_days(&self, days: i32) -> Date
[src]
Return a new date that is the given number of days in the future from the current date
use jomini::common::Date; let date = Date::parse_from_str("1400.1.2").unwrap(); let expected = Date::parse_from_str("1400.1.3").unwrap(); let expected2 = Date::parse_from_str("1400.1.1").unwrap(); assert_eq!(expected, date.add_days(1)); assert_eq!(expected2, date.add_days(-1));
pub fn from_binary(s: i32) -> Option<Self>
[src]
Decodes a date from a number that had been parsed from binary data
pub fn iso_8601(&self) -> String
[src]
Formats a date in the ISO 8601 format: YYYY-MM-DD
use jomini::common::Date; let date = Date::parse_from_str("1400.1.2").expect("to parse date"); assert_eq!(date.iso_8601(), String::from("1400-01-02"));
pub fn game_fmt(&self) -> String
[src]
Formats a date in the game format: Y.M.D
use jomini::common::Date; let date = Date::parse_from_str("1400.1.2").expect("to parse date"); let end_date = date.add_days(30); assert_eq!(end_date.game_fmt(), String::from("1400.2.1"));
Trait Implementations
impl Clone for Date
[src]
impl Copy for Date
[src]
impl Debug for Date
[src]
impl<'de> Deserialize<'de> for Date
[src]
fn deserialize<D>(deserializer: D) -> Result<Date, D::Error> where
D: Deserializer<'de>,
[src]
D: Deserializer<'de>,
impl Eq for Date
[src]
impl Ord for Date
[src]
fn cmp(&self, other: &Date) -> 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<Date> for Date
[src]
impl PartialOrd<Date> for Date
[src]
fn partial_cmp(&self, other: &Date) -> 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 Date
[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]
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>,