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
impl RawDate
sourcepub fn from_binary(s: i32) -> Option<Self>
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"));
sourcepub fn from_ymdh_opt(year: i16, month: u8, day: u8, hour: u8) -> Option<Self>
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
sourcepub fn from_ymdh(year: i16, month: u8, day: u8, hour: u8) -> Self
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
sourcepub fn hour(&self) -> u8
pub fn hour(&self) -> u8
Return the hour component. Range [1, 24]. If zero, then there is no hour
sourcepub fn parse<T: AsRef<[u8]>>(s: T) -> Result<Self, DateError>
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 Ord for RawDate
impl Ord for RawDate
source§impl PartialEq<RawDate> for RawDate
impl PartialEq<RawDate> for RawDate
source§impl PartialOrd<RawDate> for RawDate
impl PartialOrd<RawDate> for RawDate
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more