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§

source§

impl DateHour

source

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());
source

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

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

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

pub fn from_binary(s: i32) -> Option<Self>

Decode a number extracted from the binary format into a date.

source

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.

source

pub fn to_binary(self) -> i32

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§

source§

impl Clone for DateHour

source§

fn clone(&self) -> DateHour

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for DateHour

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'de> Deserialize<'de> for DateHour

source§

fn deserialize<D>(deserializer: D) -> Result<DateHour, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl FromStr for DateHour

§

type Err = DateError

The associated error which can be returned from parsing.
source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
source§

impl Hash for DateHour

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl Ord for DateHour

source§

fn cmp(&self, other: &DateHour) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl PartialEq for DateHour

source§

fn eq(&self, other: &DateHour) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd for DateHour

source§

fn partial_cmp(&self, other: &DateHour) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl PdsDate for DateHour

source§

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

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

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

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

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());
source§

impl Serialize for DateHour

source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl Copy for DateHour

source§

impl Eq for DateHour

source§

impl StructuralPartialEq for DateHour

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

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

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,