Blame lib/Date/Manip/Date.pod

Packit 95306a
# Copyright (c) 1995-2017 Sullivan Beck. All rights reserved.
Packit 95306a
# This program is free software; you can redistribute it and/or modify it
Packit 95306a
# under the same terms as Perl itself.
Packit 95306a
Packit 95306a
=pod
Packit 95306a
Packit 95306a
=head1 NAME
Packit 95306a
Packit 95306a
Date::Manip::Date - Methods for working with dates
Packit 95306a
Packit 95306a
=head1 SYNOPSIS
Packit 95306a
Packit 95306a
   use Date::Manip::Date;
Packit 95306a
   $date = new Date::Manip::Date;
Packit 95306a
Packit 95306a
=head1 DESCRIPTION
Packit 95306a
Packit 95306a
This module works specifically with date objects.
Packit 95306a
Packit 95306a
Although the word date is used extensively here, it is actually
Packit 95306a
somewhat misleading.  Date::Manip works with the full calendar date
Packit 95306a
(year, month, day, and week when appropriate), time of day (hour,
Packit 95306a
minute, second), and time zone.  It doesn't work with fractional
Packit 95306a
seconds.
Packit 95306a
Packit 95306a
=head1 METHODS
Packit 95306a
Packit 95306a
=over 4
Packit 95306a
Packit 95306a
=item B<base>
Packit 95306a
Packit 95306a
=item B<config>
Packit 95306a
Packit 95306a
=item B<err>
Packit 95306a
Packit 95306a
=item B<is_date>
Packit 95306a
Packit 95306a
=item B<is_delta>
Packit 95306a
Packit 95306a
=item B<is_recur>
Packit 95306a
Packit 95306a
=item B<new>
Packit 95306a
Packit 95306a
=item B<new_config>
Packit 95306a
Packit 95306a
=item B<new_date>
Packit 95306a
Packit 95306a
=item B<new_delta>
Packit 95306a
Packit 95306a
=item B<new_recur>
Packit 95306a
Packit 95306a
=item B<tz>
Packit 95306a
Packit 95306a
Please refer to the Date::Manip::Obj documentation for these methods.
Packit 95306a
Packit 95306a
=item B<calc>
Packit 95306a
Packit 95306a
   $date2 = $date->calc($delta [,$subtract]);
Packit 95306a
   $delta = $date->calc($date2 [,$subtract] [,$mode]);
Packit 95306a
Packit 95306a
Please refer to the Date::Manip::Calc documentation for details.
Packit 95306a
Packit 95306a
=item B<cmp>
Packit 95306a
Packit 95306a
   $val = $date1->cmp($date2);
Packit 95306a
Packit 95306a
This compares two different dates (both of which must be valid date
Packit 95306a
objects). It returns -1, 0, or 1 similar to the cmp or <=> operators
Packit 95306a
in perl. The comparison will automatically handle time zone differences
Packit 95306a
between the two dates (i.e. they will be sorted in order as they
Packit 95306a
appear in the GMT zone).
Packit 95306a
Packit 95306a
A warning is printed if either of the date objects does not include
Packit 95306a
a valid date.
Packit 95306a
Packit 95306a
=item B<complete>
Packit 95306a
Packit 95306a
   $flag = $date->complete([$field]);
Packit 95306a
Packit 95306a
This tests the date stored in the object to see if it is complete or
Packit 95306a
truncated (see below for a discussion of this).
Packit 95306a
Packit 95306a
If no $field is passed in, it returns 1 if the date is complete, or
Packit 95306a
0 if it was truncated and default values have been supplied.
Packit 95306a
Packit 95306a
If $field is passed in, it may be one of: m, d, h, mn, s . It will
Packit 95306a
return 1 if the value for that field was specified, or 0 if a
Packit 95306a
default was used.
Packit 95306a
Packit 95306a
=item B<convert>
Packit 95306a
Packit 95306a
   $err = $date->convert([$zone]);
Packit 95306a
Packit 95306a
This converts the date stored in the object to a different time zone.
Packit 95306a
$zone can be the name of a time zone. If it is not passed in, the
Packit 95306a
date is converted to the local time zone.
Packit 95306a
Packit 95306a
=item B<holiday>
Packit 95306a
Packit 95306a
   $name = $date->holiday();
Packit 95306a
   @name = $date->holiday();
Packit 95306a
   $name = $date->event();
Packit 95306a
Packit 95306a
This returns the name of the holiday if $date is a holiday. If $date
Packit 95306a
is not a holiday, undef is returned. If $date is an unnamed holiday,
Packit 95306a
an empty string is returned.
Packit 95306a
Packit 95306a
In scalar context, holiday returns the name of one holiday that occurs
Packit 95306a
on that date (the one first defined in the config file).  In list
Packit 95306a
context, it returns all holidays on that date.
Packit 95306a
Packit 95306a
=item B<input>
Packit 95306a
Packit 95306a
   $str = $date->input();
Packit 95306a
Packit 95306a
This returns the string that was parsed to form the date.
Packit 95306a
Packit 95306a
=item B<is_business_day>
Packit 95306a
Packit 95306a
   $flag = $date->is_business_day($checktime);
Packit 95306a
Packit 95306a
This returns 1 if $date is a business day.
Packit 95306a
Packit 95306a
$checktime may be passed in. If it is non-zero, the time is checked to
Packit 95306a
see if the date is a business day and falls within work hours.
Packit 95306a
Packit 95306a
=item B<list_holidays>
Packit 95306a
Packit 95306a
  @date = $date->list_holidays([$y]);
Packit 95306a
Packit 95306a
This returns a list of Date::Manip::Date objects containing all dates
Packit 95306a
during a year which are holidays. The times will all be 00:00:00.
Packit 95306a
Packit 95306a
If $y is not passed in, it will list the holidays in the same year as
Packit 95306a
the date stored in $date.
Packit 95306a
Packit 95306a
=item B<list_events>
Packit 95306a
Packit 95306a
   @list = $date->list_events(       [$format] );
Packit 95306a
   @list = $date->list_events(0      [,$format]);
Packit 95306a
   @list = $date->list_events($date1 [,$format]);
Packit 95306a
Packit 95306a
This returns a list of events.  Events are defined in the Events section
Packit 95306a
of the config file (discussed in the Date::Manip::Holidays manual).
Packit 95306a
Packit 95306a
In the first form, a list of all events active at the precise time
Packit 95306a
stored in $date will be returned.
Packit 95306a
Packit 95306a
If the first argument evaluates to 0, a list of all events active at
Packit 95306a
any time during that day (Y,M,D) are returned.
Packit 95306a
Packit 95306a
If the first argument is another date object, all events that are active
Packit 95306a
at any time between the two dates (inclusive) are returned.
Packit 95306a
Packit 95306a
By default, the list returned is of the form:
Packit 95306a
Packit 95306a
   ( [START, END, NAME],
Packit 95306a
     [START, END, NAME],
Packit 95306a
     ...
Packit 95306a
   )
Packit 95306a
Packit 95306a
where START is a date object when an event starts, END is a date
Packit 95306a
object when it ends, and NAME is the name of the event. Note that
Packit 95306a
START and END are the actual start and end date of the event and may
Packit 95306a
be outside the range of dates being examined (though the event will
Packit 95306a
obviously overlap the range or it wouldn't be included in the list).
Packit 95306a
Packit 95306a
If $format is included, it can specify an alternate format for the
Packit 95306a
output. Currently, the only supported format is named "dates" and
Packit 95306a
it returns a list in the form:
Packit 95306a
Packit 95306a
   ( [DATE1, NAME1a, NAME1b, ...],
Packit 95306a
     [DATE2, NAME2a, NAME2b, ...],
Packit 95306a
     ...
Packit 95306a
   )
Packit 95306a
Packit 95306a
This includes a list of all dates during the range when there is a
Packit 95306a
change in what events are active. DATE1 will always be the start of
Packit 95306a
the range being considered, and (NAME1a, NAME1b, ...) are the
Packit 95306a
list of all events that will be active at that time. At DATE2,
Packit 95306a
the list of active events changes with (NAME2a, NAME2b, ...) being
Packit 95306a
active.
Packit 95306a
Packit 95306a
It is quite possible that a date be included which has no active
Packit 95306a
events, and in that case, the list of names will be empty.
Packit 95306a
Packit 95306a
=item B<nearest_business_day>
Packit 95306a
Packit 95306a
   $date->nearest_business_day([$tomorrowfirst]);
Packit 95306a
Packit 95306a
This looks for the work day nearest to $date.  If $date is a work day,
Packit 95306a
it is left unmodified.  Otherwise, it will look forward or backwards
Packit 95306a
in time 1 day at a time until a work day is found.  If $tomorrowfirst
Packit 95306a
is non-zero (or if it is omitted and the config variable TomorrowFirst
Packit 95306a
is non-zero), we look to the future first.  Otherwise, we look in the
Packit 95306a
past first.  In other words, in a normal week, if $date is Wednesday,
Packit 95306a
$date is returned.  If $date is Saturday, Friday is returned.  If
Packit 95306a
$date is Sunday, Monday is returned.  If Wednesday is a holiday,
Packit 95306a
Thursday is returned if $tomorrowfirst is non-nil or Tuesday
Packit 95306a
otherwise.
Packit 95306a
Packit 95306a
=item B<next_business_day>
Packit 95306a
Packit 95306a
=item B<prev_business_day>
Packit 95306a
Packit 95306a
   $date->next_business_day($off [,$checktime]);
Packit 95306a
   $date->prev_business_day($off [,$checktime]);
Packit 95306a
Packit 95306a
The next_business_day method sets the given date to $off (which can be
Packit 95306a
a positive integer or zero) business days in the future. The prev_business_day
Packit 95306a
method sets the date to $off business days in the past.
Packit 95306a
Packit 95306a
First, $date is tested. If $checktime is nonzero, the date must fall
Packit 95306a
on a business date, and during business hours. If $checktime is zero,
Packit 95306a
the time check is not done, and the date must simply fall on a
Packit 95306a
business date.
Packit 95306a
Packit 95306a
If the check fails, the date is moved to the start of the next
Packit 95306a
business day (if $checktime is nonzero) or the next business day at
Packit 95306a
the current time (if $checktime is zero). Otherwise, it is left
Packit 95306a
unmodified.
Packit 95306a
Packit 95306a
Next, if $off is greater than 0, the day $off work days from now is
Packit 95306a
determined.
Packit 95306a
Packit 95306a
One thing to note for the prev_business_day method is that if $date
Packit 95306a
check fails, the date is set to the next business date, exactly like
Packit 95306a
next_business_day. In other words, if $date is not a business day, the
Packit 95306a
call:
Packit 95306a
Packit 95306a
   $date->prev_business_day(0 [,$checktime]);
Packit 95306a
Packit 95306a
moves $date forward in time instead of backward which is nonintuitive,
Packit 95306a
but you just have to think of day 0 as being the next business day if
Packit 95306a
$date is not a business day.
Packit 95306a
Packit 95306a
As a result, the following two calls ALWAYS give the same result:
Packit 95306a
Packit 95306a
   $date->next_business_day(0 [,$checktime]);
Packit 95306a
   $date->prev_business_day(0 [,$checktime]);
Packit 95306a
Packit 95306a
no matter what date is stored in $date.
Packit 95306a
Packit 95306a
=item B<parse>
Packit 95306a
Packit 95306a
   $err = $date->parse($string [,@opts]);
Packit 95306a
Packit 95306a
This parses a string which should include a valid date and stores
Packit 95306a
it in the object. If the string does not include a valid date, an
Packit 95306a
error is returned. Use the err method to see the full error
Packit 95306a
message.
Packit 95306a
Packit 95306a
A full date may include a calendar date (year, month, day), a time of
Packit 95306a
day (hour, minute, second), and time zone information. All of this can
Packit 95306a
be entered in many different formats.
Packit 95306a
Packit 95306a
For information on valid date formats, refer to the section VALID
Packit 95306a
DATE FORMATS. For information on valid time zone information, refer
Packit 95306a
to the section VALID TIME ZONE FORMATS.
Packit 95306a
Packit 95306a
If no time zone information is included in the date, it is treated
Packit 95306a
as being in the local time zone.
Packit 95306a
Packit 95306a
If time zone information is included, the date will be kept in that
Packit 95306a
time zone, and all operations will be done in that time zone.  The
Packit 95306a
convert method can be used to change the time zone to the local time
Packit 95306a
zone, or to another time zone.
Packit 95306a
Packit 95306a
Some things to note:
Packit 95306a
Packit 95306a
All strings are case insensitive.  "December" and "DEceMBer" are
Packit 95306a
equivalent.
Packit 95306a
Packit 95306a
When a part of the date is not given, defaults are used. This is
Packit 95306a
described below in the section "Complete vs. truncated dates and times".
Packit 95306a
Packit 95306a
The year may be entered as 2 or 4 digits.  If entered as 2 digits, it will
Packit 95306a
be converted to a 4 digit year.  There are several ways to do this based on
Packit 95306a
the value of the YYtoYYYY config variable.  Refer to the Date::Manip::Config
Packit 95306a
documentation for more details.
Packit 95306a
Packit 95306a
Dates are always checked to make sure they are valid.
Packit 95306a
Packit 95306a
If any other arguments are passed in, they act as options which may
Packit 95306a
improve the speed of parsing. These include:
Packit 95306a
Packit 95306a
   noiso8601  Do not try to parse the
Packit 95306a
              date as an ISO 8601 date
Packit 95306a
              or time.
Packit 95306a
   nodow      Do not try to parse a
Packit 95306a
              day-of-week (Monday) in
Packit 95306a
              the string.
Packit 95306a
   nocommon   Do not try to parse the
Packit 95306a
              date using the formats
Packit 95306a
              in the "Common date
Packit 95306a
              formats" section.
Packit 95306a
   noother    Do not try to parse the
Packit 95306a
              date using the "Less common
Packit 95306a
              date formats" or a time
Packit 95306a
              using the "Other time
Packit 95306a
              formats".
Packit 95306a
   nospecial  Do not try to parse the
Packit 95306a
              date using the "Special
Packit 95306a
              date strings" formats
Packit 95306a
              or a time using the
Packit 95306a
              "Special time strings"
Packit 95306a
              formats, or as a
Packit 95306a
              combined date/time using
Packit 95306a
              the "Additional combined
Packit 95306a
              date and time" formats.
Packit 95306a
   nodelta    Do not treat deltas as
Packit 95306a
              a date relative to now.
Packit 95306a
   noholidays Do not parse holiday
Packit 95306a
              names as dates.
Packit 95306a
Packit 95306a
=item B<parse_date>
Packit 95306a
Packit 95306a
   $err = $date->parse_date($string [,@opts]);
Packit 95306a
Packit 95306a
This parses a string which contains a valid date and sets the date
Packit 95306a
part of the object.
Packit 95306a
Packit 95306a
If the object contained a valid date, the time is kept unchanged. If the
Packit 95306a
object did NOT contain a valid date, a time of 00:00:00 is used.
Packit 95306a
Packit 95306a
@opts can be any of the strings described in the parse method above.
Packit 95306a
Packit 95306a
=item B<parse_time>
Packit 95306a
Packit 95306a
   $err = $date->parse_time($string [,@opts]);
Packit 95306a
Packit 95306a
This parses a string and sets the time portion of $date to contain it.
Packit 95306a
Packit 95306a
If the object contained a valid date, the Y/M/D portion is left unchanged.
Packit 95306a
Otherwise, the current date is used.
Packit 95306a
Packit 95306a
@opts can be 'noiso8601' or 'noother'.
Packit 95306a
Packit 95306a
=item B<parse_format>
Packit 95306a
Packit 95306a
   $err          = $date->parse_format($format,$string);
Packit 95306a
   ($err,%match) = $date->parse_format($format,$string);
Packit 95306a
Packit 95306a
This will parse a date contained in $string based on explicit format
Packit 95306a
information contained in $format.
Packit 95306a
Packit 95306a
If the format is invalid, $err will contain an error message.
Packit 95306a
If the format is valid, but string doesn't match, an error code
Packit 95306a
of 1 is returned.
Packit 95306a
Packit 95306a
If called in array context, a hash will be returned containing %+.
Packit 95306a
This is primarily useful if the $format string contains some
Packit 95306a
named capture groups that you define.  This is discussed below.
Packit 95306a
Packit 95306a
$format is a string containing a regular expression with some special
Packit 95306a
directives (based on the printf directives). These directives are turned
Packit 95306a
into regular expression components, and then the entire string is turned
Packit 95306a
into a regular expression which, if $string matches it, will return the
Packit 95306a
date.
Packit 95306a
Packit 95306a
The directives available are identical to the printf directives. So,
Packit 95306a
if your $format string contains the directive '%Y', it will match a
Packit 95306a
4-digit year.
Packit 95306a
Packit 95306a
All of the printf directives are available here with a few caveats:
Packit 95306a
Packit 95306a
   %l        This directive is NOT available.
Packit 95306a
Packit 95306a
   %b,%h,%B  These will all match a month name or abbreviation.
Packit 95306a
Packit 95306a
   %v,%a,%A  These will all match a day name or abbreviation.
Packit 95306a
Packit 95306a
   %z,%Z,%N  These will match any time zone string.
Packit 95306a
Packit 95306a
   %n        Multi-line matching is not currently supported,
Packit 95306a
             so this directive is not allowed.
Packit 95306a
Packit 95306a
   %x        All format directives are converted to a regular
Packit 95306a
             expression and then cached (so that a format
Packit 95306a
             can be reused without the penalty of doing the
Packit 95306a
             conversion to a regular expression with each use).
Packit 95306a
             As a result, if you need to set the DateFormat config
Packit 95306a
             variable (which determines the meaning of the %x
Packit 95306a
             directive), it must be done before a format string
Packit 95306a
             containing %x is used. If the DateFormat config variable
Packit 95306a
             is set afterwards, the format string will reflect the
Packit 95306a
             old, NOT THE NEW, value of DateFormat.
Packit 95306a
Packit 95306a
The format string may not over-specify the date. In other words, you
Packit 95306a
may not include both a %y and %Y directive or both a %j and %m directive.
Packit 95306a
Packit 95306a
A valid format string will specify any of the following sets of data:
Packit 95306a
Packit 95306a
   Required          Optional
Packit 95306a
Packit 95306a
   M D H Mn S        Y Zone Day-of-week
Packit 95306a
   M D H Mn          Y Zone Day-of-week
Packit 95306a
   M D               Y Zone Day-of-week
Packit 95306a
   H Mn S            Zone
Packit 95306a
   H Mn              Zone
Packit 95306a
Packit 95306a
For example, if you had a date stored as:
Packit 95306a
Packit 95306a
   YYYY.MM-DD
Packit 95306a
Packit 95306a
you could match it using the following:
Packit 95306a
Packit 95306a
   $date->parse_format('%Y\\.%m\\-%d',$string);
Packit 95306a
Packit 95306a
If you wanted to extract the date from an apache log line:
Packit 95306a
Packit 95306a
   10.11.12.13 - - [17/Aug/2009:12:33:30 -0400] "GET /favicon.ico ...
Packit 95306a
Packit 95306a
you could use:
Packit 95306a
Packit 95306a
   $date->parse_format('.*?\\[%d/%b/%Y:%T %z\\].*',$line);
Packit 95306a
Packit 95306a
When matching months, days, and hours, there are two directives
Packit 95306a
that could be used (for numerical versions).  For the month, you
Packit 95306a
may use %m or %f.  If your date is known to have a two-digit month,
Packit 95306a
you should use %m.  If it contains a one- or two-digit month, you must
Packit 95306a
use %f (and it is safe to use %f for two-digit months).  Similarly,
Packit 95306a
for days, you can use %d or %e and for hours you can use %H or %k.  In
Packit 95306a
both cases, the first can only be used if you are guaranteed a 2-digit
Packit 95306a
value.
Packit 95306a
Packit 95306a
In your format string, you may use capture groups (or back references
Packit 95306a
to them) in the regular expression using all of the rules of normal
Packit 95306a
regular expressions. Since Date::Manip uses named capture groups
Packit 95306a
internally, it is suggested that you also use named groups.  Mixing
Packit 95306a
numbered and named groups will work... but it'll be entirely up to you
Packit 95306a
to keep track of what numbers refer to which capture groups.
Packit 95306a
Packit 95306a
Every printf directive adds one or more named capture groups to the
Packit 95306a
regular expression.  If you use named groups in the format string,
Packit 95306a
they must not conflict with the ones used internally, or else the
Packit 95306a
date will probably not be parsed correctly.
Packit 95306a
Packit 95306a
The following named capture groups are used internally:
Packit 95306a
Packit 95306a
   y
Packit 95306a
   m
Packit 95306a
   d
Packit 95306a
   h
Packit 95306a
   mn
Packit 95306a
   s
Packit 95306a
   mon_name
Packit 95306a
   mon_abb
Packit 95306a
   dow_name
Packit 95306a
   dow_abb
Packit 95306a
   dow_char
Packit 95306a
   dow_num
Packit 95306a
   doy
Packit 95306a
   nth
Packit 95306a
   ampm
Packit 95306a
   epochs
Packit 95306a
   epocho
Packit 95306a
   tzstring
Packit 95306a
   off
Packit 95306a
   abb
Packit 95306a
   zone
Packit 95306a
   g
Packit 95306a
   w
Packit 95306a
   l
Packit 95306a
   u
Packit 95306a
Packit 95306a
To be safe, it is suggested that any additional named capture groups
Packit 95306a
introduced by the programmer start with a capital letter.  This is
Packit 95306a
guaranteed to never conflict with any existing, or future named capture
Packit 95306a
groups.
Packit 95306a
Packit 95306a
In order to get access to the values stored in the additional named
Packit 95306a
capture groups, the parse_format function must be called in list
Packit 95306a
context, and the %+ array will be returned as the second value.
Packit 95306a
Packit 95306a
As an example:
Packit 95306a
Packit 95306a
   $string = "before 2014-01-25 after";
Packit 95306a
   ($err,%m) = $date->parse_format('(?
.*?)%Y-%m-%d(?<POST>.*)',$string);
Packit 95306a
Packit 95306a
would return a hash (%m) with the following key/value pairs:
Packit 95306a
Packit 95306a
   'PRE'  => 'before '
Packit 95306a
   'POST' => ' after'
Packit 95306a
Packit 95306a
=item B<prev>
Packit 95306a
Packit 95306a
=item B<next>
Packit 95306a
Packit 95306a
The prev method changes the date to the previous (or current)
Packit 95306a
occurrence of either a day of the week, a certain time of day, or
Packit 95306a
both. The next method changes the date to the next (or current)
Packit 95306a
occurrence. The examples below illustrate the prev method, but
Packit 95306a
the next one is identical in operation.
Packit 95306a
Packit 95306a
There are two different ways to use this method. The first is to pass
Packit 95306a
in a day of week and possibly a time:
Packit 95306a
Packit 95306a
   $err = $date->prev($dow, $curr [,$time]);
Packit 95306a
Packit 95306a
If $curr = 0, this means to look for the previous occurrence of the day
Packit 95306a
of week, and set the time to the value passed in (or current time if
Packit 95306a
no time was passed in). The day is ALWAY less than the current day. If
Packit 95306a
the current day is the same day of week as $dow, then the date
Packit 95306a
returned will be one week earlier.
Packit 95306a
Packit 95306a
If $curr = 1, it means to look for the current or previous occurrence
Packit 95306a
of the day of week, and set the time to the value passed in (or 00:00:00 if
Packit 95306a
none was passed in). If the current day of week is the same as $dow, the
Packit 95306a
date will remain unchanged. Since the time is then set, the new date may
Packit 95306a
actually occur after the original date depending on the value of $time.
Packit 95306a
Packit 95306a
If $curr = 2, it means to look for the last time (not counting now)
Packit 95306a
that the day of week at the given time occurred. The date may be the
Packit 95306a
same as the original date.
Packit 95306a
Packit 95306a
$time may be a list reference of [H,MN,S], [H,MN], or [H].
Packit 95306a
Packit 95306a
The following examples should illustrate the use of this function.
Packit 95306a
Packit 95306a
    Original Date = Fri Nov 22 18:15:00
Packit 95306a
Packit 95306a
    dow      curr   time       new date
Packit 95306a
Packit 95306a
    4 (Thu)  0/1/2  undef      Thu Nov 21 00:00:00
Packit 95306a
    4        0/1/2  [12,30,0]  Thu Nov 21 12:30:00
Packit 95306a
Packit 95306a
    5 (Fri)  0/2    undef      Fri Nov 15 18:15:00
Packit 95306a
    5        1      undef      Fri Nov 22 18:15:00
Packit 95306a
Packit 95306a
    5        0      [12,30,0]  Fri Nov 15 12:30:00
Packit 95306a
    5        1/2    [12,30,0]  Fri Nov 22 12:30:00
Packit 95306a
Packit 95306a
    5        0/2    [19,30,0]  Fri Nov 15 19:30:00
Packit 95306a
    5        1      [19,30,0]  Fri Nov 22 19:30:00
Packit 95306a
Packit 95306a
The second way to use this method is by passing in undef for the day of
Packit 95306a
week.
Packit 95306a
Packit 95306a
   $err = $date->prev(undef,$curr,$time);
Packit 95306a
Packit 95306a
In this case, a time is required and it must be a list reference
Packit 95306a
of 3 elements: [H, MN, S]. Any or all of the elements may be undef.
Packit 95306a
Packit 95306a
The new date is the previous occurrence of the time.
Packit 95306a
Packit 95306a
If you define hours, then minutes and seconds may be defined, or
Packit 95306a
default to 0 and you are looking for a previous time that the
Packit 95306a
specified time (HH:00:00) occurred (which might be as much as 24 hours
Packit 95306a
in the past).
Packit 95306a
Packit 95306a
If hours are undefined and minutes are defined, then seconds may be
Packit 95306a
defined, or default to 0, and you are looking for the last time the
Packit 95306a
minutes/seconds (MN:SS) appeared on the digital clock, which will be
Packit 95306a
sometime in the past hour.
Packit 95306a
Packit 95306a
Finally, if hours and minutes are undefined, seconds must be defined
Packit 95306a
(or default to zero) and the last time that that second occurred will
Packit 95306a
be returned (which will be sometime in the past minute).
Packit 95306a
Packit 95306a
If $curr is non-zero, the current time is returned if it matches the
Packit 95306a
criteria passed in, so the returned value will be now or in the past.
Packit 95306a
If $curr is zero, the time returned will definitely be in the past.
Packit 95306a
Packit 95306a
    DATE = Fri Nov 22 18:15:00
Packit 95306a
Packit 95306a
    curr  hr     min    sec      returns
Packit 95306a
    0/1   18     undef  undef    Nov 22 18:00:00
Packit 95306a
    0/1   18     30     0        Nov 21 18:30:00
Packit 95306a
    0     18     15     undef    Nov 21 18:15:00
Packit 95306a
    1     18     15     undef    Nov 22 18:15:00
Packit 95306a
    0     undef  15     undef    Nov 22 17:15:00
Packit 95306a
    1     undef  15     undef    Nov 22 18:15:00
Packit 95306a
Packit 95306a
=item B<printf>
Packit 95306a
Packit 95306a
   $out = $date->printf($in);
Packit 95306a
   @out = $date->printf(@in);
Packit 95306a
Packit 95306a
This takes a string or list of strings which may contain any number of
Packit 95306a
special formatting directives. These directives are replaced with
Packit 95306a
information contained in the date. Everything else in the string is
Packit 95306a
returned unmodified.
Packit 95306a
Packit 95306a
A directive always begins with '%'. They are described in the section
Packit 95306a
below in the section PRINTF DIRECTIVES.
Packit 95306a
Packit 95306a
=item B<secs_since_1970_GMT>
Packit 95306a
Packit 95306a
   $secs = $date->secs_since_1970_GMT();
Packit 95306a
Packit 95306a
This returns the number of seconds that have elapsed since Jan 1, 1970
Packit 95306a
00:00:00 GMT (negative if the date is earlier).
Packit 95306a
Packit 95306a
The reverse is also allowed:
Packit 95306a
Packit 95306a
   $err = $date->secs_since_1970_GMT($secs);
Packit 95306a
Packit 95306a
which sets the date to $secs seconds from Jan 1, 1970 00:00:00 GMT in
Packit 95306a
the local time zone.
Packit 95306a
Packit 95306a
=item B<set>
Packit 95306a
Packit 95306a
   $err = $date->set($field,@vals [,$isdst]);
Packit 95306a
Packit 95306a
This explicitly sets one or more fields in a date.
Packit 95306a
Packit 95306a
$field can be any of the following:
Packit 95306a
Packit 95306a
   $field   @vals
Packit 95306a
Packit 95306a
   zone     [ZONE]         ZONE can be any zone or alias
Packit 95306a
Packit 95306a
   zdate    [ZONE,]DATE    sets the zone and entire date
Packit 95306a
Packit 95306a
   date     DATE           sets the entire date
Packit 95306a
Packit 95306a
   time     TIME           sets the entire time
Packit 95306a
Packit 95306a
   y        YEAR           sets one field
Packit 95306a
   m        MONTH
Packit 95306a
   d        DAY
Packit 95306a
   h        HOUR
Packit 95306a
   mn       MINUTE
Packit 95306a
   s        SECOND
Packit 95306a
Packit 95306a
Here, DATE is a list reference containing [Y,M,D,H,MN,S] and TIME is
Packit 95306a
a list reference containing [H,MN,S].
Packit 95306a
Packit 95306a
ZONE is optional (it defaults to the local zone as defined either by
Packit 95306a
the system clock, or the SetDate or ForceDate config variables). If it
Packit 95306a
is passed in, it can be any zone name, abbreviation, or offset. An
Packit 95306a
offset can be expressed either as a valid offset string, or as a list
Packit 95306a
reference.  Refer to the join/split functions of Date::Manip::Base for
Packit 95306a
information on valid offset strings.
Packit 95306a
Packit 95306a
An optional last argument is $isdst (which must be 0 or 1) is included
Packit 95306a
when setting a date which could be in either standard time or daylight
Packit 95306a
saving time. It is ignored in all other situations. If it is
Packit 95306a
not included, and the resulting date could be in either, it will
Packit 95306a
default to standard time.
Packit 95306a
Packit 95306a
The $date object must contain a valid date (unless the entire date
Packit 95306a
is being set with $field set to either "zdate" or "date").
Packit 95306a
Packit 95306a
If $field is "zone", the time zone of the date will be set. If ZONE is
Packit 95306a
not passed in, it will be set to the local time zone.  When setting the
Packit 95306a
time zone, no conversion is done! Whatever date and time is stored in
Packit 95306a
the $date object prior to this remains unchanged... except it will
Packit 95306a
be that date and time in the new time zone.
Packit 95306a
Packit 95306a
If $field is "zdate", the entire date and time zone is set. If ZONE is
Packit 95306a
not passed in, it is set to the local time zone.
Packit 95306a
Packit 95306a
If $field is "date", the entire date will be set, but the time zone
Packit 95306a
of the date will not be changed.
Packit 95306a
Packit 95306a
If $field is "time", or one of the individual fields, only those
Packit 95306a
fields will be modified.
Packit 95306a
Packit 95306a
An error is returned if an invalid argument list is passed in, or if
Packit 95306a
the resulting date is checked and found to be invalid.
Packit 95306a
Packit 95306a
=item B<value>
Packit 95306a
Packit 95306a
   $val = $date->value([$type]);
Packit 95306a
   @val = $date->value([$type]);
Packit 95306a
Packit 95306a
These return the value of the date stored in the object.
Packit 95306a
Packit 95306a
In scalar context, a printable string in the form YYYYMMDDHH:MN:SS
Packit 95306a
is returned. In list context, a list is returned of (Y,M,D,H,MN,S).
Packit 95306a
Packit 95306a
If $type is omitted, the date is returned in the time zone it was
Packit 95306a
parsed in.
Packit 95306a
Packit 95306a
If $type is "local", it is returned in the local time zone (which
Packit 95306a
is either the system time zone, or the zone specified with the
Packit 95306a
SetDate or ForceDate config variables).
Packit 95306a
Packit 95306a
If $type is "gmt", the date is returned in the GMT time zone.
Packit 95306a
Packit 95306a
An empty string or list is returned in the case of an error (and
Packit 95306a
an error code is set).
Packit 95306a
Packit 95306a
=item B<week_of_year>
Packit 95306a
Packit 95306a
   $wkno = $date->week_of_year([$first]);
Packit 95306a
Packit 95306a
This figures out the week number. If $first is passed in, it must be
Packit 95306a
between 1 and 7 and refers to the first day of the week. If $first is
Packit 95306a
not passed in, the FirstDay config variable is used.
Packit 95306a
Packit 95306a
NOTE: This routine should only be called in rare cases.  Use printf with
Packit 95306a
the %W, %U, %J, %L formats instead.  This routine returns a week between 0
Packit 95306a
and 53 which must then be "fixed" to get into the ISO 8601 weeks from 1 to
Packit 95306a
53.  A date which returns a week of 0 actually belongs to the last week of
Packit 95306a
the previous year.  A date which returns a week of 53 may belong to the
Packit 95306a
first week of the next year.
Packit 95306a
Packit 95306a
=back
Packit 95306a
Packit 95306a
=head1 ISSUES WITH PARSING DATES
Packit 95306a
Packit 95306a
The following issues may occur when parsing dates that should be
Packit 95306a
understood to make full use of this module.
Packit 95306a
Packit 95306a
=over 4
Packit 95306a
Packit 95306a
=item B<Complete vs. truncated dates and times>
Packit 95306a
Packit 95306a
Date formats are either complete or truncated. A complete date fully
Packit 95306a
specifies the year, month, and day and a complete time fully specifies
Packit 95306a
the hour, minute, and second.
Packit 95306a
Packit 95306a
It should be understood that in many instances, the information may be
Packit 95306a
implied rather than explicitly stated, but it is still treated as
Packit 95306a
complete.
Packit 95306a
Packit 95306a
For example, the date "January 3" is complete because it implies the
Packit 95306a
current year.
Packit 95306a
Packit 95306a
A truncated calendar date or time does not include information about
Packit 95306a
some of the fields. Date::Manip will never work with a partial date or
Packit 95306a
time, so defaults will be supplied.
Packit 95306a
Packit 95306a
For example, the date "2009-01" is missing a day field, so a default
Packit 95306a
will be used. In this case, the day will be the 1st, so this is
Packit 95306a
equivalent to "Jan 1st 2009". If only the year is given, it will
Packit 95306a
default to Jan 1.
Packit 95306a
Packit 95306a
If the time, or any of it's components is missing, they default to
Packit 95306a
00. So the time "12:30" and "12:30:00" are equivalent.
Packit 95306a
Packit 95306a
The "complete" method can be used to check what type of date was
Packit 95306a
parsed, and which values were specified (either explicitly or implied)
Packit 95306a
and which were provided as a default. It should be noted that there
Packit 95306a
is no way to differentiate between an explicit and implied value.
Packit 95306a
Packit 95306a
A string with a date and/or time may consist of any of the following:
Packit 95306a
Packit 95306a
   a complete date and a time (complete or truncated)
Packit 95306a
   a truncated date with no time
Packit 95306a
   a time (complete or truncated) with no date
Packit 95306a
Packit 95306a
In other words, the date "Jan 2009 12:30" is not valid since it consists
Packit 95306a
of a time with a truncated date.
Packit 95306a
Packit 95306a
=back
Packit 95306a
Packit 95306a
=head1 VALID TIME ZONE FORMATS
Packit 95306a
Packit 95306a
When specifying a time zone, it can be done in three different ways.
Packit 95306a
One way is to specify the actual time zone. The second is to supply
Packit 95306a
a valid time zone abbreviation. The third is to specify an offset (with
Packit 95306a
an optional abbreviation). The following dates illustrate the these
Packit 95306a
formats.
Packit 95306a
Packit 95306a
The timezone information always follows the time immediately, and may
Packit 95306a
only be included if a time is included. The following examples use
Packit 95306a
an ISO 8601 format for the date/time, but any of the other date and
Packit 95306a
time formats may be used.
Packit 95306a
Packit 95306a
The first way to specify the time zone is to specify it by complete name
Packit 95306a
(or using one of the standard aliases):
Packit 95306a
Packit 95306a
   2001-07-01-00:00:00 America/New_York
Packit 95306a
Packit 95306a
Although this is unambiguous when it comes to determining the time zone,
Packit 95306a
the time is ambiguous in most zones for one hour of the year. When
Packit 95306a
a time change occurs during which the clock is moved back, the same
Packit 95306a
wall clock time occurs twice.
Packit 95306a
Packit 95306a
For example, in America/New_York, on Sunday, Nov 2, 2008, at 02:00 in
Packit 95306a
the morning, the clock was set back to 01:00. As a result, the date
Packit 95306a
Nov 2, 2008 at 01:30 is ambiguous. It is impossible to determine if
Packit 95306a
this refers to the 01:30 that occurred half an hour before the time
Packit 95306a
change, or the one 30 minute after the change.
Packit 95306a
Packit 95306a
In practice, if this form is used, the date will be assigned to
Packit 95306a
standard time, meaning that there will be some times (typically 1 hour
Packit 95306a
per year) which cannot be expressed this way. As such, this method is
Packit 95306a
discouraged.
Packit 95306a
Packit 95306a
The second way to specify the time zone, which is the most common, is
Packit 95306a
to use a time zone abbreviation:
Packit 95306a
Packit 95306a
   2001-07-01-00:00:00 EDT
Packit 95306a
Packit 95306a
Unfortunately, the abbreviation does not uniquely determine the
Packit 95306a
time zone except in a few cases. In order to assign a time zone,
Packit 95306a
Date::Manip will refer to a list of all time zones which use the
Packit 95306a
abbreviation.  They will be tested, in the order given in the
Packit 95306a
Date::Manip::Zones documentation, and the first match (i.e. the one in
Packit 95306a
which the given date/time and abbreviation are valid) determines the
Packit 95306a
time zone which will be used. A great deal of effort has been made to
Packit 95306a
ensure that the most likely time zone will be obtained (i.e. the most
Packit 95306a
common time zones are tested before less common ones), so in most
Packit 95306a
cases, the desired results will be obtained.
Packit 95306a
Packit 95306a
If the default order does not yield the desired time zone, the order of
Packit 95306a
testing can be modified using the abbrev method described in the
Packit 95306a
Date::Manip::TZ documentation.
Packit 95306a
Packit 95306a
Although the time zone is ambiguous, the date is not, since only
Packit 95306a
time zones for which the date are valid will be used.
Packit 95306a
Packit 95306a
The third way to specify the time zone is by specifying an offset and
Packit 95306a
an optional abbreviation:
Packit 95306a
Packit 95306a
   2001-07-01-00:00:00 -04
Packit 95306a
   2001-07-01-00:00:00 -0400
Packit 95306a
   2001-07-01-00:00:00 -040000
Packit 95306a
   2001-07-01-00:00:00 -04:00
Packit 95306a
   2001-07-01-00:00:00 -04:00:00
Packit 95306a
Packit 95306a
   2001-07-01-00:00:00 -04 (EDT)
Packit 95306a
   2001-07-01-00:00:00 -0400 (EDT)
Packit 95306a
   2001-07-01-00:00:00 -040000 (EDT)
Packit 95306a
   2001-07-01-00:00:00 -04:00 (EDT)
Packit 95306a
   2001-07-01-00:00:00 -04:00:00 (EDT)
Packit 95306a
Packit 95306a
   2001-07-01-00:00:00 -04 EDT
Packit 95306a
   2001-07-01-00:00:00 -0400 EDT
Packit 95306a
   2001-07-01-00:00:00 -040000 EDT
Packit 95306a
   2001-07-01-00:00:00 -04:00 EDT
Packit 95306a
   2001-07-01-00:00:00 -04:00:00 EDT
Packit 95306a
Packit 95306a
The offset almost never sufficient to uniquely determine the time zone
Packit 95306a
(and it is not even guaranteed that both the offset and abbreviation
Packit 95306a
will, though in practice, it is probably sufficient). In this
Packit 95306a
instance, the time zone will be determined by testing all time zones
Packit 95306a
which have the given offset (and abbreviation if it is included) until
Packit 95306a
one is found which matches both pieces of information. For more
Packit 95306a
information about how this testing is done, refer to the def_zone
Packit 95306a
method of the Date::Manip::TZ documentation.
Packit 95306a
Packit 95306a
=head1 VALID DATE FORMATS
Packit 95306a
Packit 95306a
There are several categories of date formats supported by Date::Manip.
Packit 95306a
These are strings which specify only the year/month/day fields.
Packit 95306a
Packit 95306a
These formats explicitly set the date, but not the time. These formats
Packit 95306a
may be combined with a time string (as specified below) to set both
Packit 95306a
the date and time. If this is not done, the default time is determined
Packit 95306a
by the DefaultTime config variable.
Packit 95306a
Packit 95306a
=over 4
Packit 95306a
Packit 95306a
=item B<ISO 8601 dates>
Packit 95306a
Packit 95306a
The preferred date formats are those specified by ISO 8601. The
Packit 95306a
specification includes valid calendar date and valid time formats.
Packit 95306a
Date::Manip will handle all of these formats, but does not require
Packit 95306a
that the dates rigidly adhere to the specification since the ultimate
Packit 95306a
goal of Date::Manip is to handle dates as they are represented in
Packit 95306a
real life and some common variations exist which are similar to, but
Packit 95306a
not identical to, those from the specification.
Packit 95306a
Packit 95306a
A calendar date includes the following fields:
Packit 95306a
Packit 95306a
   CC    2-digit representation of the century
Packit 95306a
   YY    2-digit representation of the year in
Packit 95306a
         a century
Packit 95306a
   MM    2-digit representation of a month
Packit 95306a
   DD    2-digit representation of a day of month
Packit 95306a
   DoY   3-digit representation of a day of year
Packit 95306a
         (001-366)
Packit 95306a
   Www   the character "W" followed by a 2-digit
Packit 95306a
         week of the year (01-53)
Packit 95306a
   D     the day of the week (1-7)
Packit 95306a
Packit 95306a
The following date formats are considered complete by Date::Manip. In
Packit 95306a
the following, the date Thu Mar 5 2009 is used as an example.  This is
Packit 95306a
the 64th day of the year. Thu is the 4th day of the week.  The week
Packit 95306a
starting Mon, Mar 2 is the 10th week of the year (according the the
Packit 95306a
ISO 8601 definition). Obviously, some of the formats are only valid
Packit 95306a
when used at some times. For example, the format --MMDD refers to a
Packit 95306a
month and day in the current year, so the date Mar 5, 2009 can only be
Packit 95306a
specified using this format during 2009.
Packit 95306a
Packit 95306a
   Format      Notes   Examples
Packit 95306a
Packit 95306a
   CCYYMMDD            20090305
Packit 95306a
   CCYY-MM-DD          2009-03-05
Packit 95306a
Packit 95306a
   YYMMDD      1,2,4   090305
Packit 95306a
   YY-MM-DD            09-03-05
Packit 95306a
Packit 95306a
   -YYMMDD     3,4     -090305
Packit 95306a
   -YY-MM-DD           -09-03-05
Packit 95306a
Packit 95306a
   --MMDD      1       --0305
Packit 95306a
   --MM-DD             --03-05
Packit 95306a
Packit 95306a
   ---DD       1       ---05
Packit 95306a
Packit 95306a
Packit 95306a
   CCYYDoY             2009064
Packit 95306a
   CCYY-DoY            2009-064
Packit 95306a
Packit 95306a
   YYDoY       1,4     09064
Packit 95306a
   YY-DoY              09-064
Packit 95306a
Packit 95306a
   -YYDoY      3,4     -09064
Packit 95306a
   -YY-DoY             -09-064
Packit 95306a
Packit 95306a
   -DoY        1       -064
Packit 95306a
Packit 95306a
Packit 95306a
   CCYYWwwD            2009W104
Packit 95306a
   CCYY-Www-D          2009-W10-4
Packit 95306a
Packit 95306a
   YYWwwD      1,4     09W104
Packit 95306a
   YY-Www-D            09-W10-4
Packit 95306a
Packit 95306a
   -YYWwwD     3,4     -09W104
Packit 95306a
   -YY-Www-D           -09-W10-4
Packit 95306a
Packit 95306a
   -YWwwD      1       -9W104
Packit 95306a
   -Y-Www-D            -9-W10-4
Packit 95306a
                       Y is the year (0-9) in
Packit 95306a
                       current decade
Packit 95306a
Packit 95306a
   -WwwD       1       -W104
Packit 95306a
   -Www-D              -W10-4
Packit 95306a
Packit 95306a
   -W-D        1       -W-4
Packit 95306a
                       D is day (1-7) in
Packit 95306a
                       current week
Packit 95306a
Packit 95306a
   ---D        1       ---4
Packit 95306a
                       same as -W-D
Packit 95306a
Packit 95306a
The following date formats are truncated:
Packit 95306a
Packit 95306a
   CCYY-MM     2       2009-03   (2009-03-01)
Packit 95306a
Packit 95306a
   CCYY                2009      (2009-01-01)
Packit 95306a
Packit 95306a
   CC          2       20        (2000-01-01)
Packit 95306a
Packit 95306a
   -YYMM       4       -0903
Packit 95306a
   -YY-MM              -09-03
Packit 95306a
Packit 95306a
   -YY         4       -09
Packit 95306a
Packit 95306a
   --MM                --03
Packit 95306a
Packit 95306a
   CCYYWww             2009W10
Packit 95306a
   CCYY-Www            2009-W10
Packit 95306a
Packit 95306a
   YYWww       4       09W10
Packit 95306a
   YY-Www              09-W10
Packit 95306a
Packit 95306a
   -YYWww      3,4     -09W10
Packit 95306a
   -YY-Www             -09-W10
Packit 95306a
Packit 95306a
   -Www                -W10
Packit 95306a
Packit 95306a
Notes:
Packit 95306a
Packit 95306a
1  These formats are considered truncated in the standard, but since
Packit 95306a
   they do include (or imply, using the current date for defaults)
Packit 95306a
   all of the fields, and since they do not introduce any parsing
Packit 95306a
   complexities, the standard is relaxed, and they are treated as
Packit 95306a
   complete.
Packit 95306a
Packit 95306a
2  These formats are treated differently than in Date::Manip 5.xx as
Packit 95306a
   described below.
Packit 95306a
Packit 95306a
3  These formats are not defined in the ISO 8601 spec, but
Packit 95306a
   are added for the sake of completeness since they do not
Packit 95306a
   add any parsing incompatibilities.
Packit 95306a
Packit 95306a
4  Formats where the century is not given are described as a year in
Packit 95306a
   the current century in the specification. Date::Manip treats this
Packit 95306a
   more generically using the YYtoYYYY config variable. This will be
Packit 95306a
   used to determine how to determine the full year.
Packit 95306a
Packit 95306a
Date::Manip 5.xx handled ISO 8601 dates in a less rigid fashion, and
Packit 95306a
deviated from the specification in several formats. As of 6.00, the
Packit 95306a
specification is followed much more closely so that all of the date
Packit 95306a
formats included in it should produce valid dates.  This changes, in a
Packit 95306a
backwards incompatible way, the way a few strings will be interpreted
Packit 95306a
as dates.
Packit 95306a
Packit 95306a
As of 6.00, a two-digit date will be treated as CC. Previously, it
Packit 95306a
was treated as YY.
Packit 95306a
Packit 95306a
A six-digit date will be treated as YYMMDD. Previously, it was treated
Packit 95306a
as YYYYMM.
Packit 95306a
Packit 95306a
Previously, dashes were treated as optional in many cases. According
Packit 95306a
to the specification, dates may be written in expanded form (with all
Packit 95306a
dashes present) or abbreviate form (with no dashes). As of 6.00, this
Packit 95306a
is the behavior, so the formats: YYMMDD and YY-MM-DD are allowed, as
Packit 95306a
per the specification, but the format YY-MMDD is NOT allowed (though
Packit 95306a
it was previously).
Packit 95306a
Packit 95306a
The Www-D formats require a bit of explanation.  According to the
Packit 95306a
specification, the date:
Packit 95306a
Packit 95306a
   1996-w02-3
Packit 95306a
Packit 95306a
refers to the day with an ordinal number of 3 within the calendar week
Packit 95306a
in the 2nd week of 1996.
Packit 95306a
Packit 95306a
In the specification, the days of the week are numbered from 1 to 7
Packit 95306a
(Monday to Sunday), and the week always begins on Monday, so day 1
Packit 95306a
(Monday) is always the first day of the week, day 2 (Tuesday) is
Packit 95306a
always the second day of the week, etc.
Packit 95306a
Packit 95306a
In Date::Manip, the constraint that the week must start with Monday is
Packit 95306a
relaxed, allowing the week to begin with Sunday (a far more common
Packit 95306a
start of the week in calendars, at least in some parts of the world).
Packit 95306a
Packit 95306a
This presents a problem though in that the above date could be
Packit 95306a
interpreted as Wednesday (day 3) of the 2nd week of 1996, or as the
Packit 95306a
3rd day of the 2nd week of 1996 (which would normally be Wednesday,
Packit 95306a
but would be Tuesday if the week begins on Sunday).
Packit 95306a
Packit 95306a
As of Date::Manip 6.00, the above date will be interpreted as the 3rd
Packit 95306a
day of the 2nd week. This is a reversal from Date::Manip 5.xx, but I
Packit 95306a
believe is what the specification would require. For more information,
Packit 95306a
refer to the Date::Manip::Changes document.
Packit 95306a
Packit 95306a
=item B<Common date formats>
Packit 95306a
Packit 95306a
Date::Manip supports a number of common date formats. The following fields
Packit 95306a
may be included in a date:
Packit 95306a
Packit 95306a
  YY    2-digit representation of the year
Packit 95306a
  YYYY  4-digit representation of the year
Packit 95306a
  M     1- or 2- digit representation of the month
Packit 95306a
  MM    2-digit representation of the month
Packit 95306a
  D     1- or 2- digit representation of the day
Packit 95306a
  DD    2-digit representation of the day
Packit 95306a
  mmm   The abbreviated or full month name (i.e. Jan)
Packit 95306a
Packit 95306a
The following date formats are supported:
Packit 95306a
Packit 95306a
   Format      Notes   Examples
Packit 95306a
Packit 95306a
   M/D         1,2,3   3/5
Packit 95306a
   M/D/YY      1       3/5/09
Packit 95306a
   M/D/YYYY    1       3/5/2009
Packit 95306a
Packit 95306a
   YYYY/M/D            2009/3/5
Packit 95306a
Packit 95306a
   mmm/D               Mar/5
Packit 95306a
   mmm/D/YY            Mar/5/09
Packit 95306a
   mmm/D/YYYY          Mar/5/2009
Packit 95306a
   D/mmm               5/Mar
Packit 95306a
   D/mmm/YY            5/Mar/09
Packit 95306a
   D/mmm/YYYY          5/Mar/2009
Packit 95306a
   YYYY/mmm/D          2009/Mar/5
Packit 95306a
Packit 95306a
   mmmD                Mar5
Packit 95306a
   mmmDDYY     4       Mar0509
Packit 95306a
   mmmDDYYYY           Mar052009
Packit 95306a
   Dmmm                5Mar
Packit 95306a
   DmmmYY              5Mar09
Packit 95306a
   DmmmYYYY            5Mar2009
Packit 95306a
   YYYYmmmD            2009Mar5
Packit 95306a
Packit 95306a
   mmmD YY             Mar5 09
Packit 95306a
   mmmD YYYY           Mar5 2009
Packit 95306a
   Dmmm YY             5Mar 09
Packit 95306a
   Dmmm YYYY           5Mar 2009
Packit 95306a
Packit 95306a
   mmm/D YY            Mar/5 09
Packit 95306a
   mmm/D YYYY          Mar/5 2009
Packit 95306a
   D/mmm YY            5/Mar 09
Packit 95306a
   D/mmm YYYY          5/Mar 2009
Packit 95306a
Packit 95306a
   YY   mmmD           09   Mar5
Packit 95306a
   YYYY mmmD           2009 Mar5
Packit 95306a
   YY   Dmmm           09   5Mar
Packit 95306a
   YYYY Dmmm           2009 5Mar
Packit 95306a
Packit 95306a
   YY   mmm/D          09   Mar/5
Packit 95306a
   YYYY mmm/D          2009 Mar/5
Packit 95306a
   YY   D/mmm          09   5/Mar
Packit 95306a
   YYYY D/mmm          2009 5/Mar
Packit 95306a
Packit 95306a
   YYYY:MM:DD          2010:01:15 (EXIF format)
Packit 95306a
Packit 95306a
   mmmYYYY     4       Jun 2010
Packit 95306a
   YYYYmmm     4       2010 June
Packit 95306a
   mmm/YYYY    4       Jun/2010
Packit 95306a
   YYYY/mmm    4       2010/Jun
Packit 95306a
Packit 95306a
In the formats above, the slash (/) can be replace by any of the valid
Packit 95306a
separators: whitespace, slash (/), period (.), or dash (-). The dash,
Packit 95306a
though allowed, is discouraged since it may conflict with an ISO 8601
Packit 95306a
format.  For example, the format MM/DD/YY is just fine, but MM-DD-YY
Packit 95306a
does not work since it conflicts with YY-MM-DD.  To be safe, if "-" is
Packit 95306a
used as a separator in a non-ISO format, they should be turned into
Packit 95306a
"/" before calling the Date::Manip routines or you should use the 'noiso8601'
Packit 95306a
option with the B<parse> or B<parse_date> methods.
Packit 95306a
Packit 95306a
No matter what separator is used, the same separator must be used
Packit 95306a
throughout the date. For example, MM/DD/YY is valid and MM.DD.YY is
Packit 95306a
also valid, but MM/DD.YY is NOT valid.
Packit 95306a
Packit 95306a
Notes:
Packit 95306a
Packit 95306a
1  With these formats, Americans tend to write month first, but many
Packit 95306a
   other countries tend to write day first.  The latter behavior can be
Packit 95306a
   obtained by setting the config variable DateFormat to something other
Packit 95306a
   than "US".
Packit 95306a
Packit 95306a
2  The dot (.) separator may not be used in the M/D format since it
Packit 95306a
   will be interpreted as the H12,H+ format described below.
Packit 95306a
Packit 95306a
3  The M/D format should not use the period (.) separator as that will
Packit 95306a
   incorrectly match the HH,H+ time format.
Packit 95306a
Packit 95306a
4  Historically, I have not supported partial dates (i.e. dates that
Packit 95306a
   were not fully specified), but it has been argued that something like
Packit 95306a
   'Jun 1910' would be interpreted by almost everyone as a day in June
Packit 95306a
   of 1910 instead of June 19, 2010.  And it has been shown that in
Packit 95306a
   some applications, dates are specified in that way.  I have added the
Packit 95306a
   new config variable Format_MMMYYYY which will change this.  If this
Packit 95306a
   variable is not set, the formats allowed are:
Packit 95306a
Packit 95306a
      mmmDDYY
Packit 95306a
Packit 95306a
   If it is set, the formats allowed are:
Packit 95306a
Packit 95306a
      mmmYYYY
Packit 95306a
      YYYYmmm
Packit 95306a
Packit 95306a
   The day of week may not be included with these formats.  When
Packit 95306a
   parsing a full date/time, if Format_MMMYYYY is set to 'first',
Packit 95306a
   it returns the 1st of the month at midnight.  If it is set to
Packit 95306a
   'last', it returns the last day at 23:59:59.  If parsing only
Packit 95306a
   only a date, it will be set to the first or last day of the
Packit 95306a
   month at midnight.
Packit 95306a
Packit 95306a
These formats explicitly set the date, but not the time. The default
Packit 95306a
time is determined by the DefaultTime config variable.
Packit 95306a
Packit 95306a
=item B<Less common date formats>
Packit 95306a
Packit 95306a
The following formats are also supported by Date::Manip:
Packit 95306a
Packit 95306a
   DoW
Packit 95306a
        The day of week of the current week
Packit 95306a
           Friday
Packit 95306a
           Friday at 12:40
Packit 95306a
Packit 95306a
   MMM Nth [YYYY]
Packit 95306a
   Nth MMM [YYYY]
Packit 95306a
   YYYY MMM Nth
Packit 95306a
   YYYY Nth MMM
Packit 95306a
        Dec 1st 1970
Packit 95306a
        1st Dec 1970
Packit 95306a
        1970 Dec 1st
Packit 95306a
        1970 1st Dec
Packit 95306a
Packit 95306a
   next/prev DoW
Packit 95306a
        The next or last occurrence of DoW
Packit 95306a
           next Friday
Packit 95306a
           last Friday at 12:40
Packit 95306a
Packit 95306a
   next/last week/month/year
Packit 95306a
        The day one week/month/year from now
Packit 95306a
        or in the past
Packit 95306a
           next week
Packit 95306a
           last month at 15:00
Packit 95306a
Packit 95306a
   last day in MMM [YYYY]
Packit 95306a
        The last day of the month
Packit 95306a
           last day in October
Packit 95306a
           last day in October 1996
Packit 95306a
Packit 95306a
   last DoW in MMM [YYYY]
Packit 95306a
        The last DoW in the month
Packit 95306a
           last Tuesday in October
Packit 95306a
           last Tuesday in October 1996
Packit 95306a
Packit 95306a
   last DoW in YYYY
Packit 95306a
        The last DoW in the year
Packit 95306a
           last Tuesday in 1997
Packit 95306a
Packit 95306a
           NOTE: "last DoW" doesn't work in
Packit 95306a
           English since the word "last"
Packit 95306a
           is used for both this expression
Packit 95306a
           and for "prev DoW", which gets
Packit 95306a
           parsed first. "last DoW" MAY
Packit 95306a
           work in other languages.
Packit 95306a
Packit 95306a
   Nth DoW in MMM [YYYY]
Packit 95306a
        The Nth DoW in the month
Packit 95306a
           3rd Tuesday in October
Packit 95306a
           3rd Tuesday in October 1996
Packit 95306a
Packit 95306a
   Nth DoW [YYYY]
Packit 95306a
        The Nth DoW in the year
Packit 95306a
           22nd Sunday
Packit 95306a
           22nd Sunday in 1996
Packit 95306a
Packit 95306a
   Nth day in MMM [YYYY]
Packit 95306a
        The Nth day of the month
Packit 95306a
           1st day of February
Packit 95306a
           1st day of February 2012
Packit 95306a
Packit 95306a
   DoW week
Packit 95306a
        British: same as "in 1 week on DoW"
Packit 95306a
           Monday week
Packit 95306a
Packit 95306a
   DoW week N [YYYY]
Packit 95306a
   Dow Nth week [YYYY]
Packit 95306a
        Sunday week 22
Packit 95306a
        Sunday 22nd week
Packit 95306a
           These refer to the day of week
Packit 95306a
           of the Nth week of the year.
Packit 95306a
Packit 95306a
   Nth
Packit 95306a
        12th
Packit 95306a
           This refers to the Nth day of the
Packit 95306a
           current month.
Packit 95306a
Packit 95306a
Note that the formats "Sunday week 22" and "22nd Sunday" give
Packit 95306a
different behaviors.  "Sunday week 22" returns the Sunday of the 22nd
Packit 95306a
week of the year based on how week 1 is defined.  ISO 8601 defines
Packit 95306a
week one to contain Jan 4, so "Sunday week 1" might be the first or
Packit 95306a
second Sunday of the current year, or the last Sunday of the previous
Packit 95306a
year.  "22nd Sunday" gives the actual 22nd time Sunday occurs in a
Packit 95306a
given year, regardless of the definition of a week.
Packit 95306a
Packit 95306a
=item B<Special date strings>
Packit 95306a
Packit 95306a
Most languages have strings which can be used to specify the date (relative
Packit 95306a
to today). In English, these include the strings:
Packit 95306a
Packit 95306a
   today
Packit 95306a
   tomorrow
Packit 95306a
   yesterday
Packit 95306a
Packit 95306a
There is also support for the British formats:
Packit 95306a
Packit 95306a
   today week
Packit 95306a
   tomorrow week
Packit 95306a
   yesterday week
Packit 95306a
Packit 95306a
which refer to one week after today/tomorrow/yesterday respectively.
Packit 95306a
Packit 95306a
Other languages have similar strings.
Packit 95306a
Packit 95306a
=item B<Holidays>
Packit 95306a
Packit 95306a
You can parse holiday names as dates (including timezones).  For example:
Packit 95306a
Packit 95306a
   Christmas
Packit 95306a
   Christmas 2010
Packit 95306a
   Christmas 2010 at noon
Packit 95306a
   Christmas 2010 at noon PST
Packit 95306a
   Saturday Christmas 2010 at noon
Packit 95306a
Packit 95306a
=back
Packit 95306a
Packit 95306a
In all of the formats (except for ISO 8601 formats), the day of week
Packit 95306a
("Friday") can be entered anywhere in the date and it will be checked
Packit 95306a
for accuracy.  In other words,
Packit 95306a
Packit 95306a
  "Tue Jul 16 1996 13:17:00"
Packit 95306a
Packit 95306a
will work but
Packit 95306a
Packit 95306a
  "Jul 16 1996 Wednesday 13:17:00"
Packit 95306a
Packit 95306a
will not (because Jul 16, 1996 is Tuesday, not Wednesday).
Packit 95306a
Packit 95306a
=head1 A NOTE ABOUT FOREIGN LANGUAGE DATES
Packit 95306a
Packit 95306a
Although Date::Manip has some support for parsing dates in foreign
Packit 95306a
languages, it must be noted that the formats supported are largely
Packit 95306a
based on English equivalents.
Packit 95306a
Packit 95306a
There are probably many different dates that are perfectly valid, and
Packit 95306a
in common usage, in other languages which do not have an equivalent in
Packit 95306a
the English language, and unfortunately, Date::Manip will probably not
Packit 95306a
parse these.
Packit 95306a
Packit 95306a
You are free to send these to me, and I'll see if there is a way to
Packit 95306a
add them in, but I do not guarantee anything.  Without having a
Packit 95306a
full-blown language parser (or at least the portion of the language
Packit 95306a
that is devoted to calendar and time), most of these formats will
Packit 95306a
simply not be supportable.
Packit 95306a
Packit 95306a
=head1 VALID TIME FORMATS
Packit 95306a
Packit 95306a
There are several categories of time formats supported by Date::Manip.
Packit 95306a
These are strings which specify only the hour/minute/second fields.
Packit 95306a
Packit 95306a
=over 4
Packit 95306a
Packit 95306a
=item B<ISO 8601 times>
Packit 95306a
Packit 95306a
A time may be also be complete or truncated.  Again, Date::Manip
Packit 95306a
treats some formats as complete even though the specification calls
Packit 95306a
them truncated.
Packit 95306a
Packit 95306a
A time may include the following fields:
Packit 95306a
Packit 95306a
   HH    2-digit representation of the hour
Packit 95306a
   MN    2-digit representation of the minutes
Packit 95306a
   SS    2-digit representation of the seconds
Packit 95306a
   H+    1+ digit representation of fractional hours
Packit 95306a
   M+    1+ digit representation of fractional minutes
Packit 95306a
   S+    1+ digit representation of fractional seconds
Packit 95306a
Packit 95306a
The following time formats are considered complete by Date::Manip. The time
Packit 95306a
12:30:15 will be expressed in the examples.
Packit 95306a
Packit 95306a
   Format      Notes   Examples
Packit 95306a
Packit 95306a
   HHMNSS      2       123015
Packit 95306a
Packit 95306a
   HH:MN:SS            12:30:15
Packit 95306a
Packit 95306a
   HHMNSS,S+           123015,5
Packit 95306a
   HH:MN:SS,S+         12:30:15,5
Packit 95306a
                       Fractional seconds are ignored
Packit 95306a
Packit 95306a
   HHMN,M+             1230,25
Packit 95306a
   HH:MN,M+            12:30,25
Packit 95306a
                       This is 12:30:00 + 0.25 minutes
Packit 95306a
Packit 95306a
   HH,H+               12,5
Packit 95306a
                       This is 12:00:00 + 0.5 hours, so
Packit 95306a
                       this is equivalent to 12:30:00
Packit 95306a
Packit 95306a
   -MNSS       1       -3015
Packit 95306a
   -MN:SS              -30:15
Packit 95306a
Packit 95306a
   --SS        1       --15
Packit 95306a
Packit 95306a
   -MNSS,S+    1       -3015,5
Packit 95306a
   -MN:SS,S+           -30:15,5
Packit 95306a
Packit 95306a
   -MN,M+      1       -30,25
Packit 95306a
Packit 95306a
   --SS,S+     1       --15,5
Packit 95306a
Packit 95306a
   HHMN        3       1230
Packit 95306a
   HH:MN               12:30
Packit 95306a
Packit 95306a
The following time formats are truncated:
Packit 95306a
Packit 95306a
   HH                  12
Packit 95306a
Packit 95306a
   -MN                 -30
Packit 95306a
Packit 95306a
Notes:
Packit 95306a
Packit 95306a
1  These formats are considered truncated in the standard, but since
Packit 95306a
   they do include (or imply, using the current time for defaults) all of
Packit 95306a
   the fields, and since they do not introduce any parsing complexities,
Packit 95306a
   the standard is relaxed, and they are treated as complete.
Packit 95306a
Packit 95306a
2  The HHMNSS format will not be correctly parsed since it is impossible
Packit 95306a
   to distinguish between it and YYMMDD. In order to parse an all-digit
Packit 95306a
   time, add the string ",0" to the end to force it to be interpreted
Packit 95306a
   as a time or include time zone information (either a zone name or
Packit 95306a
   abbreviation... an offset will not work in this case).
Packit 95306a
Packit 95306a
3  The HH:MN format will be treated as complete, even though it is
Packit 95306a
   incomplete due to missing the seconds. In real life, expressing
Packit 95306a
   a time in the HH:MN format is very common, and is regarded as complete,
Packit 95306a
   and might include time zone information.
Packit 95306a
Packit 95306a
ISO 8601 times may be followed by a time zone unless they are truncated.
Packit 95306a
Truncated times may not include a timezone.  Date::Manip relaxes the
Packit 95306a
constraints placed on the time zone format and allows any of the
Packit 95306a
methods used to specify the time zone including time zone name, abbreviation,
Packit 95306a
or offset. The time zone may be separated from the time by a space, but
Packit 95306a
it is not required.
Packit 95306a
Packit 95306a
Another constraint that is relaxed is that the fractional part may be
Packit 95306a
specified using a period. In other words, the following are equivalent:
Packit 95306a
Packit 95306a
   12:30,25
Packit 95306a
   12:30.25
Packit 95306a
Packit 95306a
It should be noted (as it is in the specification) that using a
Packit 95306a
negative time zone offset may cause confusion. In addition to visually
Packit 95306a
confusing, it may not be parsed correctly. For example, the time:
Packit 95306a
Packit 95306a
   123005-0300
Packit 95306a
Packit 95306a
may not be parsed correctly. When using an offset time zone, you
Packit 95306a
should always use the colon separators in the time:
Packit 95306a
Packit 95306a
   12:30:05-0300
Packit 95306a
Packit 95306a
=item B<Other time formats>
Packit 95306a
Packit 95306a
A time may include any of the following fields:
Packit 95306a
Packit 95306a
   H24   1- or 2-digit representation of the hour (0-23)
Packit 95306a
   H12   1- or 2-digit representation of the hour (1-12)
Packit 95306a
   MN    2-digit representation of the minutes
Packit 95306a
   SS    2-digit representation of the seconds
Packit 95306a
   H+    1+ digit representation of fractional hours
Packit 95306a
   M+    1+ digit representation of fractional minutes
Packit 95306a
   S+    1+ digit representation of fractional seconds
Packit 95306a
   AM    A language specific AM/PM string
Packit 95306a
Packit 95306a
The following time formats are accepted:
Packit 95306a
Packit 95306a
   Format      	       Examples
Packit 95306a
Packit 95306a
   H24:MN:SS           17:30:15
Packit 95306a
   H12:MN:SS AM        5:30:15 PM
Packit 95306a
   H12:MN:SS
Packit 95306a
Packit 95306a
   H24:MN:SS,S+        17:30:15,5
Packit 95306a
   H12:MN:SS,S+ AM     5:30:15,5 PM
Packit 95306a
   H12:MN:SS,S+        Fractional seconds are ignored
Packit 95306a
Packit 95306a
   H24:MN,M+           17:30,25
Packit 95306a
   H12:MN,M+ AM        5:30,25 PM
Packit 95306a
   H12:MN,M+           This is 17:30:00 + 0.25 minutes
Packit 95306a
Packit 95306a
   H24,H+              17,5
Packit 95306a
   H12,H+ AM           5,5 PM
Packit 95306a
   H12,H+              This is 17:00:00 + 0.5 hours, so
Packit 95306a
                       this is equivalent to 17:30:00
Packit 95306a
Packit 95306a
   H24:MN              17:30
Packit 95306a
   H12:MN AM           5:30 PM
Packit 95306a
   H12:MN
Packit 95306a
Packit 95306a
   H12 AM              5 PM
Packit 95306a
Packit 95306a
The fractional part may be specified using a comma or a period.
Packit 95306a
Fractional seconds may also be separated using a colon.  A
Packit 95306a
language specific fractional separator may also be available for
Packit 95306a
some languages.
Packit 95306a
Packit 95306a
In other words, the following are equivalent:
Packit 95306a
Packit 95306a
   12:30:20,25
Packit 95306a
   12:30:20.25
Packit 95306a
   12:30:20:25
Packit 95306a
Packit 95306a
Some languages have alternate H:MN and MN:S separators. For example,
Packit 95306a
one H:MN separator in French is 'h' (the MN:S separator is still a
Packit 95306a
colon), so the following are equivalent:
Packit 95306a
Packit 95306a
   12:30:00
Packit 95306a
   12h30:00
Packit 95306a
Packit 95306a
Time zone information can be included immediately following the time.
Packit 95306a
It can be separated by whitespace from the time, or it can be
Packit 95306a
immediately adjacent.
Packit 95306a
Packit 95306a
=item B<Special time strings>
Packit 95306a
Packit 95306a
Different languages may have some words which can be used to specify a
Packit 95306a
certain time of day. In English, for example, the following words are
Packit 95306a
equivalent to the time listed:
Packit 95306a
Packit 95306a
   noon        12:00:00
Packit 95306a
   midnight    00:00:00
Packit 95306a
Packit 95306a
So, the following are equivalent:
Packit 95306a
Packit 95306a
   Jan 2 2009 at noon
Packit 95306a
   Jan 2 2009 12:00:00
Packit 95306a
Packit 95306a
There were two possible ways to interpret midnight. One was at the
Packit 95306a
start of the day (00:00:00) and the other was at the end of the day
Packit 95306a
(24:00:00 which would actually mean at 00:00:00 of the following day).
Packit 95306a
The first has been used to maintain backwards compatibility with
Packit 95306a
Date::Manip 5.xx .
Packit 95306a
Packit 95306a
Other languages have similar strings.
Packit 95306a
Packit 95306a
=back
Packit 95306a
Packit 95306a
In most languages, a word similar to "at" may precede the time (this
Packit 95306a
does NOT apply to ISO 8601 time formats). This word (which must be
Packit 95306a
separate from all other parts of the date with whitespace) is
Packit 95306a
optional, and the following are equivalent:
Packit 95306a
Packit 95306a
   12:30
Packit 95306a
   at 12:30
Packit 95306a
Packit 95306a
The times "12:00 am", "12:00 pm", and "midnight" are not well defined.
Packit 95306a
Date::Manip uses the following convention:
Packit 95306a
Packit 95306a
  midnight = 12:00am = 00:00:00
Packit 95306a
  noon     = 12:00pm = 12:00:00
Packit 95306a
Packit 95306a
and the day goes from 00:00:00 to 23:59:59.  In other words, midnight is the
Packit 95306a
beginning of a day rather than the end of one.  The time 24:00:00 is also
Packit 95306a
allowed (though it is automatically transformed to 00:00:00 of the following
Packit 95306a
day). This gives the unusual result of parsing:
Packit 95306a
Packit 95306a
  Wed Feb 8 2006 24:00:00
Packit 95306a
Packit 95306a
which gives the date of:
Packit 95306a
Packit 95306a
  Thu Feb 9 2006 00:00:00
Packit 95306a
Packit 95306a
=head1 VALID COMBINED DATE AND TIME FORMATS
Packit 95306a
Packit 95306a
There are several categories of strings which specify both the date and
Packit 95306a
time. These include the following:
Packit 95306a
Packit 95306a
=over 4
Packit 95306a
Packit 95306a
=item B<ISO 8601 combined date and time>
Packit 95306a
Packit 95306a
A combined ISO 8601 date and time is a string containing a complete
Packit 95306a
ISO 8601 date and a complete or truncated ISO 8601 time.  It may
Packit 95306a
also include a timezone, provided a complete time is included.
Packit 95306a
Packit 95306a
Date::Manip relaxes the restrictions on how the two are combined.  The
Packit 95306a
time may be separated from the date by space, dash, or the letter T,
Packit 95306a
or the two may be joined with nothing separating them.
Packit 95306a
Packit 95306a
When the time immediately follows the date, or when the two are
Packit 95306a
separated by a dash, the resulting string MUST be
Packit 95306a
unambiguous. Provided the date includes all of the dashes in it
Packit 95306a
(i.e. YY-MM-DD instead of YYMMDD), it is rare that there is any
Packit 95306a
ambiguity. If the date does not include dashes, the strings may be
Packit 95306a
ambiguous, and in this case, separating the date and time with a space
Packit 95306a
or the letter T is useful (and perhaps necessary) to correctly
Packit 95306a
interpret the string.
Packit 95306a
Packit 95306a
The DoY formats should always be separated from the time by
Packit 95306a
something. They are visually confusing if they are not separated from
Packit 95306a
the time.
Packit 95306a
Packit 95306a
Time zone information can be included immediately following a complete
Packit 95306a
time.  It may not be included if no time is given, or if a truncated
Packit 95306a
time is included. The time zone may be separated from the time with
Packit 95306a
whitespace, or it can be immediately adjacent to it (since the ISO
Packit 95306a
8601 specification allows it in some cases).
Packit 95306a
Packit 95306a
=item B<Non-ISO 8601 combined date and time>
Packit 95306a
Packit 95306a
A date from any of the non-ISO 8601 formats above may be combined with
Packit 95306a
any of the non-ISO 8601 time formats above in any combination to form
Packit 95306a
a valid combined date and time.
Packit 95306a
Packit 95306a
=item B<Deltas>
Packit 95306a
Packit 95306a
Dates are often specified in terms of a delta from "now". For example,
Packit 95306a
"in 2 days".
Packit 95306a
Packit 95306a
Most valid deltas can be used to specify a date, and the date is defined
Packit 95306a
as that delta added to "now". Refer to the Date::Manip::Delta documentation
Packit 95306a
for a list of valid delta formats.
Packit 95306a
Packit 95306a
If the delta itself does not include a time part, the time may be specified
Packit 95306a
explicitly. For example:
Packit 95306a
Packit 95306a
   in 3 days at 12:00:00
Packit 95306a
   in 3 days at 12:00:00 PST
Packit 95306a
Packit 95306a
will take the delta part "in 3 days" and add it to the current time, then
Packit 95306a
set the time to 12:00:00.
Packit 95306a
Packit 95306a
It is NOT allowed to include an explicit time if any time segment was
Packit 95306a
included in the delta. For example, the following is invalid:
Packit 95306a
Packit 95306a
   in 3 days 2 hours at 12:00:00
Packit 95306a
Packit 95306a
One additional format that is supported is to include only week (or higher)
Packit 95306a
components in the delta and to set the day of week. For example:
Packit 95306a
Packit 95306a
  Friday in 2 weeks
Packit 95306a
  in 2 weeks on Friday
Packit 95306a
  Friday 2 weeks ago
Packit 95306a
  2 weeks ago on Friday at 13:45
Packit 95306a
Packit 95306a
These first apply the delta (of weeks, months, and years) to the current
Packit 95306a
time, and then set the day to the given day-of-week in that week.
Packit 95306a
Packit 95306a
=item B<Special date and time strings>
Packit 95306a
Packit 95306a
Most language have strings which can be used to specify the full date and
Packit 95306a
time (relative to the current date and time). In English, these include
Packit 95306a
the string:
Packit 95306a
Packit 95306a
   now
Packit 95306a
Packit 95306a
They may also have a timezone attached:
Packit 95306a
Packit 95306a
   now PST
Packit 95306a
Packit 95306a
=item B<Additional combined date and time formats>
Packit 95306a
Packit 95306a
The following formats are also supported:
Packit 95306a
Packit 95306a
   epoch SECS
Packit 95306a
      The number of seconds since the epoch
Packit 95306a
      (Jan 1, 1970 00:00:00 GMT). SECS may
Packit 95306a
      be negative to give time before the
Packit 95306a
      epoch.
Packit 95306a
Packit 95306a
or
Packit 95306a
Packit 95306a
   epoch SECS TIMEZONE
Packit 95306a
Packit 95306a
=back
Packit 95306a
Packit 95306a
A couple of notes:
Packit 95306a
Packit 95306a
Commas may be included in all date formats arbitrarily (except for ISO
Packit 95306a
8601 formats where they may only be included when allowed by the
Packit 95306a
specification).
Packit 95306a
Packit 95306a
The time/time zone is removed from the date before the date is parsed,
Packit 95306a
so the time may appear before or after the date, or between any two
Packit 95306a
parts of the date.
Packit 95306a
Packit 95306a
The time and the zone do not need to be adjacent, so the string:
Packit 95306a
Packit 95306a
   Jan 21 17:13:27 2010 -0400
Packit 95306a
Packit 95306a
will work.  If the timezone is separate from the date, it MUST be
Packit 95306a
separated from any other portion of the date by whitespace.
Packit 95306a
Packit 95306a
Certain words such as "on", "in", "at", "of", etc. which commonly
Packit 95306a
appear in a date or time are ignored (except in ISO 8601 formats).
Packit 95306a
Packit 95306a
=head1 PRINTF DIRECTIVES
Packit 95306a
Packit 95306a
The following printf directives are replaced with information
Packit 95306a
from the date.
Packit 95306a
Packit 95306a
   Year
Packit 95306a
       %y     year                     - 00 to 99
Packit 95306a
       %Y     year                     - 0001 to 9999
Packit 95306a
Packit 95306a
   Month, Week
Packit 95306a
       %m     month of year            - 01 to 12
Packit 95306a
       %f     month of year            - " 1" to "12"
Packit 95306a
       %b,%h  month abbreviation       - Jan to Dec
Packit 95306a
       %B     month name               - January to December
Packit 95306a
Packit 95306a
   Day
Packit 95306a
       %j     day of the year          - 001 to 366
Packit 95306a
       %d     day of month             - 01 to 31
Packit 95306a
       %e     day of month             - " 1" to "31"
Packit 95306a
       %v     weekday abbreviation     - " S"," M"," T", ...
Packit 95306a
       %a     weekday abbreviation     - Sun to Sat
Packit 95306a
       %A     weekday name             - Sunday to Saturday
Packit 95306a
       %w     day of week              - 1 to 7 (1=Monday)
Packit 95306a
       %E     day of month with
Packit 95306a
              suffix                   - 1st, 2nd, 3rd...
Packit 95306a
Packit 95306a
   Hour
Packit 95306a
       %H     hour                     - 00 to 23
Packit 95306a
       %k     hour                     - " 0" to "23"
Packit 95306a
       %i     hour                     - " 1" to "12"
Packit 95306a
       %I     hour                     - 01 to 12
Packit 95306a
       %p     AM or PM
Packit 95306a
Packit 95306a
   Minute, Second, Time zone
Packit 95306a
       %M     minute                   - 00 to 59
Packit 95306a
       %S     second                   - 00 to 59
Packit 95306a
       %Z     time zone abbreviation   - EDT
Packit 95306a
       %z     time zone as GMT offset  - +0100 (see Note 4)
Packit 95306a
       %N     time zone as GMT offset  - +01:00:00
Packit 95306a
Packit 95306a
   Epoch (see NOTE 3 below)
Packit 95306a
       %s     seconds from
Packit 95306a
              1/1/1970 GMT             - negative if before
Packit 95306a
       %o     seconds from 1/1/1970
Packit 95306a
              in the current time
Packit 95306a
              zone
Packit 95306a
Packit 95306a
   Date, Time
Packit 95306a
       %c     %a %b %e %H:%M:%S %Y     - Fri Apr 28 17:23:15 1995
Packit 95306a
       %C,%u  %a %b %e %H:%M:%S %Z %Y  - Fri Apr 28 17:25:57 EDT 1995
Packit 95306a
       %g     %a, %d %b %Y %H:%M:%S %Z - Fri, 28 Apr 1995 17:23:15 EDT
Packit 95306a
       %D     %m/%d/%y                 - 04/28/95
Packit 95306a
       %x     %m/%d/%y or %d/%m/%y     - 04/28/95 or 28/04/95
Packit 95306a
                                         (Depends on DateFormat variable)
Packit 95306a
       %l     date in ls(1) format (see NOTE 1 below)
Packit 95306a
                %b %e %H:%M            - Apr 28 17:23 (*)
Packit 95306a
                %b %e  %Y              - Apr 28  1993 (*)
Packit 95306a
       %r     %I:%M:%S %p              - 05:39:55 PM
Packit 95306a
       %R     %H:%M                    - 17:40
Packit 95306a
       %T,%X  %H:%M:%S                 - 17:40:58
Packit 95306a
       %V     %m%d%H%M%y               - 0428174095
Packit 95306a
       %Q     %Y%m%d                   - 19961025
Packit 95306a
       %q     %Y%m%d%H%M%S             - 19961025174058
Packit 95306a
       %P     %Y%m%d%H:%M:%S           - 1996102517:40:58
Packit 95306a
       %O     %Y-%m-%dT%H:%M:%S        - 1996-10-25T17:40:58
Packit 95306a
       %F     %A, %B %e, %Y            - Sunday, January  1, 1996
Packit 95306a
       %K     %Y-%j                    - 1997-045
Packit 95306a
Packit 95306a
   Special Year/Week formats (see NOTE 2 below)
Packit 95306a
       %G     year, Monday as first
Packit 95306a
              day of week              - 0001 to 9999
Packit 95306a
       %W     week of year, Monday
Packit 95306a
              as first day of week     - 01 to 53
Packit 95306a
       %L     year, Sunday as first
Packit 95306a
              day of week              - 0001 to 9999
Packit 95306a
       %U     week of year, Sunday
Packit 95306a
              as first day of week     - 01 to 53
Packit 95306a
       %J     %G-W%W-%w                - 1997-W02-2
Packit 95306a
Packit 95306a
   Other formats
Packit 95306a
       %n     insert a newline character
Packit 95306a
       %t     insert a tab character
Packit 95306a
       %%     insert a `%' character
Packit 95306a
       %+     insert a `+' character
Packit 95306a
Packit 95306a
   All other characters are currently unused, but may be used in the
Packit 95306a
   future.  They currently insert the character following the %.
Packit 95306a
Packit 95306a
   The following multi-character formats also exist:
Packit 95306a
Packit 95306a
   Extended formats
Packit 95306a
       %<A=NUM>   These returns the NUMth value of the %A, %a, and %v formats
Packit 95306a
       %<a=NUM>   respectively.  In English, that would yield:
Packit 95306a
       %<v=NUM>      %<A=2>   => Tuesday
Packit 95306a
                     %<a=2>   => Tue
Packit 95306a
                     %<v=2>   => T
Packit 95306a
                  NUM must be in the range 1-7.
Packit 95306a
Packit 95306a
       %<B=NUM>   These return the NUMth value of the %B and %b formats
Packit 95306a
       %<b=NUM>   respectively.  In English, that would yield:
Packit 95306a
                     %<B=2>   => February
Packit 95306a
                     %<b=2>   => Feb
Packit 95306a
                  NUM must be in the range 1-12 (or 01-12).
Packit 95306a
Packit 95306a
       %<p=NUM>   These return the NUMth value of the %p format.  In
Packit 95306a
                  English, that would yield:
Packit 95306a
                     %<p=1>   => AM
Packit 95306a
                     %<p=2>   => PM
Packit 95306a
                  NUM must be in the range 1-2.
Packit 95306a
Packit 95306a
       %<E=NUM>   These return the NUMth value of the %E format.  In
Packit 95306a
                  English, that would yield:
Packit 95306a
                     %<E=1>   => 1st
Packit 95306a
                     %<E=53>  => 53rd
Packit 95306a
                  NUM must be in the range 1-53.
Packit 95306a
Packit 95306a
If a lone percent is the final character in a format, it is ignored.
Packit 95306a
Packit 95306a
The formats used in this routine were originally based on date.pl (version
Packit 95306a
3.2) by Terry McGonigal, as well as a couple taken from different versions
Packit 95306a
of the Solaris date(1) command.  Also, several have been added which are
Packit 95306a
unique to Date::Manip.
Packit 95306a
Packit 95306a
NOTE 1:
Packit 95306a
Packit 95306a
The ls format (%l) applies to date within the past OR future 6 months!
Packit 95306a
Any date that is before the date NOW - 6 months, or that is on or
Packit 95306a
after the date NOW + 6 months will have the year printed out.
Packit 95306a
Packit 95306a
The later time must be on or after so that there is no ambiguity. If it
Packit 95306a
is now 2000-06-06-12:00:00, then the date 1999-12-06-12:00:00 will be
Packit 95306a
written as "Dec 6 12:00" but the date 2000-12-06-12:00:00 will be written
Packit 95306a
as "Dec 6 2000".
Packit 95306a
Packit 95306a
NOTE 2:
Packit 95306a
Packit 95306a
The %U, %W, %L, %G, and %J formats are used to support the ISO-8601 format:
Packit 95306a
YYYY-wWW-D.  In this format, a date is written as a year, the week of the
Packit 95306a
year, and the day of the week.  Technically, the week may be considered to
Packit 95306a
start on any day of the week, but Sunday and Monday are the both common
Packit 95306a
choices, so both are supported.
Packit 95306a
Packit 95306a
The %W and %G formats return the week-of-year and the year treating weeks
Packit 95306a
as starting on Monday.
Packit 95306a
Packit 95306a
The %U and %L formats return the week-of-year and the year treating weeks
Packit 95306a
as starting on Sunday.
Packit 95306a
Packit 95306a
Most of the time, the %L and %G formats returns the same value as the %Y
Packit 95306a
format, but there is a problem with days occurring in the first or last week
Packit 95306a
of the year.
Packit 95306a
Packit 95306a
The ISO-8601 representation of Jan 1, 1993 written in the YYYY-wWW-D format
Packit 95306a
is actually 1992-W53-5.  In other words, Jan 1 is treated as being in the
Packit 95306a
last week of the preceding year.  Depending on the year, days in the first
Packit 95306a
week of a year may belong to the previous year, and days in the final week
Packit 95306a
of a year may belong to the next year.  The week is assigned to the year
Packit 95306a
which has most of the days.  For example, if the week starts on Sunday,
Packit 95306a
then the last week of 2003 is 2003-12-28 to 2004-01-03.  This week is
Packit 95306a
assigned to 2003 since 4 of the days in it are in 2003 and only 3 of them
Packit 95306a
are in 2004.  The first week of 2004 starts on 2004-01-04.
Packit 95306a
Packit 95306a
The %U and %W formats return a week-of-year number from 01 to 53. %L and
Packit 95306a
%G return the corresponding year, and to get this type of information,
Packit 95306a
you should always use the (%W,%G) combination or (%U,%L) combination. %Y
Packit 95306a
should not be used as it will yield incorrect results.
Packit 95306a
Packit 95306a
%J returns the full ISO-8601 format (%G-W%W-%w).
Packit 95306a
Packit 95306a
NOTE 3:
Packit 95306a
Packit 95306a
The %s and %o formats return negative values if the date is before
Packit 95306a
the start of the epoch.  Other Unix utilities would return an error, or
Packit 95306a
a zero, so if you are going to use Date::Manip in conjunction with these,
Packit 95306a
be sure to check for a negative value.
Packit 95306a
Packit 95306a
NOTE 4:
Packit 95306a
Packit 95306a
The %z format returns the offset in the RFC 822 specified format
Packit 95306a
+0500 .  Most offsets are full hour amounts, so this is not a problem,
Packit 95306a
but some offsets are irregular (+05:17:30). In this case, the string
Packit 95306a
returned is +051730 which isn't RFC 822 compliant, but since RFC 822
Packit 95306a
ignores this situation, I had to decide between returning an incorrect
Packit 95306a
value, or breaking strict compliance, and I chose the second option.
Packit 95306a
Packit 95306a
=head1 KNOWN BUGS
Packit 95306a
Packit 95306a
None known.
Packit 95306a
Packit 95306a
=head1 BUGS AND QUESTIONS
Packit 95306a
Packit 95306a
Please refer to the Date::Manip::Problems documentation for
Packit 95306a
information on submitting bug reports or questions to the author.
Packit 95306a
Packit 95306a
=head1 SEE ALSO
Packit 95306a
Packit 95306a
Date::Manip        - main module documentation
Packit 95306a
Packit 95306a
=head1 LICENSE
Packit 95306a
Packit 95306a
This script is free software; you can redistribute it and/or
Packit 95306a
modify it under the same terms as Perl itself.
Packit 95306a
Packit 95306a
=head1 AUTHOR
Packit 95306a
Packit 95306a
Sullivan Beck (sbeck@cpan.org)
Packit 95306a
Packit 95306a
=cut