Struct jomini::common::RawDate

source ·
pub struct RawDate { /* private fields */ }
Expand description

Common implementation between the different date and time formats.

Space optimized to only need 4 bytes

It may or may not have an hour component.

Paradox games do not follow any traditional calendar and instead view the world on simpler terms: that every year should be treated as a non-leap year.

Years can be negative but can’t be zero.

An hour component is considered present if it is non-zero. This means that games with hours run on a non-traditional clock from 1-24 instead of the traditional 24 hour clock (0-23). An exception is Victoria 3, which has day cycle of (0, 6, 12, 18) hours, but remains consistent in omitting the hour when it is zero.

A raw date has very minimal validation and can support any calendar system as it holds abitrary values for year, month, day, and hours

It is typically recommended to use one of the specialized types: Date, DateHour, or UniformDate as date formats aren’t variable within a game and have less pitfalls.

Implementations§

source§

impl RawDate

source

pub fn from_binary(s: i32) -> Option<Self>

Creates a raw date from a binary integer

use jomini::common::{RawDate, PdsDate};
let date = RawDate::from_binary(56379360).unwrap();
assert_eq!(date.iso_8601().to_string(), String::from("1436-01-01"));

let date2 = RawDate::from_binary(60759371).unwrap();
assert_eq!(date2.iso_8601().to_string(), String::from("1936-01-01T10"));
source

pub fn from_ymdh_opt(year: i16, month: u8, day: u8, hour: u8) -> Option<Self>

Create a raw date from individual components.

Will return none for an invalid date

source

pub fn from_ymdh(year: i16, month: u8, day: u8, hour: u8) -> Self

Create a raw date from individual components.

Will panic on invalid dates

source

pub fn hour(&self) -> u8

Return the hour component. Range [1, 24]. If zero, then there is no hour

source

pub fn has_hour(&self) -> bool

Return if this date has an hour component

source

pub fn parse<T: AsRef<[u8]>>(s: T) -> Result<Self, DateError>

Parses date components from the following formatted text:

  • Y.M.D
  • Y.M.D.H
  • YYYY.MM.DD.HH
  • or any variation of the above

A zero component for the hour is disallowed, so the hour must be omitted when parsing to only a date without a time component.

Unlike Date::parse, this will not parse the textual form of the date’s binary representation.

Trait Implementations§

source§

impl Clone for RawDate

source§

fn clone(&self) -> RawDate

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for RawDate

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl FromStr for RawDate

§

type Err = DateError

The associated error which can be returned from parsing.
source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
source§

impl Hash for RawDate

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl Ord for RawDate

source§

fn cmp(&self, other: &RawDate) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl PartialEq for RawDate

source§

fn eq(&self, other: &RawDate) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd for RawDate

source§

fn partial_cmp(&self, other: &RawDate) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

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 more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl PdsDate for RawDate

source§

fn year(&self) -> i16

Return year of date

source§

fn month(&self) -> u8

Return month of date

source§

fn day(&self) -> u8

Return day of date

source§

fn game_fmt(&self) -> PdsDateFormatter

Formats the date in the game format
source§

fn iso_8601(&self) -> PdsDateFormatter

Formats the date in an iso8601 format
source§

impl Copy for RawDate

source§

impl Eq for RawDate

source§

impl StructuralPartialEq for RawDate

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.