pub struct DateHour { /* private fields */ }
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§
source§impl DateHour
impl DateHour
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 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());
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
use jomini::common::{DateHour, PdsDate};
let date = DateHour::from_ymdh(1936, 1, 3, 12);
assert_eq!(date.day(), 3);
sourcepub fn hour(&self) -> u8
pub fn hour(&self) -> u8
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);
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 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)));
sourcepub fn from_binary(s: i32) -> Option<Self>
pub fn from_binary(s: i32) -> Option<Self>
Decode a number extracted from the binary format into a date.
sourcepub fn from_binary_heuristic(s: i32) -> Option<Self>
pub fn from_binary_heuristic(s: i32) -> Option<Self>
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§
source§impl<'de> Deserialize<'de> for DateHour
impl<'de> Deserialize<'de> for DateHour
source§fn deserialize<D>(deserializer: D) -> Result<DateHour, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<DateHour, D::Error>where
D: Deserializer<'de>,
source§impl Ord for DateHour
impl Ord for DateHour
source§impl PartialEq for DateHour
impl PartialEq for DateHour
source§impl PartialOrd for DateHour
impl PartialOrd for DateHour
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 moresource§impl PdsDate for DateHour
impl PdsDate for DateHour
source§fn year(&self) -> i16
fn year(&self) -> i16
Year of the date
use jomini::common::{DateHour, PdsDate};
let date = DateHour::from_ymdh(1936, 1, 2, 24);
assert_eq!(date.year(), 1936);
source§fn month(&self) -> u8
fn month(&self) -> u8
Month of the date
use jomini::common::{DateHour, PdsDate};
let date = DateHour::from_ymdh(1936, 1, 2, 24);
assert_eq!(date.month(), 1);
source§fn day(&self) -> u8
fn day(&self) -> u8
Day of the date
use jomini::common::{DateHour, PdsDate};
let date = DateHour::from_ymdh(1936, 1, 2, 24);
assert_eq!(date.day(), 2);
source§fn iso_8601(&self) -> PdsDateFormatter
fn iso_8601(&self) -> PdsDateFormatter
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());
source§fn game_fmt(&self) -> PdsDateFormatter
fn game_fmt(&self) -> PdsDateFormatter
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());