Struct jomini::common::UniformDate
source · pub struct UniformDate { /* private fields */ }
Expand description
A date without a time component where each month has 30 days
Useful for Stellaris
See RawDate for additional date / time commentary
Implementations§
source§impl UniformDate
impl UniformDate
sourcepub fn from_ymd_opt(year: i16, month: u8, day: u8) -> Option<Self>
pub fn from_ymd_opt(year: i16, month: u8, day: u8) -> Option<Self>
Create a new date from year, month, and day parts
Will return None
if the date does not exist
use jomini::common::{PdsDate, UniformDate};
assert_eq!(UniformDate::from_ymd_opt(1444, 11, 11), Some(UniformDate::from_ymd(1444, 11, 11)));
assert_eq!(UniformDate::from_ymd_opt(800, 5, 3), Some(UniformDate::from_ymd(800, 5, 3)));
assert!(UniformDate::from_ymd_opt(800, 0, 3).is_none());
assert!(UniformDate::from_ymd_opt(800, 1, 0).is_none());
assert!(UniformDate::from_ymd_opt(800, 13, 1).is_none());
assert!(UniformDate::from_ymd_opt(800, 12, 32).is_none());
assert!(UniformDate::from_ymd_opt(2020, 2, 29).is_some());
sourcepub fn from_ymd(year: i16, month: u8, day: u8) -> Self
pub fn from_ymd(year: i16, month: u8, day: u8) -> Self
Create a new date from year, month, and day parts
Will panic if the date does not exist.
sourcepub fn parse<T: AsRef<[u8]>>(s: T) -> Result<Self, DateError>
pub fn parse<T: AsRef<[u8]>>(s: T) -> Result<Self, DateError>
Parse a DateHour from text. Follows the same logic as RawDate::parse except that a 12 month calendar of 30 days is enforced.
use jomini::common::UniformDate;
assert_eq!(UniformDate::parse("2200.02.30"), Ok(UniformDate::from_ymd(2200, 2, 30)));
Trait Implementations§
source§impl Clone for UniformDate
impl Clone for UniformDate
source§fn clone(&self) -> UniformDate
fn clone(&self) -> UniformDate
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl Debug for UniformDate
impl Debug for UniformDate
source§impl<'de> Deserialize<'de> for UniformDate
impl<'de> Deserialize<'de> for UniformDate
source§fn deserialize<D>(deserializer: D) -> Result<UniformDate, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<UniformDate, D::Error>where
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
source§impl FromStr for UniformDate
impl FromStr for UniformDate
source§impl Hash for UniformDate
impl Hash for UniformDate
source§impl Ord for UniformDate
impl Ord for UniformDate
source§fn cmp(&self, other: &UniformDate) -> Ordering
fn cmp(&self, other: &UniformDate) -> Ordering
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
source§impl PartialEq<UniformDate> for UniformDate
impl PartialEq<UniformDate> for UniformDate
source§fn eq(&self, other: &UniformDate) -> bool
fn eq(&self, other: &UniformDate) -> bool
This method tests for
self
and other
values to be equal, and is used
by ==
.source§impl PartialOrd<UniformDate> for UniformDate
impl PartialOrd<UniformDate> for UniformDate
source§fn partial_cmp(&self, other: &UniformDate) -> Option<Ordering>
fn partial_cmp(&self, other: &UniformDate) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self
and other
) and is used by the <=
operator. Read moresource§impl PdsDate for UniformDate
impl PdsDate for UniformDate
source§fn year(&self) -> i16
fn year(&self) -> i16
Year of the date
use jomini::common::{UniformDate, PdsDate};
let date = UniformDate::from_ymd(1444, 2, 3);
assert_eq!(date.year(), 1444);
source§fn month(&self) -> u8
fn month(&self) -> u8
Month of the date
use jomini::common::{UniformDate, PdsDate};
let date = UniformDate::from_ymd(1444, 2, 3);
assert_eq!(date.month(), 2);
source§fn day(&self) -> u8
fn day(&self) -> u8
Day of the date
use jomini::common::{UniformDate, PdsDate};
let date = UniformDate::from_ymd(1444, 2, 3);
assert_eq!(date.day(), 3);
source§fn iso_8601(&self) -> PdsDateFormatter
fn iso_8601(&self) -> PdsDateFormatter
Formats a date in the ISO 8601 format: YYYY-MM-DD
use jomini::common::{UniformDate, PdsDate};
let date = UniformDate::from_ymd(1400, 1, 2);
assert_eq!(date.iso_8601().to_string(), String::from("1400-01-02"));
source§fn game_fmt(&self) -> PdsDateFormatter
fn game_fmt(&self) -> PdsDateFormatter
Formats a date in the game format: Y.MM.DD
use jomini::common::{UniformDate, PdsDate};
let date = UniformDate::from_ymd(1400, 1, 2);
assert_eq!(date.game_fmt().to_string(), String::from("1400.01.02"));