Struct jomini::common::DateHour

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

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.

Converts a date into the binary representation

use jomini::common::DateHour;
let date = DateHour::from_ymdh(1, 1, 1, 1);
assert_eq!(43808760, date.to_binary());

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
Deserialize this value from the given Serde deserializer. 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

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());
Serialize this value into the given Serde serializer. Read more

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.