Date and Time Perl modules - CPAN modules that deal with dates, times, and related topics.
$Header: /home/cvs/lpm/meetings/dates2.html,v 1.1.1.1 2001/02/12 03:23:29 rbowen Exp $
This is a list of the various Date and Time modules available on CPAN, and an attempt to put in some coherent form what they all do, and what modules you should/can use for a given task.
There are a huge number of Date and Time modules on CPAN, and it can be rather difficult to keep track of what they all do, what the differences are, and which ones are best for a particular task.
This list is in no particular order at the moment, but hopefully it will take some reasoable shape over the next few versions of this document.
Author: unattributed
Description: efficiently compute time from local and GMT time
Time::Local provides the counterpart to the builtin Perl functions
localtime and gmtime. It gives you a time value given the
components of time:
$time = timelocal($sec,$min,$hours,$mday,$mon,$year);
$time = time($sec,$min,$hours,$mday,$mon,$year);
Example:
use Time::Local;
$time = timelocal(0, 0, 8, 25, 9, 71);
# What was the time when I was born?
gmtime, object interface
Author: Time Christiansen
Description: by-name interface to Perl's built-in C<gmtime> function
Using thie module overrides the built-in gmtime function with a version
that returns a Time::tm object. This gives you a way to get at the
various components of the time by name. These methods are: sec, min,
hour, mday, mon, year, wyday, yday, and isdst.
Example:
use Time::gmtime;
$gm = gmtime;
print 'Today is ' . ($gm->mon + 1) . '/' . $gm->mday .
'/' . ($gm->year + 1900) . "\n";
Note that months start with 0 being January. This is for easy indexing into an array of month names, since arrays start counting at 0.
Note also that the year is offset by 1900. No, this is not a Y2K problem
localtime, object interface
Author: Time Christiansen
Description: by-name interface to Perl's built-in C<localtime> function
Using this module overrides the built-in localtime function with a version
that returns a Time::tm object. This gives you a way to get at the
various components of the time by name. These methods are: sec, min,
hour, mday, mon, year, wyday, yday, and isdst.
Example:
use Time::localtime;
$lt = localtime;
print 'Today is ' . ($lt->mon + 1) . '/' . $lt->mday .
'/' . ($lt->year + 1900) . "\n";
Note that months start with 0 being January. This is for easy indexing into an array of month names, since arrays start counting at 0.
Note also that the year is offset by 1900. No, this is not a Y2K problem
Author: Time Christiansen
Description: internal object used by Time::gmtime and Time::localtime
This module is not to be used by itself, but is a class used by
Time::gmtime and Time::localtime
Author: Peter Santoro
Description: Calculate time availability
After reading the docs twice, I have no idea what this module does.
Author: James A Duncan
Description: Convert from standard time to swatch 'beat' time
Swatch 'beat' time is a strange concept of dividing up the day into
1000 beats, each of which is 1 minute, 26.4 seconds. I'm not sure
what purpose this serves, but this module converts from time()
to the Swatch beat time.
use Time::Beat qw( beattime );
my $beat = beattime(time());
Author: David Muir Sharnoff
Description: Format times ala POSIX asctime
An enormously useful module, Time::CTime lets you take a time
value and put it into any format. Time::CTime exports three
functions: ctime, asctime, and, the most useful one,
strftime.
strftime allows you to provide a template, which is then used
to format the time value. ctime and asctime return the time
in a standard format.
The templates available for strftime are detailed in the
documentation, and will be discussed in more detail in another
document in this series. They look like a percent sign (%) and
a letter. Each combination represents one formatting.
So, for example, you might do the following:
use Time::CTime;
print strftime('%b %o, %U', localtime(time));
which would give a result like:
Nov 16th, 2000
Considering the amount of code that I see with custom code to format time in various ways, it would see that a lot of people don't know about this module.
The documentation for the module encourages you to use Posix,
which contains the same functionality. However, Posix is very
big, so if this is all that you are looking for, you might be
better off to stick with Time::CTime.
Author: David Muir Sharnoff
Description: simply report the number of days in a month
As the name suggests, this module does just one thing - tells you how many days are in a particular month.
use Time::DaysInMonth;
$days = days_in($year, $month);
In this case, $year is the full 4-digit year, and $month is
the month number, starting with January as 1.
Time::DaysInMonth also exports an is_leap function which
tells you whether a particular year is a leap year.
Author: David Muir Sharnoff
Description: Julian calendar manipulations
Julian dates are a way to express the date as a number of days since some fixed time in the past. For reasons that I won't bore you with here, that date is January 1, 4713 B.C. Eventually, I'll provide a link to more information.
Time::JulianDay provides a variety of functions for dealing
with conversions between Julian dates and Gregorian dates.
This is one of my favorite date/time modules for a very simple reason. Epoch time is very limiting. It locks you into an extremely narrow window of time - from Jan 1, 1970, until Monday, January 18, 2038, at about quarter past 10 in the evening.
> perl -e 'print scalar localtime(2147483647)'
Mon Jan 18 22:14:07 2038
> perl -e 'print scalar localtime(2147483648)'
Fri Dec 13 14:45:52 1901
Time::JulianDay allows you to stretch this range a lot farther
forward and backwards, but still express the date in a single number.
Of course, if you want to express the day of the year, and the year
itself, as separate pieces of data, you can stretch your range even
farther. It all depends what you're trying to do.
Author: David Muir Sharnoff
Description: date parsing both relative and absolute
This module is just awesome. David Muir Sharnoff is a god. Time::ParseDate takes
dates in arbitrary formats and converts them into epoch time. The list of
acceptable date and time formats accounts for two pages of the documentation.
Time::ParseDate is exceptionally useful in situations where a user is able
to enter a date, and there is no way to enforce that the date come in in a
particular format. Because the user could enter '30 nov 2000', 'November 20th,
2000', or '11/20/2000', or any number of other things, you need to be able
to understand any of these formats and get the right answer. Time::ParseDate
does this, and much more.
Time::ParseDate exports the function parsedate(), which takes a string, and
an optional hash of options, as arguments, and returns the number of seconds
since January 1, 1970. The various options are such things as UK, which
tells it to expect UK-style date ordering (dd/mm rather than mm/dd), and NOW,
which can specify that relative dates are relative to a specified time,
rather than the time at which the code is run.
Author: Patrick Ryan
Description: A Perl module to deal with time periods.
Time::Period tells you if a given time is within a specified period. While
this is just a < or > comparison, it is very handy to have most of this
logic done for you.
The period can be defined in rather convoluted detail, and so this is more than simply figuring out if a time was yesterday. You can, for example, determine if a particular time was in Jaunary or February (of any year) or if it was on a Tuesday, or whether it was between 1 and 3 pm.
Author: Rich Bowen
Description: Store times in a portable format
I wrote this. It seemed like a good idea at the time. I think I'll remove it now.
Time::Timezone
Time::Unix
Time::Zone
TIme::HiRes
Time::Object
Time::Seconds
Time::Warp
Date::Business
Date::Christmas
Date::Convert
Date::Discordian
Date::Easter
Date::Format
Date::Horoscope
Date::ISO
Date::Interval
Date::Language
Date::Language::Austrian
Date::Language::Czech
Date::Language::Dutch
Date::Language::English
Date::Language::French
Date::Language::German
Date::Language::Italian
Date::Language::Norwegian
Date::Manip
Date::Maya
Date::Ordinal
Date::Parse
Date::Calc
Dte::GetDate
Date::getdate
Date::Lima
Astro::SunTime
Astro::Time
Audio::Tools:Time
BSD::ITimer
BingoX::Time
CIPP::Runtime
Convert::Ethiopic::Time
Cz::Time
DateTime::Precise
Event::timer
EventServer::Gettimeofday
IPC::Run::Timer
MIDI::Realtime
Net::Jabber::Query::Time
Net::Time
Persistent::DataType::DateTime
Proc::times
QTimer
SYMM::SMIL::TimelineBase
Tangram::DMDateTime
Tangram::RawDateTime
Tangram::RawTime
Tie::ClockTimer
WDDX::Datetime
Win32::ASP::Field::datetime
Win32::ASP::Field::timestamp
Apache::HeavyCGI::Date
DBIx::HTMLView::Date
HTML::Widgets::DateEntry
HTTP::Date
Locale::Date
Mail::Field::Date
Palm::Datebook
PlotCalendar::DateDesc
PlotCalendar::DateTools
PlotCalendar::Day
PlotCalendar::Month
Tk::Date
XML::XQL::Date
CGI::WeT::Modules::Calendar
Calendar::CSA
Calendar::Hebrew
Cdk::Calendar
HTML::CalendarMonth
Locale::Hebrew::Calendar