Name

SPVM::Time::Seconds - Seconds

Description

The Time::Seconds class in SPVM has methods to manipulate seconds to calculate dates and times.

Usage

use Time::Piece;
use Time::Seconds;

my $tp = Time::Piece->localtime;
$tp = $tp->add(Time::Seconds->ONE_DAY);

my $tp2 = Time::Piece->localtime;
my $tsec = $tp->subtract_tp($tp2);

say "Difference is: " . $tsec->days;

Details

The class makes the assumption that there are 24 hours in a day, 7 days in a week, 365.24225 days in a year and 12 months in a year.

Interfaces

Cloneable

Fields

seconds

has seconds : ro long;

Seconds.

Class Methods

new

static method new : Time::Seconds ($second : long = 0);

Creates a new Time::Seconds object given seconds $second, and returns it.

ONE_MINUTE

static method ONE_MINUTE : Time::Seconds ();

Creates a new Time::Seconds object given the seconds correspond to 1 minute, and returns it.

ONE_HOUR

static method ONE_HOUR : Time::Seconds ();

Creates a new Time::Seconds object given the seconds correspond to 1 hour, and returns it.

ONE_DAY

static method ONE_DAY : Time::Seconds ();

Creates a new Time::Seconds object given the seconds correspond to 1 day, and returns it.

ONE_WEEK

static method ONE_WEEK : Time::Seconds ();

Creates a new Time::Seconds object given the seconds correspond to 1 week, and returns it.

ONE_MONTH

static method ONE_MONTH : Time::Seconds ();

Creates a new Time::Seconds object given the seconds correspond to 1 month, and returns it.

ONE_YEAR

static method ONE_YEAR : Time::Seconds ();

Creates a new Time::Seconds object given the seconds correspond to 1 year, and returns it.

ONE_FINANCIAL_MONTH

static method ONE_FINANCIAL_MONTH : Time::Seconds ();

Creates a new Time::Seconds object given the seconds correspond to 1 financial day, and returns it.

LEAP_YEAR

static method LEAP_YEAR : Time::Seconds ();

Creates a new Time::Seconds object given the seconds correspond to 1 year that is a leap year, and returns it.

NON_LEAP_YEAR

static method NON_LEAP_YEAR : Time::Seconds ();

Creates a new Time::Seconds object given the seconds correspond to 1 year that is not a leap year, and returns it.

Instance Methods

add

method add : Time::Seconds ($seconds : long);

Creates a new Time::Seconds object with seconds $seconds added to the current seconds, and returns it.

subtract

method subtract : Time::Seconds ($seconds : long);

Creates a new Time::Seconds object with seconds $seconds subtracted from the current seconds, and returns it.

minutes

method minutes : double ();

Calculates the minutes, and returns it.

hours

method hours : double ();

Calculates the hours, and returns it.

days

method days : double ();

Calculates the days, and returns it.

weeks

method weeks : double ();

Calculates the weeks, and returns it.

months

method months : double ();

Calculates the months, and returns it.

financial_months

method financial_months : double ();

Calculates the financial months, and returns it.

years

method years : double ();

Calculates the financial years, and returns it.

clone

method clone : Time::Seconds ();

Clones this instance and returns it.

pretty

method pretty : string ();

Interprets "seconds" as a delta and returns an English expression.

Copyright & License

Copyright (c) 2023 Yuki Kimoto

MIT License