develooper Front page | perl.beginners | Postings from December 2002

Standard time and calendar functions for Perl?

Thread Next
R. Joseph Newton
December 8, 2002 23:06
Standard time and calendar functions for Perl?
Message ID:

I feel like I've just spent my afternoon reinventing the wheel.  I'm
working on a Perl script that is highly dependent on relative time, and I
find myself having to create low-level functionality such as:

sub NextMonth {
  my ($Month) = @_;
  %NextMonths = qw(
  Jan Feb
  Feb Mar
  Mar Apr
  Apr May
  May Jun
  Jun Jul
  Jul Aug
  Aug Sep
  Sep Oct
  Oct Nov
  Nov Dec
  Dec Jan);
  return $NextMonths{'$Month'};

I've had to write similar functions for detedting leap years, and right
now am holding back from just writing a whole damn library of essential
time.  I wouldn't mind doing this in a separate project if need be, but
it's just distracting as all get out when the subject of my program is
whether to insert a weather closure alert into a weather report page or
pass the page through unchanged.  Essentially, I'm looking for functions
whose signatures, in C++ argot, would resemble:

Date AddDays(Date baseDate, long offset);
Date AddMonths(Date baseDate, long offset);
Date AddYear(Date baseDate, long offset);
Time AddHours(Time baseTime long offset);
Time AddMinutes(Time baseTime long offset);
Time AddSeconds(Time baseTime, double offset);

Is there anything out there like this for Perl?  If they're not, I guess
I'll shrug my shoulders, roll my eyes, and write them myself.  I'd really
like to mone on with my project, though.



Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About