| 1 |
# Copyright (c) 1995-2026 Sullivan Beck. All rights reserved. |
| 2 |
# This program is free software; you can redistribute it and/or modify it |
| 3 |
# under the same terms as Perl itself. |
| 4 |
|
| 5 |
=pod |
| 6 |
|
| 7 |
=head1 NAME |
| 8 |
|
| 9 |
Date::Manip::DM6 - Date manipulation routines |
| 10 |
|
| 11 |
=head1 SYNOPSIS |
| 12 |
|
| 13 |
use Date::Manip; |
| 14 |
|
| 15 |
$version = DateManipVersion($flag); |
| 16 |
|
| 17 |
Date_Init("VAR=VAL","VAR=VAL",...); |
| 18 |
|
| 19 |
$date = ParseDate(\@args [,@opts]); |
| 20 |
$date = ParseDate($string [,@opts]); |
| 21 |
$date = ParseDate(\$string [,@opts]); |
| 22 |
|
| 23 |
$date = ParseDateString($string [,@opts]); |
| 24 |
|
| 25 |
$date = ParseDateFormat($format,$string); |
| 26 |
|
| 27 |
@date = UnixDate($date,@format); |
| 28 |
$date = UnixDate($date,@format); |
| 29 |
|
| 30 |
$delta = ParseDateDelta(\@args [,$mode]); |
| 31 |
$delta = ParseDateDelta($string [,$mode]); |
| 32 |
$delta = ParseDateDelta(\$string [,$mode]); |
| 33 |
|
| 34 |
@str = Delta_Format($delta, [$mode,] $dec,@format); |
| 35 |
$str = Delta_Format($delta, [$mode,] $dec,@format); |
| 36 |
|
| 37 |
$recur = ParseRecur($string,$base,$date0,$date1,$flags); |
| 38 |
@dates = ParseRecur($string,$base,$date0,$date1,$flags); |
| 39 |
|
| 40 |
$flag = Date_Cmp($date1,$date2); |
| 41 |
|
| 42 |
$d = DateCalc($d1,$d2 [,$errref] [,$mode]); |
| 43 |
|
| 44 |
$date = Date_SetTime($date,$hr,$min,$sec); |
| 45 |
$date = Date_SetTime($date,$time); |
| 46 |
|
| 47 |
$date = Date_SetDateField($date,$field,$val [,$nocheck]); |
| 48 |
|
| 49 |
$date = Date_GetPrev($date,$dow,$today,$hr,$min,$sec); |
| 50 |
$date = Date_GetPrev($date,$dow,$today,$time); |
| 51 |
|
| 52 |
$date = Date_GetNext($date,$dow,$today,$hr,$min,$sec); |
| 53 |
$date = Date_GetNext($date,$dow,$today,$time); |
| 54 |
|
| 55 |
$name = Date_IsHoliday($date); |
| 56 |
@name = Date_IsHoliday($date); |
| 57 |
|
| 58 |
$listref = Events_List($date); |
| 59 |
$listref = Events_List($date0,$date1); |
| 60 |
|
| 61 |
$date = Date_ConvTZ($date,$from,$to); |
| 62 |
|
| 63 |
$flag = Date_IsWorkDay($date [,$flag]); |
| 64 |
|
| 65 |
$date = Date_NextWorkDay($date,$off [,$time]); |
| 66 |
|
| 67 |
$date = Date_PrevWorkDay($date,$off [,$time]); |
| 68 |
|
| 69 |
$date = Date_NearestWorkDay($date [,$tomorrowfirst]); |
| 70 |
|
| 71 |
In the following routines, $y may be entered as either a 2 or 4 digit |
| 72 |
year (it will be converted to a 4 digit year based on the variable |
| 73 |
YYtoYYYY described below). Month and day should be numeric in all |
| 74 |
cases. |
| 75 |
|
| 76 |
$day = Date_DayOfWeek($m,$d,$y); |
| 77 |
$secs = Date_SecsSince1970($m,$d,$y,$h,$mn,$s); |
| 78 |
$secs = Date_SecsSince1970GMT($m,$d,$y,$h,$mn,$s); |
| 79 |
$days = Date_DaysSince1BC($m,$d,$y); |
| 80 |
$day = Date_DayOfYear($m,$d,$y); |
| 81 |
($y,$m,$d,$h,$mn,$s) = Date_NthDayOfYear($y,$n); |
| 82 |
$days = Date_DaysInYear($y); |
| 83 |
$days = Date_DaysInMonth($m,$y); |
| 84 |
$wkno = Date_WeekOfYear($m,$d,$y,$first); |
| 85 |
$flag = Date_LeapYear($y); |
| 86 |
$day = Date_DaySuffix($d); |
| 87 |
$tz = Date_TimeZone(); |
| 88 |
|
| 89 |
=head1 ROUTINES |
| 90 |
|
| 91 |
=over 4 |
| 92 |
|
| 93 |
=item B<DateManipVersion> |
| 94 |
|
| 95 |
$version = DateManipVersion($flag); |
| 96 |
|
| 97 |
Returns the version of Date::Manip. If $flag is non-zero, timezone information |
| 98 |
is also returned. |
| 99 |
|
| 100 |
=item B<Date_Init> |
| 101 |
|
| 102 |
Date_Init("VAR=VAL","VAR=VAL",...); |
| 103 |
|
| 104 |
The Date_Init function is used to set any of the Date::Manip configuration |
| 105 |
variables described in the Date::Manip::Config document. |
| 106 |
|
| 107 |
The strings to pass in are of the form "VAR=VAL". Any number may be |
| 108 |
included and they can come in any order. VAR may be any configuration |
| 109 |
variable. VAL is any allowed value for that variable. For example, |
| 110 |
to switch from English to French and use non-US format (so that 12/10 |
| 111 |
is Oct 12), do the following: |
| 112 |
|
| 113 |
Date_Init("Language=French","DateFormat=non-US"); |
| 114 |
|
| 115 |
Note that variables are parsed in the order they are given, so |
| 116 |
"DateFormat=non-US", "ConfigFile=./manip.cnf" may not give the |
| 117 |
expected result. To be safe, ConfigFile should always appear first in |
| 118 |
the list. |
| 119 |
|
| 120 |
=item B<ParseDate> |
| 121 |
|
| 122 |
$date = ParseDate(\@args [,@opts]); |
| 123 |
$date = ParseDate($string [,@opts]); |
| 124 |
$date = ParseDate(\$string [,@opts]); |
| 125 |
|
| 126 |
This takes an array or a string containing a date and parses it. When the |
| 127 |
date is included as an array (for example, the arguments to a program) the |
| 128 |
array should contain a valid date in the first one or more elements |
| 129 |
(elements after a valid date are ignored). Elements containing a valid |
| 130 |
date are shifted from the array. The largest possible number of elements |
| 131 |
which can be correctly interpreted as a valid date are always used. If a |
| 132 |
string is entered rather than an array, that string is tested for a valid |
| 133 |
date. The string is unmodified, even if passed in by reference. |
| 134 |
|
| 135 |
The ParseDate routine is primarily used to handle command line arguments. |
| 136 |
If you have a command where you want to enter a date as a command line |
| 137 |
argument, you can use Date::Manip to make something like the following |
| 138 |
work: |
| 139 |
|
| 140 |
mycommand -date Dec 10 1997 -arg -arg2 |
| 141 |
|
| 142 |
No more reading man pages to find out what date format is required in a |
| 143 |
man page. |
| 144 |
|
| 145 |
The C<@opts> argument may contain values that can be passed to the |
| 146 |
C<Date::Manip::Date::parse> method. |
| 147 |
|
| 148 |
Historical note: this is originally why the Date::Manip routines were |
| 149 |
written (though long before they were released as the Date::Manip module). |
| 150 |
I was using a bunch of programs (primarily batch queue managers) where |
| 151 |
dates and times were entered as command line options and I was getting |
| 152 |
highly annoyed at the many different (but not compatible) ways that they |
| 153 |
had to be entered. Date::Manip originally consisted of basically 1 routine |
| 154 |
which I could pass "@ARGV" to and have it remove a date from the beginning. |
| 155 |
|
| 156 |
=item B<ParseDateString> |
| 157 |
|
| 158 |
$date = ParseDateString($string [,@opts]); |
| 159 |
|
| 160 |
This parses a string containing a date and returns it. Refer to the |
| 161 |
Date::Manip::Date documentation for valid date formats. The date |
| 162 |
returned is in the local time zone. |
| 163 |
|
| 164 |
The C<@opts> argument may contain values that can be passed to the |
| 165 |
C<Date::Manip::Date::parse> method. |
| 166 |
|
| 167 |
=item B<ParseDateFormat> |
| 168 |
|
| 169 |
$date = ParseDateFormat($format,$string); |
| 170 |
|
| 171 |
This parses a string containing a date based on a format string and |
| 172 |
returns the date. Refer to the Date::Manip::Date documentation for the |
| 173 |
parse_format method for more information. The date returned is in the |
| 174 |
local time zone. |
| 175 |
|
| 176 |
=item B<UnixDate> |
| 177 |
|
| 178 |
$out = UnixDate($date,$in); |
| 179 |
@out = UnixDate($date,@in); |
| 180 |
|
| 181 |
This takes a date and a list of strings containing formats roughly |
| 182 |
identical to the format strings used by the UNIX date(1) command. |
| 183 |
Each format is parsed and an array of strings corresponding to each |
| 184 |
format is returned. |
| 185 |
|
| 186 |
The formats are described in the Date::Manip::Date document. |
| 187 |
|
| 188 |
=item B<ParseDateDelta> |
| 189 |
|
| 190 |
$delta = ParseDateDelta(\@args [,$mode]); |
| 191 |
$delta = ParseDateDelta($string [,$mode]); |
| 192 |
$delta = ParseDateDelta(\$string [,$mode]); |
| 193 |
|
| 194 |
In the first form, it takes an array and shifts a valid delta from it. |
| 195 |
In the other two forms, it parses a string to see if it contains a |
| 196 |
valid delta. |
| 197 |
|
| 198 |
A valid delta is returned if found. Otherwise, an empty string is |
| 199 |
returned. |
| 200 |
|
| 201 |
The delta can be converted to 'exact', 'semi', or 'approx' using the |
| 202 |
Date::Manip::Delta::convert method if $mode is passed in. |
| 203 |
|
| 204 |
=item B<Delta_Format> |
| 205 |
|
| 206 |
$out = Delta_Format($delta [,$mode], $dec,$in); |
| 207 |
@out = Delta_Format($delta [,$mode], $dec,@in); |
| 208 |
|
| 209 |
This is similar to the UnixDate routine except that it extracts information |
| 210 |
from a delta. |
| 211 |
|
| 212 |
When formatting fields in a delta, the Date::Manip 6.00 formats have changed |
| 213 |
and are much more powerful. The old 5.xx formats are still available for |
| 214 |
the Delta_Format command for backward compatibility. These formats include: |
| 215 |
|
| 216 |
%Xv : print the value of the field X |
| 217 |
|
| 218 |
%Xd : print the value of the field X and all |
| 219 |
smaller units in terms of X |
| 220 |
|
| 221 |
%Xh : print the value of field X and all |
| 222 |
larger units in terms of X |
| 223 |
|
| 224 |
%Xt : print the value of all fields in |
| 225 |
terms of X |
| 226 |
|
| 227 |
These make use of the $mode and $dec arguments to determine how to |
| 228 |
format the information. |
| 229 |
|
| 230 |
$dec is an integer, and is required, It tells the number of decimal |
| 231 |
places to use. |
| 232 |
|
| 233 |
$mode is either "exact", "semi", or "approx" and defaults to "exact" |
| 234 |
if it is not included. |
| 235 |
|
| 236 |
In "exact" mode, only exact relationships are used. This means that |
| 237 |
there can be no mixing of the Y/M, W/D, and H/MN/S segments (for |
| 238 |
non-business deltas, or Y/M, W, and D/H/MN/S segments for business |
| 239 |
deltas) because there is no exact relation between the fields of each |
| 240 |
set. |
| 241 |
|
| 242 |
In "semi" mode, the semi-approximate relationships are used so |
| 243 |
there is no mixing between Y/M and W/D/H/MN/S. |
| 244 |
|
| 245 |
In "approx" mode, approximate relationships are used so all fields |
| 246 |
can mix. |
| 247 |
|
| 248 |
The semi-approximate and approximate relationships are described in |
| 249 |
the Date::Manip::Delta manual. |
| 250 |
|
| 251 |
So, in "exact" mode, with a non-business delta, and $dec = 2, the |
| 252 |
following are equivalent: |
| 253 |
|
| 254 |
old style new style |
| 255 |
--------- --------- |
| 256 |
%Xv %Xv |
| 257 |
%hd %.2hhs |
| 258 |
%hh %.2hdh |
| 259 |
%ht %.2hds |
| 260 |
%yd %.2yyM |
| 261 |
|
| 262 |
In "approximate" mode, the following are equivalent: |
| 263 |
|
| 264 |
old style new style |
| 265 |
--------- --------- |
| 266 |
%Xv %Xv |
| 267 |
%hd %.2hhs |
| 268 |
%hh %.2hdh |
| 269 |
%ht %.2hys |
| 270 |
%yd %.2yys |
| 271 |
|
| 272 |
If you want to use the new style formats in Delta_Format, use one of |
| 273 |
the calls: |
| 274 |
|
| 275 |
Delta_Format($delta, @in); |
| 276 |
Delta_Format($delta, undef, @in); |
| 277 |
|
| 278 |
If the first element of @in is an integer, you have to use the 2nd |
| 279 |
form. |
| 280 |
|
| 281 |
The old formats will remain available for the time being, though at |
| 282 |
some point they may be deprecated. |
| 283 |
|
| 284 |
=item B<DateCalc> |
| 285 |
|
| 286 |
$d = DateCalc($d1,$d2 [,\$err] [,$mode]); |
| 287 |
|
| 288 |
This takes two dates, deltas, or one of each and performs the appropriate |
| 289 |
calculation with them. Dates must be a string that can be parsed by |
| 290 |
ParseDateString. Deltas must be a string that can be parsed by |
| 291 |
ParseDateDelta. Two deltas add together to form a third delta. A date |
| 292 |
and a delta returns a 2nd date. Two dates return a delta (the difference |
| 293 |
between the two dates). |
| 294 |
|
| 295 |
Since the two items can be interpreted as either dates or deltas, and |
| 296 |
since many strings can be interpreted as both a date or a delta, it |
| 297 |
is a good idea to pass the input through ParseDateDelta, |
| 298 |
if appropriate if there is any ambiguity. For example, the string |
| 299 |
"09:00:00" can be interpreted either as a date (today at 9:00:00) or a |
| 300 |
delta (9 hours). To avoid unexpected results, avoid calling DateCalc |
| 301 |
as: |
| 302 |
|
| 303 |
$d = DateCalc("09:00:00",$someothervalue); |
| 304 |
|
| 305 |
Instead, call it as: |
| 306 |
|
| 307 |
$d = DateCalc(ParseDate("09:00:00"),$someothervalue); |
| 308 |
|
| 309 |
to force it to be a date, or: |
| 310 |
|
| 311 |
$d = DateCalc(ParseDateDelta("09:00:00"),$someothervalue); |
| 312 |
|
| 313 |
to force it to be a delta. This will avoid unexpected results. |
| 314 |
Passing something through ParseDate is optional since they will be |
| 315 |
treated as dates by default (and for performance reasons, you're |
| 316 |
better off not calling ParseDate). |
| 317 |
|
| 318 |
If there is no ambiguity, you are better off NOT doing this for |
| 319 |
performance reasons. If the delta is a business delta, you definitely |
| 320 |
should NOT do this. |
| 321 |
|
| 322 |
One other thing to note is that when parsing dates, a delta can |
| 323 |
be interpreted as a date relative to now. DateCalc will ALWAYS |
| 324 |
treat a delta as a delta, NOT a date. |
| 325 |
|
| 326 |
For details on how calculations are done, refer to the Date::Manip::Calc |
| 327 |
documentation. |
| 328 |
|
| 329 |
By default, math is done using an exact mode. |
| 330 |
|
| 331 |
If two deltas, or a date and a delta are passed in, $mode may be used |
| 332 |
to force the delta to be either business or non-business mode deltas. |
| 333 |
If $mode is 0 or 1, the delta(s) will be non-business. Otherwise, |
| 334 |
they will be business deltas. If $mode is passed in, it will be used |
| 335 |
only if the business or non-business state was not explicitly set in |
| 336 |
the delta. $mode can also be any of the modes discussed in |
| 337 |
the Date::Manip::Calc documentation. |
| 338 |
|
| 339 |
If two dates are passed in, $mode is used to determine the type of |
| 340 |
calculation. By default, an exact delta is produced. If $mode is 1, |
| 341 |
an approximate delta is produced. If $mode is 2, a business |
| 342 |
approximate (bapprox) mode calculation is done. If $mode is 3, a |
| 343 |
exact business mode delta is produced. |
| 344 |
|
| 345 |
If \$err is passed in, it is set to: |
| 346 |
|
| 347 |
1 is returned if $d1 is not a delta or date |
| 348 |
2 is returned if $d2 is not a delta or date |
| 349 |
3 if any other error occurs. |
| 350 |
|
| 351 |
This argument is optional, but if included, it must come before $mode. |
| 352 |
|
| 353 |
Nothing is returned if an error occurs. |
| 354 |
|
| 355 |
=item B<ParseRecur> |
| 356 |
|
| 357 |
$recur = ParseRecur($string [,$base,$date0,$date1,$flags]); |
| 358 |
@dates = ParseRecur($string [,$base,$date0,$date1,$flags]); |
| 359 |
|
| 360 |
This parses a string containing a recurrence and returns a fully specified |
| 361 |
recurrence, or a list of dates referred to. |
| 362 |
|
| 363 |
$string can be any of the forms: |
| 364 |
|
| 365 |
FREQ |
| 366 |
FREQ*FLAGS |
| 367 |
FREQ*FLAGS*BASE |
| 368 |
FREQ*FLAGS*BASE*DATE0 |
| 369 |
FREQ*FLAGS*BASE*DATE0*DATE1 |
| 370 |
|
| 371 |
where FREQ is a frequence (see the Date::Manip::Delta documentation), |
| 372 |
FLAGS is a comma separated list of flags, and BASE, DATE0, and DATE1 are |
| 373 |
date strings. The dates and flags can also be passed in as $base, $date0, |
| 374 |
$date1, and $flags, and these will override any values in $string. |
| 375 |
|
| 376 |
In scalar context, the fully specified recurrence (or as much information |
| 377 |
as is available) will be returned. In list context, a list of dates will |
| 378 |
be returned. |
| 379 |
|
| 380 |
=item B<Date_Cmp> |
| 381 |
|
| 382 |
$flag = Date_Cmp($date1,$date2); |
| 383 |
|
| 384 |
This takes two dates and compares them. Any dates that can be parsed will be |
| 385 |
compared. |
| 386 |
|
| 387 |
=item B<Date_GetPrev> |
| 388 |
|
| 389 |
$date = Date_GetPrev($date,$dow, $curr [,$hr,$min,$sec]); |
| 390 |
$date = Date_GetPrev($date,$dow, $curr [,$time]); |
| 391 |
$date = Date_GetPrev($date,undef,$curr,$hr,$min,$sec); |
| 392 |
$date = Date_GetPrev($date,undef,$curr,$time); |
| 393 |
|
| 394 |
This takes a date (any string that may be parsed by ParseDateString) and finds |
| 395 |
the previous occurrence of either a day of the week, or a certain time of day. |
| 396 |
|
| 397 |
This is documented in the "prev" method in Date::Manip::Date, except that |
| 398 |
here, $time is a string (HH, HH:MN:, or HH:MN:SS), and $dow may be a string |
| 399 |
of the form "Fri" or "Friday". |
| 400 |
|
| 401 |
=item B<Date_GetNext> |
| 402 |
|
| 403 |
$date = Date_GetNext($date,$dow, $curr [,$hr,$min,$sec]); |
| 404 |
$date = Date_GetNext($date,$dow, $curr [,$time]); |
| 405 |
$date = Date_GetNext($date,undef,$curr,$hr,$min,$sec); |
| 406 |
$date = Date_GetNext($date,undef,$curr,$time); |
| 407 |
|
| 408 |
Similar to Date_GetPrev. |
| 409 |
|
| 410 |
=item B<Date_SetTime> |
| 411 |
|
| 412 |
$date = Date_SetTime($date,$hr,$min,$sec); |
| 413 |
$date = Date_SetTime($date,$time); |
| 414 |
|
| 415 |
This takes a date (any string that may be parsed by ParseDateString) and |
| 416 |
sets the time in that date. For example, one way to get the time for 7:30 |
| 417 |
tomorrow would be to use the lines: |
| 418 |
|
| 419 |
$date = ParseDate("tomorrow"); |
| 420 |
$date = Date_SetTime($date,"7:30"); |
| 421 |
|
| 422 |
$time is a string (HH, HH:MN, or HH:MN:SS). |
| 423 |
|
| 424 |
=item B<Date_SetDateField> |
| 425 |
|
| 426 |
$date = Date_SetDateField($date,$field,$val); |
| 427 |
|
| 428 |
This takes a date and sets one of its fields to a new value. $field is |
| 429 |
any of the strings "y", "m", "d", "h", "mn", "s" (case insensitive) and |
| 430 |
$val is the new value. |
| 431 |
|
| 432 |
=item B<Date_IsHoliday> |
| 433 |
|
| 434 |
$name = Date_IsHoliday($date); |
| 435 |
@name = Date_IsHoliday($date); |
| 436 |
|
| 437 |
This returns undef if $date is not a holiday, or a string containing |
| 438 |
the name of the holiday otherwise (or a list of names in list |
| 439 |
context). An empty string is returned for an unnamed holiday. |
| 440 |
|
| 441 |
=item B<Date_IsWorkDay> |
| 442 |
|
| 443 |
$flag = Date_IsWorkDay($date [,$flag]); |
| 444 |
|
| 445 |
This returns 1 if $date is a work day. If $flag is non-zero, the time is |
| 446 |
checked to see if it falls within work hours. It returns an empty string |
| 447 |
if $date is not valid. |
| 448 |
|
| 449 |
=item B<Events_List> |
| 450 |
|
| 451 |
$ref = Events_List($date); |
| 452 |
$ref = Events_List($date,0 [,$flag]); |
| 453 |
$ref = Events_List($date,$date1 [,$flag]); |
| 454 |
|
| 455 |
This returns a list of events. If $flag is not given, or is equal to 0, |
| 456 |
the list (returned as a reference) is similar to the the list returned |
| 457 |
by the Date::Manip::Date::list_events method with $format = "dates". |
| 458 |
The only difference is that it is formatted slightly different to be |
| 459 |
backward compatible with Date::Manip 5.xx. |
| 460 |
|
| 461 |
The data from the list_events method is: |
| 462 |
|
| 463 |
( [DATE1, NAME1a, NAME1b, ...], |
| 464 |
[DATE2, NAME2a, NAME2b, ...], |
| 465 |
... |
| 466 |
) |
| 467 |
|
| 468 |
The reference returned from Events_List (if $flag = 0) is: |
| 469 |
|
| 470 |
[ DATE1, [NAME1a, NAME1b, ...], |
| 471 |
DATE2, [DATE2a, DATE2b, ...], |
| 472 |
... |
| 473 |
] |
| 474 |
|
| 475 |
For example, if the following events are defined: |
| 476 |
|
| 477 |
2000-01-01 ; 2000-03-21 = Winter |
| 478 |
2000-03-22 ; 2000-06-21 = Spring |
| 479 |
2000-02-01 = Event1 |
| 480 |
2000-05-01 = Event2 |
| 481 |
2000-04-01-12:00:00 = Event3 |
| 482 |
|
| 483 |
the following examples illustrate the function: |
| 484 |
|
| 485 |
Events_List("2000-04-01") |
| 486 |
=> [ 2000040100:00:00, [ Spring ] ] |
| 487 |
|
| 488 |
Events_List("2000-04-01 12:30"); |
| 489 |
=> [ 2000040112:30:00, [ Spring, Event3 ] ] |
| 490 |
|
| 491 |
Events_List("2000-04-01",0); |
| 492 |
=> [ 2000040100:00:00, [ Spring ], |
| 493 |
2000040112:00:00, [ Spring, Event3 ], |
| 494 |
2000040113:00:00, [ Spring ] ] |
| 495 |
|
| 496 |
Events_List("2000-03-15","2000-04-10"); |
| 497 |
=> [ 2000031500:00:00, [ Winter ], |
| 498 |
2000032200:00:00, [ Spring ] |
| 499 |
2000040112:00:00, [ Spring, Event3 ] |
| 500 |
2000040113:00:00, [ Spring ] ] |
| 501 |
|
| 502 |
If $flag is 1, then a tally of the amount of time given to each event |
| 503 |
is returned. Time for which two or more events apply is counted for |
| 504 |
both. |
| 505 |
|
| 506 |
Events_List("2000-03-15","2000-04-10",1); |
| 507 |
=> { Event3 => +0:0:+0:0:1:0:0, |
| 508 |
Spring => +0:0:+2:4:23:0:0, |
| 509 |
Winter => +0:0:+1:0:0:0:0 |
| 510 |
} |
| 511 |
|
| 512 |
When $flag is 2, a more complex tally with no event counted twice is |
| 513 |
returned. |
| 514 |
|
| 515 |
Events_List("2000-03-15","2000-04-10",2); |
| 516 |
=> { Event3+Spring => +0:0:+0:0:1:0:0, |
| 517 |
Spring => +0:0:+2:4:22:0:0, |
| 518 |
Winter => +0:0:+1:0:0:0:0 |
| 519 |
} |
| 520 |
|
| 521 |
The hash contains one element for each combination of events. |
| 522 |
|
| 523 |
In both of these cases, there may be a hash element with an empty |
| 524 |
string as the key which contains the amount of time with no events |
| 525 |
active. |
| 526 |
|
| 527 |
=item B<Date_DayOfWeek> |
| 528 |
|
| 529 |
$day = Date_DayOfWeek($m,$d,$y); |
| 530 |
|
| 531 |
Returns the day of the week (1 for Monday, 7 for Sunday). |
| 532 |
|
| 533 |
=item B<Date_SecsSince1970> |
| 534 |
|
| 535 |
$secs = Date_SecsSince1970($m,$d,$y,$h,$mn,$s); |
| 536 |
|
| 537 |
Returns the number of seconds since Jan 1, 1970 00:00 (negative if date is |
| 538 |
earlier) in the current timezone. |
| 539 |
|
| 540 |
=item B<Date_SecsSince1970GMT> |
| 541 |
|
| 542 |
$secs = Date_SecsSince1970GMT($m,$d,$y,$h,$mn,$s); |
| 543 |
|
| 544 |
Returns the number of seconds since Jan 1, 1970 00:00 GMT (negative if date |
| 545 |
is earlier). Note that the date is still given in the current timezone, NOT |
| 546 |
GMT. |
| 547 |
|
| 548 |
=item B<Date_DaysSince1BC> |
| 549 |
|
| 550 |
$days = Date_DaysSince1BC($m,$d,$y); |
| 551 |
|
| 552 |
Returns the number of days since Dec 31, 1BC. This includes the year 0001. |
| 553 |
|
| 554 |
=item B<Date_DayOfYear> |
| 555 |
|
| 556 |
$day = Date_DayOfYear($m,$d,$y); |
| 557 |
|
| 558 |
Returns the day of the year (1 to 366) |
| 559 |
|
| 560 |
=item B<Date_NthDayOfYear> |
| 561 |
|
| 562 |
($y,$m,$d,$h,$mn,$s) = Date_NthDayOfYear($y,$n); |
| 563 |
|
| 564 |
Returns the year, month, day, hour, minutes, and decimal seconds given |
| 565 |
a floating point day of the year. |
| 566 |
|
| 567 |
All arguments must be numeric. $n must be greater than or equal to 1 |
| 568 |
and less than 366 on non-leap years and 367 on leap years. |
| 569 |
|
| 570 |
NOTE: When $n is a decimal number, the results are non-intuitive perhaps. |
| 571 |
Day 1 is Jan 01 00:00. Day 2 is Jan 02 00:00. Intuitively, you |
| 572 |
might think of day 1.5 as being 1.5 days after Jan 01 00:00, but this |
| 573 |
would mean that Day 1.5 was Jan 02 12:00 (which is later than Day 2). |
| 574 |
The best way to think of this function is a time line starting at 1 and |
| 575 |
ending at 366 (in a non-leap year). In terms of a delta, think of $n |
| 576 |
as the number of days after Dec 31 00:00 of the previous year. |
| 577 |
|
| 578 |
=item B<Date_DaysInYear> |
| 579 |
|
| 580 |
$days = Date_DaysInYear($y); |
| 581 |
|
| 582 |
Returns the number of days in the year (365 or 366) |
| 583 |
|
| 584 |
=item B<Date_DaysInMonth> |
| 585 |
|
| 586 |
$days = Date_DaysInMonth($m,$y); |
| 587 |
|
| 588 |
Returns the number of days in the month. |
| 589 |
|
| 590 |
=item B<Date_WeekOfYear> |
| 591 |
|
| 592 |
$wkno = Date_WeekOfYear($m,$d,$y,$first); |
| 593 |
|
| 594 |
Figure out week number. $first is the first day of the week which is |
| 595 |
usually 1 (Monday) or 7 (Sunday), but could be any number between 1 and 7 |
| 596 |
in practice. |
| 597 |
|
| 598 |
NOTE: This routine should only be called in rare cases. Use printf |
| 599 |
with the %W, %U, %J, %L formats instead as that will always return the |
| 600 |
correct values for week and year. |
| 601 |
|
| 602 |
This routine returns a week between 0 and 53 which must then be |
| 603 |
"fixed" to get into the ISO 8601 weeks from 1 to 53. A date which |
| 604 |
returns a week of 0 actually belongs to the last week of the previous |
| 605 |
year. A date which returns a week of 53 may belong to the first week |
| 606 |
of the next year. |
| 607 |
|
| 608 |
=item B<Date_LeapYear> |
| 609 |
|
| 610 |
$flag = Date_LeapYear($y); |
| 611 |
|
| 612 |
Returns 1 if the argument is a leap year |
| 613 |
Written by David Muir Sharnoff <[email protected]> |
| 614 |
|
| 615 |
=item B<Date_DaySuffix> |
| 616 |
|
| 617 |
$day = Date_DaySuffix($d); |
| 618 |
|
| 619 |
Add `st', `nd', `rd', `th' to a date (i.e. 1st, 22nd, 29th). Works for |
| 620 |
international dates. |
| 621 |
|
| 622 |
=item B<Date_TimeZone> |
| 623 |
|
| 624 |
$tz = Date_TimeZone; |
| 625 |
|
| 626 |
This determines and returns the local time zone. If it is unable to determine |
| 627 |
the local time zone, the following error occurs: |
| 628 |
|
| 629 |
ERROR: Date::Manip unable to determine Time Zone. |
| 630 |
|
| 631 |
See the Date::Manip::TZ documentation (DETERMINING THE LOCAL TIME ZONE) for |
| 632 |
more information. |
| 633 |
|
| 634 |
=item B<Date_ConvTZ> |
| 635 |
|
| 636 |
$date = Date_ConvTZ($date,$from,$to); |
| 637 |
|
| 638 |
This converts a date (which MUST be in the format returned by ParseDate) |
| 639 |
from one time zone to another. |
| 640 |
|
| 641 |
$from and $to each default to the local time zone. If they are given, |
| 642 |
they must be any time zone or alias understood by Date::Manip. |
| 643 |
|
| 644 |
If an error occurs, an empty string is returned. |
| 645 |
|
| 646 |
=item B<Date_NextWorkDay> |
| 647 |
|
| 648 |
$date = Date_NextWorkDay($date,$off [,$time]); |
| 649 |
|
| 650 |
Finds the day $off work days from now. If $time is passed in, we must also |
| 651 |
take into account the time of day. |
| 652 |
|
| 653 |
If $time is not passed in, day 0 is today (if today is a workday) or the |
| 654 |
next work day if it isn't. In any case, the time of day is unaffected. |
| 655 |
|
| 656 |
If $time is passed in, day 0 is now (if now is part of a workday) or the |
| 657 |
start of the very next work day. |
| 658 |
|
| 659 |
=item B<Date_PrevWorkDay> |
| 660 |
|
| 661 |
$date = Date_PrevWorkDay($date,$off [,$time]); |
| 662 |
|
| 663 |
Similar to Date_NextWorkDay. |
| 664 |
|
| 665 |
=item B<Date_NearestWorkDay> |
| 666 |
|
| 667 |
$date = Date_NearestWorkDay($date [,$tomorrowfirst]); |
| 668 |
|
| 669 |
This looks for the work day nearest to $date. If $date is a work day, it |
| 670 |
is returned. Otherwise, it will look forward or backwards in time 1 day |
| 671 |
at a time until a work day is found. If $tomorrowfirst is non-zero (or if |
| 672 |
it is omitted and the config variable TomorrowFirst is non-zero), we look |
| 673 |
to the future first. Otherwise, we look in the past first. In other words, |
| 674 |
in a normal week, if $date is Wednesday, $date is returned. If $date is |
| 675 |
Saturday, Friday is returned. If $date is Sunday, Monday is returned. If |
| 676 |
Wednesday is a holiday, Thursday is returned if $tomorrowfirst is non-nil |
| 677 |
or Tuesday otherwise. |
| 678 |
|
| 679 |
=back |
| 680 |
|
| 681 |
For all of the functions which return a date, the format of the returned |
| 682 |
date is governed by the Printable config variable. If a date is returned, |
| 683 |
it is in the local time zone, NOT the time zone the date was parsed in. |
| 684 |
|
| 685 |
=head1 SEE ALSO |
| 686 |
|
| 687 |
Date::Manip - main module documentation |
| 688 |
|
| 689 |
=head1 LICENSE |
| 690 |
|
| 691 |
This script is free software; you can redistribute it and/or |
| 692 |
modify it under the same terms as Perl itself. |
| 693 |
|
| 694 |
=head1 AUTHOR |
| 695 |
|
| 696 |
Sullivan Beck ([email protected]) |
| 697 |
|
| 698 |
=cut |