time

Generated by tinox doc

Time utilities: Time::now()/sleep(), Duration (seconds/minutes/hours arithmetic), Timer and Stopwatch for measuring elapsed time (Stopwatch only counts while running; Timer always measures start-to-now or start-to-stop).

Stopwatch and duration

import tinox.core.time;

class Main
{
    fnc main() -> Int32
    {
        let sw: Stopwatch = Time::newStopwatch();
        sw.start();
        Time::sleep(50);
        sw.stop();
        println("elapsed: " + sw.elapsed().toString() + "ms");

        let d: Duration = Time::durationFromMinutes(90);
        println("90 minutes = " + d.getHours().toString() + "h " + (d.getMinutes() - d.getHours() * 60).toString() + "m");

        return 0;
    }
}

class Duration

* Represents a duration of time in seconds * * Provides factory methods for creating durations from * different time units and arithmetic operations.

Fields

secondsInt64 The duration in seconds

Methods

fn new(seconds: Int64) → Duration
* Creates a Duration from seconds * * @param seconds the number of seconds * @return a new Duration instance
fn fromMinutes(minutes: Int64) → Duration
* Creates a Duration from minutes * * @param minutes the number of minutes * @return a new Duration instance
fn fromHours(hours: Int64) → Duration
* Creates a Duration from hours * * @param hours the number of hours * @return a new Duration instance
fn getSeconds() → Int64
* Returns the duration in seconds * * @return the number of seconds
fn getMinutes() → Int64
* Returns the duration in whole minutes * * @return the number of minutes (truncated)
fn getHours() → Int64
* Returns the duration in whole hours * * @return the number of hours (truncated)
fn add(other: Duration) → Duration
* Adds another duration to this one * * @param other the duration to add * @return a new Duration with the combined time
fn sub(other: Duration) → Duration
* Subtracts another duration from this one * * @param other the duration to subtract * @return a new Duration with the difference

class Stopwatch

* A stopwatch for measuring elapsed time while running * * Unlike Timer, Stopwatch only reports elapsed time * while it is actively running (between start and stop).

Fields

startTimeInt64 The time when start() was called
stopTimeInt64 The time when stop() was called (0 if never stopped)
runningBool Whether the stopwatch is currently running

Methods

fn new() → Stopwatch
* Creates a new Stopwatch (not running) * * @return a new Stopwatch instance
fn start() → Nothing
* Starts the stopwatch, recording the current time
fn stop() → Nothing
* Stops the stopwatch, freezing the current time so elapsed() * keeps reporting the start-to-stop duration afterward
fn isRunning() → Bool
* Checks if the stopwatch is currently running * * @return true if start() was called without a subsequent stop()
fn elapsed() → Int64
* Returns the elapsed time * * While running, returns the time from start() to now. Once * stopped, keeps returning the frozen start-to-stop duration * (rather than resetting to 0) so callers can read the result * after stop(). Returns 0 if start() was never called. * * @return elapsed time in milliseconds

class Time

* Time utility class providing factory methods for time-related objects * and access to system time functions

Methods

fn now() → Int64
* Returns the current system time in milliseconds * * @return current time in milliseconds since epoch
fn sleep(ms: Int64) → Nothing
* Pauses execution for the specified duration * * @param ms the number of milliseconds to sleep
fn newTimer() → Timer
* Creates a new Timer instance * * @return a new Timer ready to measure elapsed time
fn newStopwatch() → Stopwatch
* Creates a new Stopwatch instance * * @return a new Stopwatch ready to measure elapsed time
fn newDuration(seconds: Int64) → Duration
* Creates a Duration from seconds * * @param seconds the number of seconds * @return a new Duration instance
fn durationFromMinutes(minutes: Int64) → Duration
* Creates a Duration from minutes * * @param minutes the number of minutes * @return a new Duration instance
fn durationFromHours(hours: Int64) → Duration
* Creates a Duration from hours * * @param hours the number of hours * @return a new Duration instance

class Timer

* A timer for measuring elapsed time between start and stop * * Call start() to begin timing, stop() to end timing, * and elapsed() to get the measured duration.

Fields

startTimeInt64 The start time in milliseconds
endTimeInt64 The stop time in milliseconds (0 if not stopped)

Methods

fn new() → Timer
* Creates a new Timer (not started) * * @return a new Timer instance
fn start() → Nothing
* Starts the timer, recording the current time
fn stop() → Nothing
* Stops the timer, recording the end time
fn elapsed() → Int64
* Returns the elapsed time in milliseconds * * If the timer is still running (stop not called), * returns the time from start to now. * * @return elapsed time in milliseconds
fn elapsedSeconds() → Int64
* Returns the elapsed time in whole seconds * * @return elapsed time in seconds (truncated)