NAME Date::Tie - a perlish interface to ISO dates
SYNOPSIS use Date::Tie;
tie my %date, 'Date::Tie', year => 2001, month => 11, day => 9;
$date{year}++;
$date{month} += 12; # 2003-11-09
# you can also do this
my $date = Date::Tie->new( year => 2001, month => 11, day => 9 );
$date->{year}++;
$date->{month} += 12; # 2003-11-09
$date{weekday} = 0; # sunday at the start of this week
$date{weekday} = 7; # sunday at the end of this week
$date{weekday} = 14; # sunday next week
$date{tz} = '-0300'; # change timezone
$date{tzhour}++; # increment timezone
DESCRIPTION
Date::Tie is an attempt to simplify date operations syntax.
Date::Tie manages a hash containing the keys: epoch, year, month, day, hour, minute, second, yearday, week, weekday, weekyear, tz, tzhour, tzminute.
'week' is the week number in the year.
'day' and 'monthday' refer to the same entity.
'weekyear' is the year number when using week notation. It is often NOT EQUAL to 'year'. Changing 'weekyear' will leave you with the same week and weekday, while changing 'year' will leave you with the same month and monthday.
'epoch' is the local epoch. It changes when timezone ('tzhour', 'tzminute') changes.
'tz' is the timezone as hundreds (-0030). It is not always the same as (tzhour . tzminute), which in this case would be +00-30.
Whenever a new value is stored, it will change the other keys following the ISO date rules.
For example: print $a{hour}, ":", $a{minute}; # 00 59 $a{minute}++; print $a{hour}, ":", $a{minute}; # 01 00
The hash is created with the current value of gmtime, and timezone +0000.
ISO 8601 BASICS
Day of year starts with 001.
Day of week starts with 1 and is a monday.
Week starts with 01 and is the first week of the year that has a thursday. Week 01 often begins in the previous year.
CAVEATS
Reading time zone -0030 with ('tzhour' . 'tzminute') gives +00-30. Use 'tz' to get -0030.
TODO
test fractions of seconds
HISTORY
0.04 yearday, weekday, week, weekyear
better storage
initializes to 'now'.
timezones
more tests
0.03 STORE rewritten
examples work
0.02 Make it a real module
0.01 I started this when dLux asked:
> What about this kind of syntax:
> my $mydate = new XXXX::Date "2001-11-07";
> # somewhere later in the code
> my $duedate = $mydate + 14 * XXX::Date::DAY;
> my $duedate = $mydate + 14 * DAY;
> my $duedate = $mydate->add(12, DAYS);
> my $duedate = $mydate->add(day => 12);
> my $duedate = $mydate + "12 days";
> my $duedate = $mydate + "12 days and 4 hours and 3 seconds"; # :-)
AUTHOR Flávio Soibelmann Glock (fglock@pucrs.br)
1 POD Error
The following errors were encountered while parsing the POD:
- Around line 353:
Non-ASCII character seen before =encoding in 'Flávio'. Assuming CP1252