horfimbor-time
Game-time calculator for Horfimbor. Converts between real-world UTC timestamps and compressed in-game time, where the game only runs during a fixed window of each real-time cycle.
More complete examples are available in poc-monorepo and horfimbor-template.
Concept
Real time is divided into repeating cycles of irl_length milliseconds. Within each cycle, only the first ig_length milliseconds count as active in-game time. During the remainder of the cycle, the game is paused and no in-game time passes.
IRL cycle (e.g. 24h):
|████░░░░░░░░░░░░░░░░░░░░░|████░░░░░░░░░░░░░░░░░░░░░|
↑ ↑
active (ig_length: 1h) next cycle starts
↓ ↓
In-game time advances In-game time frozen
Quick Start
[]
= "0.3"
= "0.4"
#
API
HfTimeConfiguration
use ;
use HfTimeConfiguration;
let _config = new.expect;
Validation: irl_length > ig_length, both non-zero.
Accessors: start_time(), irl_length() -> i64 (ms), ig_length() -> i64 (ms).
Compute active in-game milliseconds between two real-world timestamps:
# use ;
# use HfTimeConfiguration;
# let config = new.unwrap;
let start_datetime = now;
let end_datetime = now + hours;
let _ig_ms = config.diff_hf_millis;
HfTime
Represents a point in real time, associated with a configuration.
# use ;
# use ;
# let config = new.unwrap;
let t = now; // current time
let t = new; // from a DateTime<Utc>
let _datetime = t.as_datetime;
let _duration: Duration = t.as_duration;
let _hf_duration: HfDuration = t.as_hf_duration;
Status
Check whether the game is currently active or paused:
# use ;
# use ;
# let config = new.unwrap;
# let t = now;
let = t.hf_status;
match status
Arithmetic
# use ;
# use ;
# let config = new.unwrap;
// Add real-world time (chrono Duration)
let _later_irl = now + hours;
// Add in-game time — correctly skips paused windows
let _later_ig = now + from_seconds;
Adding HfDuration advances through the timeline, automatically skipping any paused periods until the full in-game duration has elapsed.
HfDuration
In-game time, measured in milliseconds.
use HfDuration;
let d = from_milliseconds;
let d = from_seconds;
let _ms: i64 = d.as_milliseconds;
let _s: i64 = d.as_seconds;
Supports +, -, and *:
# use HfDuration;
# let d = from_seconds;
let doubled = d * 2;
let total = d + from_seconds;
Error Types
HfTimeError::InvalidLength—irl_length <= ig_lengthor either is zero.HfTimeConfigurationError::InvalidStartDate— start timestamp is outside valid range.