Time::Seconds(3pm)

πŸ’… Time::Seconds β€” the perl manual page, but make it cute

okay so bestie, this is Time::Seconds, straight out of the Perl Programmers Reference Guide, and it's literally the glow-up your seconds deserved ✨


🌸 NAME 🌸

Time::Seconds β€” a simple API to convert seconds to other date values πŸŽ€


✨ SYNOPSIS ✨

like, here's the whole vibe in one go, no cap:

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";

πŸ’– DESCRIPTION πŸ’–

So this module is part of the Time::Piece distribution, and its whole job is giving you the number of minutes, hours, days, weeks or years hiding inside some number of seconds. It's what Time::Piece hands back to you when you delta two Time::Piece objects β€” like, you subtract one from the other and boom, you get one of these πŸ¦‹

Time::Seconds also exports these constants:

ONE_DAY
ONE_WEEK
ONE_HOUR
ONE_MINUTE
ONE_MONTH
ONE_YEAR
ONE_FINANCIAL_MONTH
LEAP_YEAR
NON_LEAP_YEAR
⚠️ real talk though: since perl does not (yet?) support constant objects, these constants are in seconds only. So you literally cannot do this: print ONE_WEEK->minutes; β€” yeah, tragic, i know 😭

πŸ‘‘ METHODS πŸ‘‘

here's the lineup, bestie:

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, slay πŸ’…

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) 🧚


🫢 AUTHOR 🫢

  • Matt Sergeant, matt@sergeant.org
  • Tobias Brox, tobiasb@tobiasb.funcom.com
  • BalΓ‘zs SzabΓ³ (dLux), dlux@kapu.hu

icons, all of them πŸ‘‘


Copyright 2001, Larry Wall.

This module is free software, you may distribute it under the same terms as Perl. πŸ“


πŸ’€ Bugs πŸ’€

Currently the methods aren't as efficient as they could be, for reasons of clarity. This is probably a bad idea. πŸ™ˆ (not me reading that and going "bestie... why" β€” but it's in the docs, so it stays, periodt)


and that's the whole page! πŸŽ€ this tea was served up in perl v5.42.3, dated 2026-11-03, in Time::Seconds(3pm) β€” k byeee, go convert some seconds πŸ’œ

πŸ“¦ where this page comes from