Skip to main content

Durations

Package: dev.anchorlight.stonelib.time

Time shown to players comes in three shapes that are not interchangeable. 18:30 in a sentence reads as a time of day, and 18 minutes 30 seconds does not fit on a scoreboard. Durations gives each shape its own method, so the choice is explicit.

Formats​

MethodUse it forExamples
clockBossbars and live countdowns, where the digits are ticking and the reader is watching them.0:05, 12:34, 1:02:33
humanProse: a quest description, a cooldown message. Never renders like a clock.1 second, 30 seconds, 18 minutes, 18m 30s, 2 hours, 2h 5m
compactSidebars and status lines, where space is tight. At most two units.30s, 5m 30s, 2h 5m

Each takes either a Duration or a whole number of seconds:

Durations.clock(Duration.ofSeconds(754)); // "12:34"
Durations.human(Duration.ofMinutes(18)); // "18 minutes"
Durations.human(1110); // "18m 30s"
Durations.compact(Duration.ofSeconds(7530)); // "2h 5m"

Exact output​

Inputclockhumancompact
0 seconds0:000 seconds0s
1 second0:011 second1s
45 seconds0:4545 seconds45s
1 minute1:001 minute1m 0s
18 minutes 30 seconds18:3018m 30s18m 30s
1 hour1:00:001 hour1h 0m
1 hour 30 seconds1:00:301h 0m1h 0m
2 hours 5 minutes 40 seconds2:05:402h 5m2h 5m
50 hours50:00:0050 hours50h 0m

Rules behind the table:

  • Hours never roll over into days.
  • Once there are hours, human and compact show only hours and minutes, dropping seconds.
  • human uses a spelled-out, correctly pluralised unit only when the value is a whole number of that unit, and the short form otherwise.
  • Fractions of a second are dropped, never rounded up.
  • null and negative durations are shown as zero.

Ticks​

MethodMeaning
toTicks(Duration)Whole server ticks, at 20 per second, for scheduler calls.
scheduler.runSyncLater(this::endRound, Durations.toTicks(Duration.ofMinutes(5))); // 6000 ticks

toTicks works in whole seconds, so Duration.ofMillis(1500) becomes 20 ticks, not 30, and anything under a second becomes 0. For sub-second delays, pass a tick count directly.