Struct jomini::common::DateHour [−][src]
pub struct DateHour { /* fields omitted */ }
Expand description
A date with an hour component
Geared towards the hearts of iron games.
See RawDate for additional date / time commentary
use jomini::common::{DateHour, PdsDate};
let date = DateHour::from_ymdh(1936, 1, 1, 24);
let iso = date.iso_8601().to_string();
assert_eq!(iso, String::from("1936-01-01T23"));
Implementations
Create a new DateHour from individual components
The hour is expected to be non-zero in addition to the validation that a regular Date object undergoes.
use jomini::common::DateHour;
assert!(DateHour::from_ymdh_opt(1936, 1, 1, 24).is_some());
assert!(DateHour::from_ymdh_opt(1936, 1, 1, 0).is_none());
use jomini::common::{DateHour, PdsDate};
let date = DateHour::from_ymdh(1936, 1, 3, 12);
assert_eq!(date.day(), 3);
hour of the date. Range: [1, 24]
use jomini::common::DateHour;
let date = DateHour::from_ymdh(1936, 1, 2, 12);
assert_eq!(date.hour(), 12);
Parse a DateHour from text. Follows the same logic as RawDate::parse except an hour component is enforced.
use jomini::common::DateHour;
assert_eq!(DateHour::parse("1936.1.1.24"), Ok(DateHour::from_ymdh(1936, 1, 1, 24)));
Decode a number extracted from the binary format into a date.
Decode a number extracted from the binary format into a date, but ensure that the date is at least in the 1800’s (an arbitrary chosen value to support HOI4 mods that move the start date up). There is a special exception made for 1.1.1.1 and -1.1.1.1 which represents an event that has not occurred yet.
Trait Implementations
Deserialize this value from the given Serde deserializer. Read more
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
Year of the date
use jomini::common::{DateHour, PdsDate};
let date = DateHour::from_ymdh(1936, 1, 2, 24);
assert_eq!(date.year(), 1936);
Month of the date
use jomini::common::{DateHour, PdsDate};
let date = DateHour::from_ymdh(1936, 1, 2, 24);
assert_eq!(date.month(), 1);
Day of the date
use jomini::common::{DateHour, PdsDate};
let date = DateHour::from_ymdh(1936, 1, 2, 24);
assert_eq!(date.day(), 2);
Return the date as an iso8601 compatible string
The hour component is converted to a range of [0, 23] per the spec
use jomini::common::{DateHour, PdsDate};
let date = DateHour::from_ymdh(1936, 1, 2, 12);
assert_eq!(String::from("1936-01-02T11"), date.iso_8601().to_string());
Return the date in the game format
use jomini::common::{DateHour, PdsDate};
let date = DateHour::from_ymdh(1936, 1, 2, 12);
assert_eq!(String::from("1936.1.2.12"), date.game_fmt().to_string());
Auto Trait Implementations
impl RefUnwindSafe for DateHour
impl UnwindSafe for DateHour
Blanket Implementations
Mutably borrows from an owned value. Read more