Name

SPVM::Go::Duration_1l - A duration of time (Go-style, long)

Description

Go::Duration_1l class in SPVM represents the elapsed time between two instants as a long nanosecond count.

This class is defined as a mulnum_t, which means it can be handled efficiently in memory.

Usage

use Go::Duration_1l;

# Create from nanoseconds
my $duration = Go::Duration_1l->new(500_000_000L);

# Create from seconds (double)
my $duration = Go::Duration_1l->new_from_sec(1.5);

Fields

has nsec : long;

The number of nanoseconds represented by the duration. For example, 1 second is stored as 1,000,000,000.

Class Methods

new

static method new : Go::Duration_1l ($nsec : long = 0);

Creates a new Go::Duration_1l object from the given nanoseconds.

See time.Duration.

new_from_timespec

static method new_from_timespec : Go::Duration_1l ($timespec : Sys::Time::Timespec);

Creates a new Go::Duration_1l object from a Sys::Time::Timespec object.

It throws an exception if the tv_sec of the $timespec exceeds the range that can be represented as nanoseconds in a long type.

new_from_sec

static method new_from_sec : Go::Duration_1l ($seconds : double);

Creates a new Go::Duration_1l object from seconds (double).

to_timespec

static method to_timespec : Sys::Time::Timespec ($duration : Go::Duration_1l);

Converts the Go::Duration_1l object to a Sys::Time::Timespec object.

This method correctly handles negative durations by normalizing the tv_nsec field to a positive value (0 to 999,999,999).

to_sec

static method to_sec : double ($duration : Go::Duration_1l);

Returns the duration as a floating point number of seconds.

See Duration.Seconds.

See Also

Author

Yuki Kimoto kimoto.yuki@gmail.com

Copyright & License

Copyright (c) 2026 Yuki Kimoto

MIT License