3 use vars qw/@EXPORT @ISA/;
19 use constant ONE_MINUTE => 60;
20 use constant ONE_HOUR => 3_600;
21 use constant ONE_DAY => 86_400;
22 use constant ONE_WEEK => 604_800;
23 use constant ONE_MONTH => 2_629_744; # ONE_YEAR / 12
24 use constant ONE_YEAR => 31_556_930; # 365.24225 days
25 use constant ONE_FINANCIAL_MONTH => 2_592_000; # 30 days
26 use constant LEAP_YEAR => 31_622_400; # 366 * ONE_DAY
27 use constant NON_LEAP_YEAR => 31_536_000; # 365 * ONE_DAY
35 '-=' => \&subtract_from,
42 $val = 0 unless defined $val;
47 my ($lhs, $rhs, $reverse) = @_;
50 if (UNIVERSAL::isa($rhs, 'Time::Seconds')) {
54 die "Can't use non Seconds object in operator overload";
65 my ($lhs, $rhs) = _get_ovlvals(@_);
70 my ($lhs, $rhs) = _get_ovlvals(@_);
71 return Time::Seconds->new($lhs + $rhs);
77 $rhs = $rhs->seconds if UNIVERSAL::isa($rhs, 'Time::Seconds');
83 my ($lhs, $rhs) = _get_ovlvals(@_);
84 return Time::Seconds->new($lhs - $rhs);
90 $rhs = $rhs->seconds if UNIVERSAL::isa($rhs, 'Time::Seconds');
96 Time::Seconds->new(${$_[0]});
126 $s->days / 30.4368541;
129 sub financial_months {
134 *f_months = \&financial_months;
138 $s->days / 365.24225;
146 Time::Seconds - a simple API to convert seconds to other date values
159 print "Difference is: ", $s->days, "\n";
163 This module is part of the Time::Piece distribution. It allows the user
164 to find out the number of minutes, hours, days, weeks or years in a given
165 number of seconds. It is returned by Time::Piece when you delta two
168 Time::Seconds also exports the following constants:
180 Since perl does not (yet?) support constant objects, these constants
181 are in seconds only, so you cannot, for example, do this: C<print
182 ONE_WEEK-E<gt>minutes;>
186 The following methods are available:
188 my $val = Time::Seconds->new(SECONDS)
195 $val->financial_months; # 30 days
198 The methods make the assumption that there are 24 hours in a day, 7 days in
199 a week, 365.24225 days in a year and 12 months in a year.
200 (from The Calendar FAQ at http://www.tondering.dk/claus/calendar.html)
204 Matt Sergeant, matt@sergeant.org
206 Tobias Brox, tobiasb@tobiasb.funcom.com
210 Please see Time::Piece for the license.
214 Currently the methods aren't as efficient as they could be, for reasons of
215 clarity. This is probably a bad idea.