NAME
Calendar::Functions - A module containing functions for dates and calendars.
SYNOPSIS
use Calendar::Functions qw();
$ext = ext($day);
$moty = moty($monthname);
$monthname = moty($moty);
$dotw = dotw($dayname);
$dayname = dotw($dotw);
use Calendar::Functions qw(:dates);
my $dateobj = encode_date($day,$month,$year);
($day,$month,$year) = decode_date($dateobj);
$duration = diff_dates($dateobj1, $dateobj2);
$hash = month_list($month,$year);
$days = month_days($month,$year);
use Calendar::Functions qw(:form);
$str = format_date( $fmt, $day, $month, $year, $dotw);
$str = reformat_date( $date, $fmt1, $fmt2 );
use Calendar::Functions qw(:all);
$dotw = dotw3($day,$month,$year);
$dotw = dotw3($dateobj);
fail_range($year);
DESCRIPTION
The module is intended to provide numerous support functions for other date and/or calendar functions
EXPORT
ext, moty, dotw
dates: encode_date, decode_date, diff_dates,
month_list, month_days
form: format_date, reformat_date
all: encode_date, decode_date, diff_dates,
month_list, month_days,
format_date, reformat_date,
ext, moty, dotw,
dotw3, fail_range
METHODS
- encode_date( DD, MM, YYYY )
-
Translates the given date values into a date object or number.
- decode_date( date )
-
Translates the given date values into a date object or number.
- diff_dates( date, date )
-
Using the appropriate module finds the duration between the two dates.
- month_list( month, year )
-
Given a numerical month (1-12) and year, a hash of days for that month are returned, with each day being the key and the day of the week being the value.
- dotw3( day, month, year | dateobj )
-
Given a numerical representation of a date (day, month (1-12) and year), or a date object (as provided by encode_date), the value for day of the week is calculated and returned.
- month_days( month, year )
-
For any given month (1-12) and year, will return the number of days in that month. Note that this relies on other modules to give an accurate leap year calculation.
- format_date( fmt, day, mon, year [, dotw])
-
transposes the standard date values into a formatted string.
- reformat_date( date, form1, form1 )
-
transposes the standard date values into a formatted string.
- ext( day )
-
Returns the extension associated with the given day value.
- dotw( day | dayname )
-
Returns the day number (0..6) if passed the day name, or the day name if passed a numeric.
- moty( month | monthname )
-
Returns the month number (1..12) if passed the month name, or the month name if passed a numeric.
- fail_range( year )
-
Returns true or false based on whether the date given will break the basic date range, 01-01-1902 to 31-12-2037.
DATE FORMATS
- Parameters
-
The date formatting parameters passed to the two formatting functions can take many different formats. A formatting string can contain several key strings, which will be replaced with date components. The following are key strings which are currently supported:
DD MM YYYY DAY MONTH DDEXT DMY MDY YMD MABV DABV
The first three are tranlated into the numerical day/month/year strings. The DAY format is translated into the day of the week name, and MONTH is the month name. DDEXT is the day with the appropriate suffix, eg 1st, 22nd or 13th. DMY, MDY and YMD default to '13-09-1965' (DMY) style strings. MABV and DABV provide 3 letter abbreviations of MONTH and DAY respectively.
DATE MODULES
Internal to this module is some date comparison code. As a consequence this requires some date modules that can handle a wide range of dates. There are three modules which are tested for you, these are, in order of preference, DateTime, Date::ICal and Time::Local.
Each module has the ability to handle dates, although only Time::Local exists in the core release of Perl. Unfortunately Time::Local is limited by the Operating System. On a 32bit machine this limit means dates before 1st January 1902 and after 31st December 2037 will not be represented. If this date range is well within your scope, then you can safely allow the module to use Time::Local. However, should you require a date range that exceedes this range, then it is recommended that you install one of the two other modules.
ERROR HANDLING
In the event that Time::Local is being used and dates that exceed the range of 1st January 1902 to 31st December 2037 are passed, an undef is returned.
SEE ALSO
L<perl>
L<Date::ICal>
L<DateTime>
L<Time::Local>
BUGS & ENHANCEMENTS
There appears to be a problem with Time::Local not returning the correct number of seconds for localtime to distinguish the correct day of the week. I suspect, even though timegm() is being used, offsets are getting set. Now using 12:00pm as the time of day to try and avoid offset strangeness.
DateTime after 0.16 implements delta_days differently from previous versions. Until I have time to rewrite this module to be compatible with both versions, I won't be supporting DateTime 0.17 or greater.
If you think you've found a bug, send details and patches (if you have one) to <modules@missbarbell.co.uk>.
If you have a suggestion for an enhancement, though I can't promise to implement it, please send details to <modules@missbarbell.co.uk>.
AUTHOR
Barbie, <barbie@cpan.org> for Miss Barbell Productions http://www.missbarbell.co.uk.
THANKS TO
Dave Cross, <dave@dave.org> for creating Calendar::Simple, the newbie poster on a technical message board who inspired me to write the original wrapper code and Richard Clamp <richardc@unixbeard.co.uk> for testing the beta versions.
COPYRIGHT AND LICENSE
Copyright (C) 2002-2003 Barbie for Miss Barbell Productions
All Rights Reserved.
This module is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.