horfimbor-time

Crates.iohorfimbor-time
lib.rshorfimbor-time
version0.2.0
sourcesrc
created_at2024-08-25 19:10:49.174495
updated_at2024-08-27 22:56:54.043073
descriptionTime calculator for the Horfimbor game
homepage
repositoryhttps://github.com/horfimbor/horfimbor-time
max_upload_size
id1351379
size13,925
Aedius (Aedius)

documentation

README

Horfimbor time

This crate provide a converter between the ingame time and the "real" timestamp.

the typical use case of this library use some configuration, get the current HfTime, add some in-game time ( to construct a building or whatever ) then get the remaining irl time to wait

use chrono::{DateTime, Duration, TimeZone, Utc};
use horfimbor_time::{HfTime, HfTimeConfiguration, HfDuration};

let config = HfTimeConfiguration::new(
    Duration::seconds(3600 * 24),
    Duration::seconds(3600),
    Utc.with_ymd_and_hms(2021, 01, 01, 20, 0, 0).unwrap(),
)
.expect("cannot create configuration");

let time = HfTime::now(config);
let building_time = HfDuration::seconds(4000);
let end = time + building_time;

println!("building will end at : {}", end.as_datetime().unwrap());

let tomorrow = Utc::now() + Duration::seconds(24 * 3600);
assert!(end
    .as_datetime()
    .expect("cannot convert to datetime")
    .gt(&tomorrow))

Commit count: 0

cargo fmt