| 1 |
# Copyright (c) 1996-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::Config - Date::Manip configuration |
| 10 |
|
| 11 |
=head1 SYNOPSIS |
| 12 |
|
| 13 |
This documents the configuration information which is stored in |
| 14 |
each L<Date::Manip::Base> object, how to modify this information, |
| 15 |
and how the information is used in the other Date::Manip modules. |
| 16 |
|
| 17 |
=head1 DESCRIPTION |
| 18 |
|
| 19 |
Date::Manip is a very configurable bundle of modules. Many of it's |
| 20 |
behaviors can be modified to change how date operations are done. To |
| 21 |
do this, a list of configuration variables may be set which define |
| 22 |
many Date::Manip behaviors. |
| 23 |
|
| 24 |
There are three ways to set config variables. The first two are to |
| 25 |
pass them in when creating an object, or to pass them to the config |
| 26 |
method after the object is created. All of the main Date::Manip |
| 27 |
modules (L<Date::Manip::Base>, L<Date::Manip::TZ>, L<Date::Manip::Date>, |
| 28 |
L<Date::Manip::Delta>, and L<Date::Manip::Recur>) have the config method. |
| 29 |
|
| 30 |
As an example, you can create and configure a |
| 31 |
L<Date::Manip::Date> object using the commands: |
| 32 |
|
| 33 |
$date = new Date::Manip::Date; |
| 34 |
$date->config($var1,$val1,$var2,$val2,...); |
| 35 |
|
| 36 |
This can be shortened to: |
| 37 |
|
| 38 |
$date = new Date::Manip::Date [$var1,$val1,...]; |
| 39 |
|
| 40 |
The values of the config variables are stored in the L<Date::Manip::Base> |
| 41 |
object. So, if you have a L<Date::Manip::Date> object, it has a |
| 42 |
L<Date::Manip::Base> object associated with it, and the configuration |
| 43 |
information is stored there. The same L<Date::Manip::Base> object may be |
| 44 |
used by any number of higher objects, and all will share the same |
| 45 |
configuration. If multiple L<Date::Manip::Date> objects share the same |
| 46 |
L<Date::Manip::Base> object, setting a configuration variable on any of |
| 47 |
them affects all of the L<Date::Manip::Date> objects. If you need to work |
| 48 |
with different configurations simultaneously, it is necessary to work |
| 49 |
with multiple L<Date::Manip::Base> objects. This is covered in the |
| 50 |
L<Date::Manip::Objects> document. |
| 51 |
|
| 52 |
An alternate method exists if you are using one of the functional |
| 53 |
interfaces. To set a variable using the functional interface, use the |
| 54 |
call: |
| 55 |
|
| 56 |
Date_Init("$var1=$val1"); |
| 57 |
|
| 58 |
The third way to set config variables is to store them in a config |
| 59 |
file. The config file is read in by passing the appropriate values to |
| 60 |
the config method as described below. A config file is a good way to |
| 61 |
easily change a large number of settings. They are also necessary for |
| 62 |
other purposes (such as events and holidays which are covered |
| 63 |
in the L<Date::Manip::Holidays> document). |
| 64 |
|
| 65 |
=head1 CONFIG FILES |
| 66 |
|
| 67 |
One of the variables that can be passed to the config method is |
| 68 |
"ConfigFile". The value of this variable is the path to a config |
| 69 |
file. |
| 70 |
|
| 71 |
When any Date::Manip::* object is configured, any number of config |
| 72 |
files may be read (and the config files can specify additional files |
| 73 |
to read). |
| 74 |
|
| 75 |
The starting section of a config file contains general configuration |
| 76 |
variables. A list of all config variables is given below. |
| 77 |
|
| 78 |
Following this, any number of special sections may be included in |
| 79 |
the config file. The special sections are used to specify other |
| 80 |
types of information, such as a list of holidays or special events. |
| 81 |
These special sections are described elsewhere in the documentation. |
| 82 |
|
| 83 |
The syntax of the config file is very simple. Every line is of |
| 84 |
the form: |
| 85 |
|
| 86 |
VAR = VAL |
| 87 |
|
| 88 |
or |
| 89 |
|
| 90 |
*SECTION |
| 91 |
|
| 92 |
Blank lines and lines beginning with a pound sign (#) are ignored. |
| 93 |
All whitespace is optional. Variables names in the main section and |
| 94 |
section names are case insensitive (though values in the main section |
| 95 |
are typically case sensitive). Strings in other sections (both variables |
| 96 |
and values) are case sensitive. |
| 97 |
|
| 98 |
The following is a sample config file: |
| 99 |
|
| 100 |
DateFormat = US |
| 101 |
Language = English |
| 102 |
|
| 103 |
*Holidays |
| 104 |
|
| 105 |
Dec 25 = Christmas |
| 106 |
Jan 1 = New Year's |
| 107 |
|
| 108 |
All config variables that may appear in the main part of a config file |
| 109 |
are described in the next section. Other sections are described elsewhere. |
| 110 |
The *Holidays and *Events sections are both described in the |
| 111 |
L<Date::Manip::Holidays> documentation. |
| 112 |
|
| 113 |
A sample config file is included with the Date::Manip distribution. |
| 114 |
Modify it as appropriate and copy it to some appropriate directory and |
| 115 |
use the ConfigFile variable to access it. For example, if a config |
| 116 |
file is stored in F</home/foo/Manip.cnf>, you can load it by: |
| 117 |
|
| 118 |
$date->config("ConfigFile","/home/foo/Manip.cnf"); |
| 119 |
|
| 120 |
or (if using a functional interface): |
| 121 |
|
| 122 |
Date_Init("ConfigFile=/home/foo/Manip.cnf"); |
| 123 |
|
| 124 |
NOTE: if you use business mode calculations, you must have a config |
| 125 |
file since this is the only place where you can define holidays. |
| 126 |
|
| 127 |
In the top section, only variables described below may be used. In |
| 128 |
other sections, checking (if any) is done in the module that uses |
| 129 |
the data from that section. |
| 130 |
|
| 131 |
=head1 BASIC CONFIGURATION VARIABLES |
| 132 |
|
| 133 |
This section describes the basic Date::Manip configuration variables |
| 134 |
which can be used in a config file, or which may be passed in using |
| 135 |
the appropriate functions for each module. |
| 136 |
|
| 137 |
Variable names are case insensitive, both as arguments to the config |
| 138 |
function and in the config file. The values are case sensitive except |
| 139 |
where specified otherwise. |
| 140 |
|
| 141 |
=over 4 |
| 142 |
|
| 143 |
=item B<Defaults> |
| 144 |
|
| 145 |
The value for this config variable is ignored. Whenever the Defaults |
| 146 |
config variable is encountered, the defaults for all config variables |
| 147 |
are restored, overriding ALL changes that have been made. |
| 148 |
|
| 149 |
In other words, in the following call: |
| 150 |
|
| 151 |
$date->config("Language","Russian", |
| 152 |
"Defaults","1"); |
| 153 |
|
| 154 |
the first option will end up being ignored since the Defaults config |
| 155 |
variable will set the language back to it's default value which is |
| 156 |
English. |
| 157 |
|
| 158 |
When using a functional interface, use: |
| 159 |
|
| 160 |
Date_Init("Defaults=1"); |
| 161 |
|
| 162 |
=item B<ConfigFile> |
| 163 |
|
| 164 |
The ConfigFile variable defines a config file which will be parsed for |
| 165 |
configuration information. It may be included any number of times, each |
| 166 |
one including the path to a single config file. The value of this |
| 167 |
variable is a full path to a file. |
| 168 |
|
| 169 |
An example call to the config function might be: |
| 170 |
|
| 171 |
$date->config("ConfigFile","/tmp/file1", |
| 172 |
'Language',$val); |
| 173 |
|
| 174 |
Config files are parsed immediately when encountered. So in this example, |
| 175 |
the file F</tmp/file1> will be parsed before the next variable ('Language'). |
| 176 |
In addition, if a config file contains a ConfigFile variable, that file |
| 177 |
will immediately be parsed before continuing with the original file. |
| 178 |
|
| 179 |
The path to the file may be specified in any way valid for the |
| 180 |
operating system. If a file is not found, a warning will be issued, |
| 181 |
but execution will continue. |
| 182 |
|
| 183 |
Multiple config files are safe, and a section may safely be split |
| 184 |
across multiple files. |
| 185 |
|
| 186 |
When using a functional interface, use: |
| 187 |
|
| 188 |
Date_Init("ConfigFile=/tmp/file1"); |
| 189 |
|
| 190 |
=item B<Language> |
| 191 |
|
| 192 |
Date::Manip can be used to parse dates in many different languages. |
| 193 |
A list of the languages is given in the L<Date::Manip::Lang> document. |
| 194 |
|
| 195 |
To parse dates in a different language, just use the Language config |
| 196 |
variable with the name of the language as the value. Language names |
| 197 |
are case insensitive. |
| 198 |
|
| 199 |
Additional languages may be added with the help of someone fluent in |
| 200 |
English and the other language. If you are interested in providing a |
| 201 |
translation for a new language, please refer to the L<Date::Manip::Lang> |
| 202 |
document for instructions. |
| 203 |
|
| 204 |
=item B<Encoding> |
| 205 |
|
| 206 |
Date::Manip has some support for handling date strings encoded in |
| 207 |
alternate character encodings. |
| 208 |
|
| 209 |
By default, input strings may be tested using multiple encodings that |
| 210 |
are commonly used for the specific languages, as well as using |
| 211 |
standard perl escape sequences, and output is done in UTF-8. |
| 212 |
|
| 213 |
The input, output, or both can be overridden using the Encoding |
| 214 |
variable. |
| 215 |
|
| 216 |
Setting Encoding to the name of a single encoding (a name supported |
| 217 |
by the Encoding perl module), will force all input and output to be |
| 218 |
done in that encoding. |
| 219 |
|
| 220 |
So, setting: |
| 221 |
|
| 222 |
Encoding = iso-8859-1 |
| 223 |
|
| 224 |
means that all input and output will be in that encoding. The |
| 225 |
encoding 'perl' has the special meaning of storing the string in |
| 226 |
perl escape sequences. |
| 227 |
|
| 228 |
Encoding can also be set to the name of two encoding (separated |
| 229 |
by a comma). |
| 230 |
|
| 231 |
Encoding = iso-8859-1,utf-16 |
| 232 |
|
| 233 |
which means that all input is in iso-8859-1 encoding, but all output |
| 234 |
will be utf-16. |
| 235 |
|
| 236 |
Encoding may also be set as follows: |
| 237 |
|
| 238 |
Encoding = iso-8859-1, |
| 239 |
|
| 240 |
meaning that input is in iso-8859-1 and output is in the default (i.e. |
| 241 |
UTF-8) encoding. |
| 242 |
|
| 243 |
Encoding = ,utf-16 |
| 244 |
|
| 245 |
means to check the input in all of the encodings, but all output will |
| 246 |
be in utf-16 encoding. |
| 247 |
|
| 248 |
Note that any time you change languages, it will reset the encodings, |
| 249 |
so you should set this config variable AFTER setting the language. |
| 250 |
|
| 251 |
=item B<FirstDay> |
| 252 |
|
| 253 |
It is sometimes necessary to know what day of week is regarded as |
| 254 |
first. By default, this is set to Monday as that conforms to ISO |
| 255 |
8601, but many countries and people will prefer Sunday (and in a few |
| 256 |
cases, a different day may be desired). Set the FirstDay variable to |
| 257 |
be a digit 1-7 corresponding to the day of the week (1=Monday to 7=Sunday). |
| 258 |
|
| 259 |
=item B<Week1ofYear> |
| 260 |
|
| 261 |
This variable (along with the FirstDay variable) is used to define |
| 262 |
exactly when the first week of the year begins. |
| 263 |
|
| 264 |
If the value is 'janX' (where X is a digit 1-7), then it means that the |
| 265 |
first week of the year contains that date. The default ISO 8601 definition |
| 266 |
of a week is that it is the first week containing January 4, so the default |
| 267 |
value of this variable is 'jan4'. |
| 268 |
|
| 269 |
If the value is 'dowX' (where X is a digit 1-7), then the first week |
| 270 |
of the year is the one that contains the first occurrence of the DoW |
| 271 |
given (X=1 is Monday, X=7 is Sunday). So, if you want the first week |
| 272 |
to be the one that contains the first Monday of the year, use 'dow1'. |
| 273 |
|
| 274 |
If the value is 'firstday', then the first week of the year is the one |
| 275 |
that contains the first occurrence of the DoW given in the FirstDay |
| 276 |
config variable. |
| 277 |
|
| 278 |
=item B<Printable> |
| 279 |
|
| 280 |
Some commands may produce a printable version of a date. By default, |
| 281 |
the printable version of the date is of the format: |
| 282 |
|
| 283 |
YYYYMMDDHH:MN:SS |
| 284 |
|
| 285 |
Two other simple versions have been created. If the Printable variable is |
| 286 |
set to 1, the format is: |
| 287 |
|
| 288 |
YYYYMMDDHHMNSS |
| 289 |
|
| 290 |
If Printable is set to 2, the format is: |
| 291 |
|
| 292 |
YYYY-MM-DD-HH:MN:SS |
| 293 |
|
| 294 |
This config variable is present in order to maintain backward |
| 295 |
compatibility, and may actually be deprecated at some point. As such, |
| 296 |
additional formats will not be added. Instead, use the printf method |
| 297 |
in the L<Date::Manip::Date> module to extract information with complete |
| 298 |
flexibility. |
| 299 |
|
| 300 |
=back |
| 301 |
|
| 302 |
=head1 DATE PARSING CONFIGURATION VARIABLES |
| 303 |
|
| 304 |
=over 4 |
| 305 |
|
| 306 |
=item B<DateFormat> |
| 307 |
|
| 308 |
Different countries look at the date 12/10 as Dec 10 or Oct 12. In |
| 309 |
the United States, the first is most common, but this certainly |
| 310 |
doesn't hold true for other countries. Setting DateFormat to "US" |
| 311 |
(case insensitive) forces the first behavior (Dec 10). Setting |
| 312 |
DateFormat to anything else forces the second behavior (Oct 12). The |
| 313 |
"US" setting is the default (sorry about that... I live in the US). |
| 314 |
|
| 315 |
=item B<YYtoYYYY> |
| 316 |
|
| 317 |
When parsing a date containing a 2-digit year, the year must be converted |
| 318 |
to 4 digits. This config variable determines how this is done. |
| 319 |
|
| 320 |
By default, a 2 digit year is treated as falling in the 100 year period of |
| 321 |
CURR-89 to CURR+10. So in the year 2005, a two digit year will be somewhere |
| 322 |
in the range 1916 to 2015. |
| 323 |
|
| 324 |
YYtoYYYY may be set to any integer N to force a 2 digit year into the |
| 325 |
period CURR-N to CURR+(99-N). A value of 0 forces the year to be the |
| 326 |
current year or later. A value of 99 forces the year to be the |
| 327 |
current year or earlier. Although the most common choice of values |
| 328 |
will be somewhere between 0 and 99, there is no restriction on N that |
| 329 |
forces it to be so. It can actually be any positive or negative number |
| 330 |
you want to force it into any 100 year period desired. |
| 331 |
|
| 332 |
YYtoYYYY can also be set to "C" to force it into the current century, or |
| 333 |
to "C##" to force it into a specific century. So, in 1998, "C" forces |
| 334 |
2 digit years to be 1900-1999. "C18" would always force a 2 digit year to |
| 335 |
be in the range 1800-1899. Note: I'm aware that the actual definitions of |
| 336 |
century are 1901-2000, NOT 1900-1999, so for purists, treat this as |
| 337 |
the way to supply the first two digits rather than as supplying a |
| 338 |
century. |
| 339 |
|
| 340 |
It can also be set to the form "C####" to force it into a specific 100 |
| 341 |
year period. C1950 refers to 1950-2049. |
| 342 |
|
| 343 |
=item B<DefaultTime> |
| 344 |
|
| 345 |
When a date is parsed from one of the formats listed in the "Common date formats" |
| 346 |
or "Less common formats" sections of the L<Date::Manip::Date> document, and no time |
| 347 |
is explicitly included, the default time can be determined by the value of this |
| 348 |
variable. The two possible values are: |
| 349 |
|
| 350 |
midnight the default time is 00:00:00 |
| 351 |
curr the default time is the current time |
| 352 |
|
| 353 |
"midnight" is the default value. |
| 354 |
|
| 355 |
NOTE: this only applies to dates parsed with the parse method. Dates parsed |
| 356 |
using the parse_date method always default to 00:00:00. |
| 357 |
|
| 358 |
=item B<PeriodTimeSep> |
| 359 |
|
| 360 |
By default, the time separator (i.e. the character that separates |
| 361 |
hours from minutes and minutes from seconds) is specified in the |
| 362 |
language translations and in most cases it does not include a period. |
| 363 |
In English, the only defined time separator is a colon (:), so the time |
| 364 |
can be written as 12:15:30 . |
| 365 |
|
| 366 |
If you want to use a period (.) as a time separator as well, set this |
| 367 |
to 1. Then you can write the time as 12.15.30 . |
| 368 |
|
| 369 |
By default, a period is used as a date separator, so 12.15.30 would be |
| 370 |
interpreted as Dec 15 1930 (or 2030), so if you use the period as a |
| 371 |
date separator, it should not be used as a time separator too. |
| 372 |
|
| 373 |
=item B<Format_MMMYYYY> |
| 374 |
|
| 375 |
By default, when parsing a string like 'Jun 1925', it will be interpreted |
| 376 |
as 'Jun 19, 2025' (i.e. MMM DDYY). Also, the string '1925 Jun' is not allowed. |
| 377 |
|
| 378 |
This variable can be set to either 'first' or 'last', and in that case, |
| 379 |
both 'Jun 1925' and '1925 Jun' will be allowed, and will refer to either |
| 380 |
the first or last day of June in 1925. |
| 381 |
|
| 382 |
=back |
| 383 |
|
| 384 |
=head1 BUSINESS CONFIGURATION VARIABLES |
| 385 |
|
| 386 |
These are configuration variables used to define work days and |
| 387 |
holidays used in business mode calculations. Refer to the |
| 388 |
L<Date::Manip::Calc> documentation for details on these calculations. |
| 389 |
|
| 390 |
=over 4 |
| 391 |
|
| 392 |
=item B<WorkWeekBeg> |
| 393 |
|
| 394 |
=item B<WorkWeekEnd> |
| 395 |
|
| 396 |
The first and last days of the work week. These default to Monday and |
| 397 |
Friday. Days are numbered from 1 (Monday) to 7 (Sunday). WorkWeekBeg |
| 398 |
must come before WorkWeekEnd numerically so there is no way to handle |
| 399 |
a work week of Sunday to Thursday using these variables. |
| 400 |
|
| 401 |
There is also no way to handle an odd work schedule such as 10 days |
| 402 |
on, 4 days off. |
| 403 |
|
| 404 |
However, both of these situations can be handled using a fairly simple |
| 405 |
workaround. |
| 406 |
|
| 407 |
To handle a work week of Sunday to Thursday, just set WorkWeekBeg=1 |
| 408 |
and WorkWeekEnd=7 and defined a holiday that occurs every Friday and |
| 409 |
Saturday. |
| 410 |
|
| 411 |
To handle a 10 days on, 4 days off schedule, do something similar |
| 412 |
but defined a holiday that occurs on all of the 4 days off. |
| 413 |
|
| 414 |
Both of these can be done using recurrences. Refer to the L<Date::Manip::Recur> |
| 415 |
documentation for details. |
| 416 |
|
| 417 |
=item B<WorkDay24Hr> |
| 418 |
|
| 419 |
=item B<WorkDayBeg> |
| 420 |
|
| 421 |
=item B<WorkDayEnd> |
| 422 |
|
| 423 |
If WorkDay24Hr is non-zero, a work day is treated as usually being 24 |
| 424 |
hours long (daylight saving time changes ARE taken into account). The |
| 425 |
WorkDayBeg and WorkDayEnd variables are ignored in this case. |
| 426 |
|
| 427 |
By default, WorkDay24Hr is zero, and the work day is defined by the |
| 428 |
WorkDayBeg and WorkDayEnd variables. These are the times when the work |
| 429 |
day starts and ends respectively. WorkDayBeg must come before |
| 430 |
WorkDayEnd (i.e. there is no way to handle the night shift where the |
| 431 |
work day starts one day and ends another). |
| 432 |
|
| 433 |
The time in both should be a valid time format (H, H:M, or H:M:S). |
| 434 |
|
| 435 |
Note that setting WorkDay24Hr to a non-zero value automatically sets |
| 436 |
WorkDayBeg and WorkDayEnd to "00:00:00" and "24:00:00" respectively, |
| 437 |
so to switch back to a non-24 hour day, you will need to reset both |
| 438 |
of those config variables. |
| 439 |
|
| 440 |
Similarly, setting either the WorkDayBeg or WorkDayEnd variables |
| 441 |
automatically turns off WorkDay24Hr. |
| 442 |
|
| 443 |
=item B<TomorrowFirst> |
| 444 |
|
| 445 |
Periodically, if a day is not a business day, we need to find the |
| 446 |
nearest business day to it. By default, we'll look to "tomorrow" |
| 447 |
first, but if this variable is set to 0, we'll look to "yesterday" |
| 448 |
first. This is only used in the |
| 449 |
C<Date::Manip::Date::nearest_business_day> method (and the |
| 450 |
C<Date_NearestWorkDay> function) and is easily overridden (see |
| 451 |
documentation for the nearest_business_day method). |
| 452 |
|
| 453 |
=item B<EraseHolidays> |
| 454 |
|
| 455 |
=item B<EraseEvents> |
| 456 |
|
| 457 |
If these variables are used (a value must be passed in, but is |
| 458 |
ignored), the current list of defined holidays or events is erased. A |
| 459 |
new set will be set the next time a config file is read in. |
| 460 |
|
| 461 |
Although these variables are supported, the best way to have multiple |
| 462 |
holiday or events lists will be to create multiple L<Date::Manip::Base> |
| 463 |
objects based on separate config files. |
| 464 |
|
| 465 |
=back |
| 466 |
|
| 467 |
=head1 RECURRENCE CONFIGURATION VARIABLES |
| 468 |
|
| 469 |
The following config variables help in the handling of recurrences. |
| 470 |
|
| 471 |
=over 4 |
| 472 |
|
| 473 |
=item B<RecurRange> |
| 474 |
|
| 475 |
When a recurrence is created, it begins with a default range (start |
| 476 |
and end date). The range selected depends on the value of this |
| 477 |
variable, and can be set to any of the following: |
| 478 |
|
| 479 |
none no default range supplied |
| 480 |
year the current year |
| 481 |
month the current month |
| 482 |
week the current week |
| 483 |
day the current day |
| 484 |
all Jan 2, 0001 to Dec 30, 9999 |
| 485 |
|
| 486 |
The default value is "none". |
| 487 |
|
| 488 |
=item B<MaxRecurAttempts> |
| 489 |
|
| 490 |
Occasionally, a recurrence is invalid (though it cannot be easily determined |
| 491 |
in advance). |
| 492 |
|
| 493 |
When searching for dates that match the recurrence, this is the maximum number |
| 494 |
of attempts that will be done. If none are found, the recurrence will be |
| 495 |
assumed to be invalid. |
| 496 |
|
| 497 |
=back |
| 498 |
|
| 499 |
=head1 TIME ZONE RELATED CONFIGURATION VARIABLES |
| 500 |
|
| 501 |
The following configuration variables may alter the current |
| 502 |
time zone. As such, they are only available once the L<Date::Manip::TZ> |
| 503 |
module is available. An easy way to handle this is to only pass them |
| 504 |
to the config method of a L<Date::Manip::TZ> object or one of the high |
| 505 |
level objects (L<Date::Manip::Date>, L<Date::Manip::Delta>, or |
| 506 |
L<Date::Manip::Recur>). |
| 507 |
|
| 508 |
Many of Date::Manip's operations rely on knowing what time it is |
| 509 |
now. This consists of three things: knowing what date and time it is, |
| 510 |
knowing what time zone it is, and knowing whether it is daylight |
| 511 |
saving or not. All of this is necessary in order to correctly handle |
| 512 |
every possible date. |
| 513 |
|
| 514 |
The daylight saving time information is only used for a couple hours |
| 515 |
each year during daylight saving time changes (at all other times, the |
| 516 |
date, time, and time zone are sufficient information), so it is |
| 517 |
optional, and defaults to standard time if omitted. |
| 518 |
|
| 519 |
The default behavior of Date::Manip is to use the system localtime |
| 520 |
function to determine the date, time, and daylight saving time |
| 521 |
information, and to use various methods (see |
| 522 |
L<Date::Manip::TZ/"DETERMINING THE SYSTEM TIME ZONE">) to determine what |
| 523 |
time zone the computer is in. |
| 524 |
|
| 525 |
=over 4 |
| 526 |
|
| 527 |
=item B<SetDate> |
| 528 |
|
| 529 |
The SetDate config variable is used to set the current date, time, or |
| 530 |
time zone, but then allow it to change over time using the rules of |
| 531 |
that time zone. |
| 532 |
|
| 533 |
There are several cases where this may be useful. |
| 534 |
|
| 535 |
Often, you may want to use the system time to get the date and time, but |
| 536 |
you want to work in another time zone. For this, use the call: |
| 537 |
|
| 538 |
$date->config("setdate","now,ZONE"); |
| 539 |
|
| 540 |
or in the function interface: |
| 541 |
|
| 542 |
Date_Init("setdate=now,ZONE"); |
| 543 |
|
| 544 |
If it is currently |
| 545 |
|
| 546 |
Jun 6, 2009 12:00:00 in the America/New_York time zone |
| 547 |
|
| 548 |
and you call: |
| 549 |
|
| 550 |
$date->config("setdate","now,Europe/Rome"); |
| 551 |
|
| 552 |
the Date::Manip will treat that exact instant as |
| 553 |
|
| 554 |
Jun 6, 2009 12:00:00 in the Europe/Rome time zone |
| 555 |
|
| 556 |
At that precise moment, looking at the system time and parsing the |
| 557 |
date "now" in Date::Manip will give the same date and time. |
| 558 |
|
| 559 |
The time will continue to advance, but it will use time change rules |
| 560 |
from the Europe/Rome time zone. What that means is that if a daylight |
| 561 |
saving time occurs on the computer, but NOT in the Europe/Rome |
| 562 |
time zone (or vice versa), the system date and time will no longer |
| 563 |
match the results of parsing the date "now" in Date::Manip. |
| 564 |
|
| 565 |
In general (unless the program runs for an extended period of |
| 566 |
time), the system date and time WILL match the value of "now", so |
| 567 |
this is a good way to simulate placing the computer in another |
| 568 |
time zone. |
| 569 |
|
| 570 |
If the current date/time is ambiguous (i.e. it exists in both |
| 571 |
standard and daylight saving time in the alternate zone), you |
| 572 |
can use the call: |
| 573 |
|
| 574 |
$date->config("setdate","now,DSTFLAG,ZONE"); |
| 575 |
|
| 576 |
to force it to be in one or the other. DSTFLAG can be "std", |
| 577 |
"dst", "stdonly", or "dstonly". "std" and "dst" mean that |
| 578 |
the date can be in either standard or saving time, but will |
| 579 |
try standard first (for "dst") or saving time first (if "dst"), |
| 580 |
and will only try the other if the date is not valid. If |
| 581 |
"stdonly" or "dstonly" is used, the date will be forced to |
| 582 |
be standard or saving time respectively (an error will be |
| 583 |
triggered if there is no valid date in that time). |
| 584 |
|
| 585 |
If the current date/time doesn't exist in the alternate zone, |
| 586 |
an error will occur. |
| 587 |
|
| 588 |
The other common operation is that you might want to see results |
| 589 |
as they would appear on a computer running in a different time zone. |
| 590 |
|
| 591 |
This can be done using the call: |
| 592 |
|
| 593 |
$date->config("setdate","zone,ZONE"); |
| 594 |
$date->config("setdate","zone,DSTFLAG,ZONE"); |
| 595 |
|
| 596 |
If it is currently |
| 597 |
|
| 598 |
Jun 6, 2009 12:00:00 in the America/New_York time zone |
| 599 |
|
| 600 |
and you call: |
| 601 |
|
| 602 |
$date->config("setdate","zone,America/Chicago"); |
| 603 |
|
| 604 |
then parsing "now" at precisely that moment will return "Jun 6, 2009 |
| 605 |
11:00:00". This is equivalent to working in the current zone, but |
| 606 |
then converting everything to the alternate zone. |
| 607 |
|
| 608 |
Note that DSTFLAG is only used if ZONE is entered as an offset. |
| 609 |
|
| 610 |
The final case where the SetDate config variable is used is to alter |
| 611 |
the date and time to some other value (completely independent of |
| 612 |
the current date and time) and allow it to advance normally from |
| 613 |
that point. |
| 614 |
|
| 615 |
$date->config("setdate","DATE"); |
| 616 |
$date->config("setdate","DATE,ZONE"); |
| 617 |
$date->config("setdate","DATE,DSTFLAG,ZONE"); |
| 618 |
|
| 619 |
set both the date/time and zone. |
| 620 |
|
| 621 |
If DATE is not valid in the time zone (either the local time zone |
| 622 |
or the specified one), and error occurs. |
| 623 |
|
| 624 |
The call: |
| 625 |
|
| 626 |
$date->config("setdate","now"); |
| 627 |
|
| 628 |
resets everything to use the current date/time and zone and lets it |
| 629 |
advance normally. |
| 630 |
|
| 631 |
=item B<ForceDate> |
| 632 |
|
| 633 |
The ForceDate config variable is similar to the SetDate variable, except |
| 634 |
that once "now" is set, it is not allowed to change. Parsing the date "now" |
| 635 |
will not change, regardless of how long the program runs (unless either |
| 636 |
the SetDate or ForceDate variables are set to some other value). |
| 637 |
|
| 638 |
$date->config("forcedate","now,ZONE"); |
| 639 |
$date->config("forcedate","now,DSTFLAG,ZONE"); |
| 640 |
$date->config("forcedate","zone,ZONE"); |
| 641 |
$date->config("forcedate","zone,DSTFLAG,ZONE"); |
| 642 |
$date->config("forcedate","DATE"); |
| 643 |
$date->config("forcedate","DATE,ZONE"); |
| 644 |
$date->config("forcedate","DATE,DSTFLAG,ZONE"); |
| 645 |
$date->config("forcedate","now"); |
| 646 |
|
| 647 |
all set "now" in the same way as the SetDate variable. Spaces after commas are |
| 648 |
ignored. |
| 649 |
|
| 650 |
=back |
| 651 |
|
| 652 |
ZONE can be any time zone name, alias, abbreviation, or offset, and |
| 653 |
the best time zone will be determined from all given information. |
| 654 |
|
| 655 |
It should be noted that setting the SetDate or ForceDate variable |
| 656 |
twice will always refer to the system date/time as a starting point. |
| 657 |
For example, if a program is running, and calls the method: |
| 658 |
|
| 659 |
$date->config("forcedate","now"); |
| 660 |
|
| 661 |
at Jun 6, 2009 at 12:00, that time will be treated as now from that |
| 662 |
point on. If the same call is done an hour later, "now" will then |
| 663 |
be Jun 6, 2009 at 13:00 from that moment on. |
| 664 |
|
| 665 |
Since the current date is used in the date parsing routines, no |
| 666 |
parsing can be done on the DATE value in any of the calls. Instead, |
| 667 |
DATE must be a date in one of the two formats: |
| 668 |
|
| 669 |
YYYY-MM-DD-HH:MN:SS |
| 670 |
YYYYMMDDHH:MN:SS |
| 671 |
|
| 672 |
=head1 MISCELLANEOUS CONFIGURATION VARIABLES |
| 673 |
|
| 674 |
=over 4 |
| 675 |
|
| 676 |
=item B<Use_POSIX_Printf> |
| 677 |
|
| 678 |
In the date printf function, most of the directives match the POSIX |
| 679 |
directives. However, a small number of them do not. |
| 680 |
|
| 681 |
With this option set to 1, all of the directives will match the |
| 682 |
POSIX directives. |
| 683 |
|
| 684 |
=back |
| 685 |
|
| 686 |
=head1 DEPRECATED CONFIGURATION VARIABLES |
| 687 |
|
| 688 |
The following config variables are currently supported, but are |
| 689 |
deprecated. They will be removed in a future Date::Manip release: |
| 690 |
|
| 691 |
=over 4 |
| 692 |
|
| 693 |
=item B<TZ> |
| 694 |
|
| 695 |
This variable is deprecated. It is scheduled to be removed in version |
| 696 |
7.00. The SetDate or ForceDate variables (described next) should be |
| 697 |
used instead. |
| 698 |
|
| 699 |
The following are equivalent: |
| 700 |
|
| 701 |
$date->config("tz","Europe/Rome"); |
| 702 |
$date->config("setdate","now,Europe/Rome"); |
| 703 |
|
| 704 |
or in the functional interface: |
| 705 |
|
| 706 |
Date_Init("tz=Europe/Rome"); |
| 707 |
Date_Init("setdate=now,Europe/Rome"); |
| 708 |
|
| 709 |
=item B<Jan1Week1> |
| 710 |
|
| 711 |
This variable is deprecated. It is scheduled to be removed in version |
| 712 |
7.00. The Week1ofYear variables (described next) should be used |
| 713 |
instead. |
| 714 |
|
| 715 |
ISO 8601 states that the first week of the year is the one which contains |
| 716 |
Jan 4 (i.e. it is the first week in which most of the days in that week |
| 717 |
fall in that year). This means that the first 3 days of the year may |
| 718 |
be treated as belonging to the last week of the previous year. If this |
| 719 |
is set to non-nil, the ISO 8601 standard will be ignored and the first |
| 720 |
week of the year contains Jan 1. |
| 721 |
|
| 722 |
=back |
| 723 |
|
| 724 |
=head1 KNOWN BUGS |
| 725 |
|
| 726 |
None known. |
| 727 |
|
| 728 |
=head1 BUGS AND QUESTIONS |
| 729 |
|
| 730 |
Please refer to the L<Date::Manip::Problems> documentation for |
| 731 |
information on submitting bug reports or questions to the author. |
| 732 |
|
| 733 |
=head1 SEE ALSO |
| 734 |
|
| 735 |
L<Date::Manip> - main module documentation |
| 736 |
|
| 737 |
=head1 LICENSE |
| 738 |
|
| 739 |
This script is free software; you can redistribute it and/or |
| 740 |
modify it under the same terms as Perl itself. |
| 741 |
|
| 742 |
=head1 AUTHOR |
| 743 |
|
| 744 |
Sullivan Beck (https://github.com/SBECK-github/) |
| 745 |
|
| 746 |
=cut |