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§

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"));

Create a raw date from individual components.

Will return none for an invalid date

Create a raw date from individual components.

Will panic on invalid dates

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

Return if this date has an hour component

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§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
The associated error which can be returned from parsing.
Parses a string s to return a value of this type. Read more
Feeds this value into the given Hasher. Read more
Feeds a slice of this type into the given Hasher. Read more
This method returns an Ordering between self and other. Read more
Compares and returns the maximum of two values. Read more
Compares and returns the minimum of two values. Read more
Restrict a value to a certain interval. Read more
This method tests for self and other values to be equal, and is used by ==.
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
This method returns an ordering between self and other values if one exists. Read more
This method tests less than (for self and other) and is used by the < operator. Read more
This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
This method tests greater than (for self and other) and is used by the > operator. Read more
This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Return year of date

Return month of date

Return day of date

Formats the date in the game format
Formats the date in an iso8601 format

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.