Crates.io | horfimbor-time |
lib.rs | horfimbor-time |
version | 0.2.0 |
source | src |
created_at | 2024-08-25 19:10:49.174495 |
updated_at | 2024-08-27 22:56:54.043073 |
description | Time calculator for the Horfimbor game |
homepage | |
repository | https://github.com/horfimbor/horfimbor-time |
max_upload_size | |
id | 1351379 |
size | 13,925 |
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))