Name

SPVM::Sys::Time::Util - Time Utilities

Description

Sys::Time::Util class in SPVM has utility methods to manipulate time.

Usage

use Sys::Time::Util;

Class Methods

nanoseconds_to_timespec

static method nanoseconds_to_timespec : Sys::Time::Timespec ($nanoseconds : long);

Converts nanoseconds $nanoseconds to a Sys::Time::Timespec object, and returns it.

Exceptions:

$nanoseconds must be greater than or equal to 0. Otherwise an exception is thrown.

timespec_to_nanoseconds

static method timespec_to_nanoseconds : long ($ts : Sys::Time::Timespec);

Converts the Sys::Time::Timespec object $ts to nanoseconds, and returns it.

This method could cause overflow.

Exceptions:

$ts must be defined. Otherwise an exception is thrown.

$ts->tv_sec must be greater than or equal to 0. Otherwise an exception is thrown.

$ts->tv_nsec must be greater than or equal to 0. Otherwise an exception is thrown.

microseconds_to_timeval

static method microseconds_to_timeval : Sys::Time::Timeval ($microseconds : long);

Converts microseconds $microseconds to a Sys::Time::Timeval object, and returns it.

Exceptions:

$microseconds must be greater than or equal to 0. Otherwise an exception is thrown.

timeval_to_microseconds

static method timeval_to_microseconds : double ($tv : Sys::Time::Timeval);

Converts the Sys::Time::Timeval object $tv to microseconds, and returns it.

This method could cause overflow.

Exceptions:

$tv must be defined. Otherwise an exception is thrown.

$tv->tv_sec must be greater than or equal to 0. Otherwise an exception is thrown.

$tv->tv_usec must be greater than or equal to 0. Otherwise an exception is thrown.

float_seconds_to_timespec

static method float_seconds_to_timespec : Sys::Time::Timespec ($float_seconds : double);

Converts floating seconds $float_seconds to a Sys::Time::Timespec object, and returns it.

This method may result in a loss of precision.

Exceptions:

$float_seconds must be greater than or equal to 0. Otherwise an exception is thrown.

timespec_to_float_seconds

static method timespec_to_float_seconds : double ($ts : Sys::Time::Timespec);

Converts the Sys::Time::Timespec object $ts to floating seconds, and returns it.

This method may result in a loss of precision.

Exceptions:

$ts must be defined. Otherwise an exception is thrown.

$ts->tv_sec must be greater than or equal to 0. Otherwise an exception is thrown.

$ts->tv_nsec must be greater than or equal to 0. Otherwise an exception is thrown.

float_seconds_to_timeval

static method float_seconds_to_timeval : Sys::Time::Timeval ($float_seconds : double);

Converts floating seconds $float_seconds to a Sys::Time::Timeval object, and returns it.

This method may result in a loss of precision.

Exceptions:

$float_seconds must be greater than or equal to 0. Otherwise an exception is thrown.

timeval_to_float_seconds

static method timeval_to_float_seconds : double ($tv : Sys::Time::Timeval);

Converts the Sys::Time::Timeval object $tv to floating seconds, and returns it.

This method may result in a loss of precision.

Exceptions:

$tv must be defined. Otherwise an exception is thrown.

$tv->tv_sec must be greater than or equal to 0. Otherwise an exception is thrown.

$tv->tv_usec must be greater than or equal to 0. Otherwise an exception is thrown.

float_seconds_to_nanoseconds

static method float_seconds_to_nanoseconds : long ($float_seconds : double);

Converts floating seconds $float_seconds to nanoseconds, and returns it.

This method may result in a loss of precision.

Excetpions:

$float_seconds must be greater than or equal to 0. Otherwise an exception is thrown.

nanoseconds_to_float_seconds

static method nanoseconds_to_float_seconds : double ($nanoseconds : long);

Converts nanoseconds $nanoseconds to floating seconds, and returns it.

This method may result in a loss of precision.

Excetpions:

$nanoseconds must be greater than or equal to 0. Otherwise an exception is thrown.

float_seconds_to_microseconds

static method float_seconds_to_microseconds : long ($float_seconds : double);

Converts floating seconds $float_seconds to microseconds, and returns it.

This method may result in a loss of precision.

Excetpions:

$float_seconds must be greater than or equal to 0. Otherwise an exception is thrown.

microseconds_to_float_seconds

static method microseconds_to_float_seconds : double ($microseconds : long);

Converts microseconds $microseconds to floating seconds, and returns it.

This method may result in a loss of precision.

Excetpions:

$float_seconds must be greater than or equal to 0. Otherwise an exception is thrown.

timeval_interval

static method timeval_interval : double ($tv_a : Sys::Time::Timeval, $tv_b : Sys::Time::Timeval);

Calculates $tv_b minus $tv_a and returns it as floating seconds.

This method may result in a loss of precision.

Excetpions:

$tv_a must be defined. Otherwise an exception is thrown.

$tv_b must be defined. Otherwise an exception is thrown.

timespec_interval

static method timespec_interval : double ($ts_a : Sys::Time::Timespec, $ts_b : Sys::Time::Timespec);

Calculates $ts_b minus $ts_a and returns it as floating seconds.

This method may result in a loss of precision.

Excetpions:

$ts_a must be defined. Otherwise an exception is thrown.

$ts_b must be defined. Otherwise an exception is thrown.

add_timespec

static method add_timespec : Sys::Time::Timespec ($ts : Sys::Time::Timespec, $diff_ts : Sys::Time::Timespec);

Returns $ts plus $diff_ts.

Excetpions:

$ts must be defined. Otherwise an exception is thrown.

$diff_ts must be defined. Otherwise an exception is thrown.

add_timeval

static method add_timeval : Sys::Time::Timeval ($tv : Sys::Time::Timeval, $diff_tv : Sys::Time::Timeval);

Returns $tv plus $diff_tv.

Excetpions:

$tv must be defined. Otherwise an exception is thrown.

$diff_tv must be defined. Otherwise an exception is thrown.

subtract_timespec

static method subtract_timespec : Sys::Time::Timespec ($ts : Sys::Time::Timespec, $diff_ts : Sys::Time::Timespec);

Returns $ts minus $diff_ts.

Excetpions:

$ts must be defined. Otherwise an exception is thrown.

$diff_ts must be defined. Otherwise an exception is thrown.

subtract_timeval

static method subtract_timeval : Sys::Time::Timeval ($tv : Sys::Time::Timeval, $diff_tv : Sys::Time::Timeval);

Returns $tv minus $diff_tv.

Excetpions:

$tv must be defined. Otherwise an exception is thrown.

$diff_tv must be defined. Otherwise an exception is thrown.

Copyright & License

Copyright (c) 2023 Yuki Kimoto

MIT License