1 # $Id: Seconds.pm 44 2002-09-08 20:51:38Z matt $
5 use vars qw/@EXPORT @EXPORT_OK @ISA/;
24 @EXPORT_OK = qw(cs_sec cs_mon);
26 use constant ONE_MINUTE => 60;
27 use constant ONE_HOUR => 3_600;
28 use constant ONE_DAY => 86_400;
29 use constant ONE_WEEK => 604_800;
30 use constant ONE_MONTH => 2_629_744; # ONE_YEAR / 12
31 use constant ONE_REAL_MONTH => '1M';
32 use constant ONE_YEAR => 31_556_930; # 365.24225 days
33 use constant ONE_REAL_YEAR => '1Y';
34 use constant ONE_FINANCIAL_MONTH => 2_592_000; # 30 days
35 use constant LEAP_YEAR => 31_622_400; # 366 * ONE_DAY
36 use constant NON_LEAP_YEAR => 31_536_000; # 365 * ONE_DAY
38 # hacks to make Time::Piece compile once again
39 use constant cs_sec => 0;
40 use constant cs_mon => 1;
43 'fallback' => 'undef',
49 '-=' => \&subtract_from,
56 $val = 0 unless defined $val;
61 my ($lhs, $rhs, $reverse) = @_;
64 if (UNIVERSAL::isa($rhs, 'Time::Seconds')) {
68 die "Can't use non Seconds object in operator overload";
79 my ($lhs, $rhs) = _get_ovlvals(@_);
84 my ($lhs, $rhs) = _get_ovlvals(@_);
85 return Time::Seconds->new($lhs + $rhs);
91 $rhs = $rhs->seconds if UNIVERSAL::isa($rhs, 'Time::Seconds');
97 my ($lhs, $rhs) = _get_ovlvals(@_);
98 return Time::Seconds->new($lhs - $rhs);
104 $rhs = $rhs->seconds if UNIVERSAL::isa($rhs, 'Time::Seconds');
110 Time::Seconds->new(${$_[0]});
140 $s->days / 30.4368541;
143 sub financial_months {
150 $s->days / 365.24225;
158 Time::Seconds - a simple API to convert seconds to other date values
171 print "Difference is: ", $s->days, "\n";
175 This module is part of the Time::Piece distribution. It allows the user
176 to find out the number of minutes, hours, days, weeks or years in a given
177 number of seconds. It is returned by Time::Piece when you delta two
180 Time::Seconds also exports the following constants:
192 Since perl does not (yet?) support constant objects, these constants are in
193 seconds only, so you cannot, for example, do this: C<print ONE_WEEK-E<gt>minutes;>
197 The following methods are available:
199 my $val = Time::Seconds->new(SECONDS)
206 $val->financial_months; # 30 days
209 The methods make the assumption that there are 24 hours in a day, 7 days in
210 a week, 365.24225 days in a year and 12 months in a year.
211 (from The Calendar FAQ at http://www.tondering.dk/claus/calendar.html)
215 Matt Sergeant, matt@sergeant.org
217 Tobias Brox, tobiasb@tobiasb.funcom.com
219 Bal�zs Szab� (dLux), dlux@kapu.hu
223 Please see Time::Piece for the license.
227 Currently the methods aren't as efficient as they could be, for reasons of
228 clarity. This is probably a bad idea.