Name

SPVM::Sys::Time - System Calls for Time Manipulation

Description

The Sys::Process class in SPVM has methods to call system calls for time manipulation.

Usage

use Sys::Time;

my $epoch = Sys::Time->time;

my $time_info_local = Sys::Time->localtime($epoch);

my $time_info_utc = Sys::Time->gmtime($epoch);

Class Methods

time

static method time : long ();

Calls the time function and returns its return value.

localtime

static method localtime : Sys::Time::Tm ($time_ref : long*);

Calls the localtime function and creates a Sys::Time::Tm object given its return value, and returns it.

gmtime

static method gmtime : Sys::Time::Tm ($time_ref : long*);

Calls the gmtime function and creates a Sys::Time::Tm object given its return value, and returns it.

gettimeofday

static method gettimeofday : int ($tv : Sys::Time::Timeval, $tz : Sys::Time::Timezone);

Calls the gmtime function and creates a Sys::Time::Timeval object given its return value, and returns it.

Exceptions:

If the gettimeofday function failed, an exception is thrown with eval_error_id set to the basic type ID of the Error::System.

clock

static method clock : long ()

Calls the clock function, and returns its return value.

Exceptions:

If the clock function failed, an exception is thrown with eval_error_id set to the basic type ID of the Error::System.

clock_gettime

static method clock_gettime : int ($clk_id : int, $tp : Sys::Time::Timespec);

Calls the clock_gettime function, and returns its return value.

See Sys::Time::Constant about constant values given to $clk_id.

Exceptions:

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

If the clock_gettime function failed, an exception is thrown with eval_error_id set to the basic type ID of the Error::System.

clock_getres

static method clock_getres : int ($clk_id : int, $res : Sys::Time::Timespec);

Calls the clock_getres function, and returns its return value.

See Sys::Time::Constant about constant values given to $clk_id.

Exceptions:

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

If the clock_getres function failed, an exception is thrown with eval_error_id set to the basic type ID of the Error::System.

setitimer

static method setitimer : int ($which : int, $new_value : Sys::Time::Itimerval, $old_value : Sys::Time::Itimerval)

Calls the setitimer function, and returns its return value.

See Sys::Time::Constant about constant values given to $which.

Exceptions:

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

If the clock_getres function failed, an exception is thrown with eval_error_id set to the basic type ID of the Error::System.

In Windows the following exception is thrown with eval_error_id set to the basic type ID of the Error::NotSupported class. setitimer is not supported in this system(defined(_WIN32)).

getitimer

static method getitimer : int ($which : int, $curr_value : Sys::Time::Itimerval);

Calls the getitimer function, and returns its return value.

See Sys::Time::Constant about constant values given to $which.

Exceptions:

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

If the getitimer function failed, an exception is thrown with eval_error_id set to the basic type ID of the Error::System.

In Windows the following exception is thrown with eval_error_id set to the basic type ID of the Error::NotSupported class. getitimer is not supported in this system(defined(_WIN32)).

times

static method times : long ($buffer : Sys::Time::Tms);

Calls the times function, and returns its return value.

Exceptions:

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

If the times function failed, an exception is thrown with eval_error_id set to the basic type ID of the Error::System.

In Windows the following exception is thrown with eval_error_id set to the basic type ID of the Error::NotSupported class. times is not supported in this system(defined(_WIN32)).

clock_nanosleep

static method clock_nanosleep : int ($clockid : int, $flags : int, $request : Sys::Time::Timespec, $remain : Sys::Time::Timespec);

Calls the clock_nanosleep function, and returns its return value.

See Sys::Time::Constant about constant values given to $clockid and $flags.

Exceptions:

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

In Mac the following exception is thrown with eval_error_id set to the basic type ID of the Error::NotSupported class. clock_nanosleep is not supported in this system(__APPLE__).

nanosleep

static method nanosleep : int ($rqtp : Sys::Time::Timespec, $rmtp : Sys::Time::Timespec);

Calls the nanosleep function, and returns its return value.

Exceptions:

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

If the nanosleep function failed, an exception is thrown with eval_error_id set to the basic type ID of the Error::System.

utime

static method utime : int ($filename : string, $times : Sys::Time::Utimbuf);

Calls the utime function, and returns its return value.

utimes

static method utimes : int ($filename : string, $times : Sys::Time::Timeval[]);

Calls the utimes function, and returns its return value.

The utime() system call changes the access and modification times of the inode specified by filename to the actime and modtime fields of times respectively.

Copyright & License

Copyright (c) 2023 Yuki Kimoto

MIT License