Time::Seconds(3p)

Time::Seconds3p

A simple api to convert seconds to other date values

Usage

    use Time::Piece;
    use Time::Seconds;
    
    my $t = localtime;
    $t += ONE_DAY;
    
    my $t2 = localtime;
    my $s = $t - $t2;
    
    print "Difference is: ", $s->days, "\n";

Overview

This module is part of the Time::Piece distribution. It allows the user to find out the number of minutes, hours, days, weeks or years in a given number of seconds. It is returned by Time::Piece when you delta two Time::Piece objects.

Time::Seconds also exports the following constants:

    ONE_DAY
    ONE_WEEK
    ONE_HOUR
    ONE_MINUTE
    ONE_MONTH
    ONE_YEAR
    ONE_FINANCIAL_MONTH
    LEAP_YEAR
    NON_LEAP_YEAR

Since perl does not (yet?) support constant objects, these constants are in seconds only, so you cannot, for example, do this: "print ONE_WEEK->minutes;"

Methods

The following methods are available:

    my $val = Time::Seconds->new(SECONDS)
    $val->seconds;
    $val->minutes;
    $val->hours;
    $val->days;
    $val->weeks;
    $val->months;
    $val->financial_months; # 30 days
    $val->years;
    $val->pretty; # gives English representation of the delta

The usual arithmetic (+,-,+=,-=) is also available on the objects.

The methods make 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. (from The Calendar FAQ at http://www.tondering.dk/claus/calendar.html)

Releases

32 releases since OpenBSD 5.0; the text changed 20 times.

  1. 5.0–5.3
  2. 5.4–5.5
  3. 5.6
  4. 5.7
  5. 5.8–5.9
  6. 6.0
  7. 6.1
  8. 6.2
  9. 6.3–6.4
  10. 6.5
  11. 6.6
  12. 6.7
  13. 6.8
  14. 6.9–7.2
  15. 7.3
  16. 7.4
  17. 7.5
  18. 7.6
  19. 7.7–7.8
  20. 7.9
  21. 8.0

Author

Matt Sergeant, [email protected]

Tobias Brox, [email protected]

Balázs Szabó (dLux), [email protected]

Bugs

Currently the methods aren't as efficient as they could be, for reasons of clarity. This is probably a bad idea.

From man 8.0-current-20261101 in OpenBSD 8.0-current (2026-11-01). Parsed by carta from the page's man source.