Name

SPVM::Sys::Time::Timespec - struct timespec in the C language

Description

Sys::Time::Timespec class in SPVM represents struct timespec in the C language.

Usage

use Sys::Time::Timespec;

my $ts = Sys::Time::Timespec->new;

my $ts = Sys::Time::Timespec->new(5, 300_000_000);

my $ts_sec = $ts->tv_sec;
$ts->set_tv_sec(12);

my $ts_nsec = $ts->tv_nsec;
$ts->set_tv_nsec(34);

Interfaces

Class Methods

new

static method new : Sys::Time::Timespec ($tv_sec : long = 0, $tv_nsec : long = 0);

Creates a new Sys::Time::Timespec object with the given "tv_sec" and "tv_nsec".

Before creating the object, this method calls "check" to validate the range of the arguments. If the arguments are invalid (e.g., "tv_nsec" is out of the range [0, 999,999,999]), an exception is thrown.

The internal struct timespec is allocated in memory and managed by this object.

Example:

my $ts = Sys::Time::Timespec->new(1737158400L, 500L);

check

static method check : void ($tv_sec : long, $tv_nsec : long);

Validates the range of the given "tv_sec" and "tv_nsec".

If "tv_nsec" is not greater than or equal to 0 and less than or equal to 999,999,999, an exception is thrown.

Instance Methods

tv_sec

method tv_sec : long ()

Returns tv_sec.

set_tv_sec

method set_tv_sec : void ($ts_sec : long);

Sets tv_sec.

tv_nsec

method tv_nsec : long ()

Returns tv_nsec.

set_tv_nsec

method set_tv_nsec : void ($ts_nsec : long);

Sets tv_nsec.

clone

method clone : Sys::Time::Timespec ();

Creates a new Sys::Time::Timespec object that is a copy of the current instance.

The new object will have the same "tv_sec" and "tv_nsec" values as the original.

DESTROY

native method DESTROY : void ();

The destructor.

See Also

Copyright & License

Copyright (c) 2023 Yuki Kimoto

MIT License