There are three ways to set config variables. The first two are to pass them in when creating an object, or to pass them to the config method after the object is created. All of the main Date::Manip modules (Date::Manip::Base, Date::Manip::TZ, Date::Manip::Date, Date::Manip::Delta, and Date::Manip::Recur) have the config method.
As an example, you can create and configure a Date::Manip::Date object using the commands:
$date = new Date::Manip::Date; $date->config($var1,$val1,$var2,$val2,...);
This can be shortened to:
$date = new Date::Manip::Date [$var1,$val1,...];
The values of the config variables are stored in the Date::Manip::Base object. So, if you have a Date::Manip::Date object, it has a Date::Manip::Base object associated with it, and the configuration information is stored there. The same Date::Manip::Base object may be used by any number of higher objects, and all will share the same configuration. If multiple Date::Manip::Date objects share the same Date::Manip::Base object, setting a configuration variable on any of them affects all of the Date::Manip::Date objects. If you need to work with different configurations simultaneously, it is necessary to work with multiple Date::Manip::Base objects. This is covered in the Date::Manip::Objects document.
An alternate method exists if you are using one of the functional interfaces. To set a variable using the functional interface, use the call:
The third way to set config variables is to store them in a config file. The config file is read in by passing the appropriate values to the config method as described below. A config file is a good way to easily change a large number of settings. They are also necessary for other purposes (such as events and holidays which are covered in the Date::Manip::Holidays document).
When any Date::Manip::* object is configured, any number of config files may be read (and the config files can specify additional files to read).
The starting section of a config file contains general configuration variables. A list of all config variables is given below.
Following this, any number of special sections may be included in the config file. The special sections are used to specify other types of information, such as a list of holidays or special events. These special sections are described elsewhere in the documentation.
The syntax of the config file is very simple. Every line is of the form:
VAR = VAL
Blank lines and lines beginning with a pound sign (#) are ignored. All whitespace is optional. Variables names in the main section and section names are case insensitive (though values in the main section are typically case sensitive). Strings in other sections (both variables and values) are case sensitive.
The following is a sample config file:
DateFormat = US Language = English *Holidays Dec 25 = Christmas Jan 1 = New Year's
All config variables that may appear in the main part of a config file are described in the next section. Other sections are described elsewhere. The *Holidays and *Events sections are both described in the Date::Manip::Holidays documentation.
A sample config file is included with the Date::Manip distribution. Modify it as appropriate and copy it to some appropriate directory and use the ConfigFile variable to access it. For example, if a config file is stored in /home/foo/Manip.cnf, you can load it by:
or (if using a functional interface):
NOTE: if you use business mode calculations, you must have a config file since this is the only place where you can define holidays.
Variable names are case insensitive, both as arguments to the config function and in the config file. The values are case sensitive except where specified otherwise.
In other words, in the following call:
the first option will end up being ignored since the Defaults config variable will set the language back to it's default value which is English.
When using a functional interface, use:
An example call to the config function might be:
Config files are parsed immediately when encountered. So in this example, the file /tmp/file1 will be parsed before the next variable ('Language'). In addition, if a config file contains a ConfigFile variable, that file will immediately be parsed before continuing with the original file.
The path to the file may be specified in any way valid for the operating system. If a file is not found, a warning will be issued, but execution will continue.
Multiple config files are safe, and a section may safely be split across multiple files.
When using a functional interface, use:
To parse dates in a different language, just use the Language config variable with the name of the language as the value. Language names are case insensitive.
Additional languages may be added with the help of someone fluent in English and the other language. If you are interested in providing a translation for a new language, please refer to the Date::Manip::Lang document for instructions.
By default, input strings may be tested using multiple encodings that are commonly used for the specific languages, as well as using standard perl escape sequences, and output is done in UTF-8.
The input, output, or both can be overridden using the Encoding variable.
Setting Encoding to the name of a single encoding (a name supported by the Encoding perl module), will force all input and output to be done in that encoding.
Encoding = iso-8859-1
means that all input and output will be in that encoding. The encoding 'perl' has the special meaning of storing the string in perl escape sequences.
Encoding can also be set to the name of two encoding (separated by a comma).
Encoding = iso-8859-1,utf-16
which means that all input is in iso-8859-1 encoding, but all output will be utf-16.
Encoding may also be set as follows:
Encoding = iso-8859-1,
meaning that input is in iso-8859-1 and output is in the default (i.e. UTF-8) encoding.
Encoding = ,utf-16
means to check the input in all of the encodings, but all output will be in utf-16 encoding.
Note that any time you change languages, it will reset the encodings, so you should set this config variable AFTER setting the language.
Two other simple versions have been created. If the Printable variable is set to 1, the format is:
If Printable is set to 2, the format is:
This config variable is present in order to maintain backward compatibility, and may actually be deprecated at some point. As such, additional formats will not be added. Instead, use the printf method in the Date::Manip::Date module to extract information with complete flexibility.
By default, a 2 digit year is treated as falling in the 100 year period of CURR-89 to CURR+10. So in the year 2005, a two digit year will be somewhere in the range 1916 to 2015.
YYtoYYYY may be set to any integer N to force a 2 digit year into the period CURR-N to CURR+(99-N). A value of 0 forces the year to be the current year or later. A value of 99 forces the year to be the current year or earlier. Although the most common choice of values will be somewhere between 0 and 99, there is no restriction on N that forces it to be so. It can actually be any positive or negative number you want to force it into any 100 year period desired.
YYtoYYYY can also be set to ``C'' to force it into the current century, or to ``C##'' to force it into a specific century. So, in 1998, ``C'' forces 2 digit years to be 1900-1999. ``C18'' would always force a 2 digit year to be in the range 1800-1899. Note: I'm aware that the actual definitions of century are 1901-2000, NOT 1900-1999, so for purists, treat this as the way to supply the first two digits rather than as supplying a century.
It can also be set to the form ``C####'' to force it into a specific 100 year period. C1950 refers to 1950-2049.
midnight the default time is 00:00:00 curr the default time is the current time
``midnight'' is the default value.
NOTE: this only applies to dates parsed with the parse method. Dates parsed using the parse_date method always default to 00:00:00.
If you want to use a period (.) as a time separator as well, set this to 1. Then you can write the time as 12.15.30 .
By default, a period is used as a date separator, so 12.15.30 would be interpreted as Dec 15 1930 (or 2030), so if you use the period as a date separator, it should not be used as a time separator too.
This variable can be set to either 'first' or 'last', and in that case, both 'Jun 1925' and '1925 Jun' will be allowed, and will refer to either the first or last day of June in 1925.
There is also no way to handle an odd work schedule such as 10 days on, 4 days off.
However, both of these situations can be handled using a fairly simple workaround.
To handle a work week of Sunday to Thursday, just set WorkWeekBeg=1 and WorkWeekEnd=7 and defined a holiday that occurs every Friday and Saturday.
To handle a 10 days on, 4 days off schedule, do something similar but defined a holiday that occurs on all of the 4 days off.
Both of these can be done using recurrences. Refer to the Date::Manip::Recur documentation for details.
By default, WorkDay24Hr is zero, and the work day is defined by the WorkDayBeg and WorkDayEnd variables. These are the times when the work day starts and ends respectively. WorkDayBeg must come before WorkDayEnd (i.e. there is no way to handle the night shift where the work day starts one day and ends another).
The time in both should be a valid time format (H, H:M, or H:M:S).
Note that setting WorkDay24Hr to a non-zero value automatically sets WorkDayBeg and WorkDayEnd to ``00:00:00'' and ``24:00:00'' respectively, so to switch back to a non-24 hour day, you will need to reset both of those config variables.
Similarly, setting either the WorkDayBeg or WorkDayEnd variables automatically turns off WorkDay24Hr.
Although these variables are supported, the best way to have multiple holiday or events lists will be to create multiple Date::Manip::Base objects based on separate config files.
none no default range supplied year the current year month the current month week the current week day the current day all Jan 2, 0001 to Dec 30, 9999
The default value is ``none''.
When searching for dates that match the recurrence, this is the maximum number of attempts that will be done. If none are found, the recurrence will be assumed to be invalid.
Many of Date::Manip's operations rely on knowing what time it is now. This consists of three things: knowing what date and time it is, knowing what time zone it is, and knowing whether it is daylight saving or not. All of this is necessary in order to correctly handle every possible date.
The daylight saving time information is only used for a couple hours each year during daylight saving time changes (at all other times, the date, time, and time zone are sufficient information), so it is optional, and defaults to standard time if omitted.
The default behavior of Date::Manip is to use the system localtime function to determine the date, time, and daylight saving time information, and to use various methods (see ``DETERMINING THE SYSTEM TIME ZONE'' in Date::Manip::TZ) to determine what time zone the computer is in.
The following are equivalent:
or in the functional interface:
There are several cases where this may be useful.
Often, you may want to use the system time to get the date and time, but you want to work in another time zone. For this, use the call:
or in the function interface:
If it is currently
Jun 6, 2009 12:00:00 in the America/New_York time zone
and you call:
the Date::Manip will treat that exact instant as
Jun 6, 2009 12:00:00 in the Europe/Rome time zone
At that precise moment, looking at the system time and parsing the date ``now'' in Date::Manip will give the same date and time.
The time will continue to advance, but it will use time change rules from the Europe/Rome time zone. What that means is that if a daylight saving time occurs on the computer, but NOT in the Europe/Rome time zone (or vice versa), the system date and time will no longer match the results of parsing the date ``now'' in Date::Manip.
In general (unless the program runs for an extended period of time), the system date and time WILL match the value of ``now'', so this is a good way to simulate placing the computer in another time zone.
If the current date/time is ambiguous (i.e. it exists in both standard and daylight saving time in the alternate zone), you can use the call:
to force it to be in one or the other. DSTFLAG can be ``std'', ``dst'', ``stdonly'', or ``dstonly''. ``std'' and ``dst'' mean that the date can be in either standard or saving time, but will try standard first (for ``dst'') or saving time first (if ``dst''), and will only try the other if the date is not valid. If ``stdonly'' or ``dstonly'' is used, the date will be forced to be standard or saving time respectively (an error will be triggered if there is no valid date in that time).
If the current date/time doesn't exist in the alternate zone, an error will occur.
The other common operation is that you might want to see results as they would appear on a computer running in a different time zone.
This can be done using the call:
If it is currently
Jun 6, 2009 12:00:00 in the America/New_York time zone
and you call:
then parsing ``now'' at precisely that moment will return ``Jun 6, 2009 11:00:00''. This is equivalent to working in the current zone, but then converting everything to the alternate zone.
Note that DSTFLAG is only used if ZONE is entered as an offset.
The final case where the SetDate config variable is used is to alter the date and time to some other value (completely independent of the current date and time) and allow it to advance normally from that point.
$date->config("setdate","DATE"); $date->config("setdate","DATE,ZONE"); $date->config("setdate","DATE,DSTFLAG,ZONE");
set both the date/time and zone.
If DATE is not valid in the time zone (either the local time zone or the specified one), and error occurs.
resets everything to use the current date/time and zone and lets it advance normally.
$date->config("forcedate","now,ZONE"); $date->config("forcedate","now,DSTFLAG,ZONE"); $date->config("forcedate","zone,ZONE"); $date->config("forcedate","zone,DSTFLAG,ZONE"); $date->config("forcedate","DATE"); $date->config("forcedate","DATE,ZONE"); $date->config("forcedate","DATE,DSTFLAG,ZONE"); $date->config("forcedate","now");
all set ``now'' in the same way as the SetDate variable. Spaces after commas are ignored.
ZONE can be any time zone name, alias, abbreviation, or offset, and the best time zone will be determined from all given information.
It should be noted that setting the SetDate or ForceDate variable twice will always refer to the system date/time as a starting point. For example, if a program is running, and calls the method:
at Jun 6, 2009 at 12:00, that time will be treated as now from that point on. If the same call is done an hour later, ``now'' will then be Jun 6, 2009 at 13:00 from that moment on.
Since the current date is used in the date parsing routines, no parsing can be done on the DATE value in any of the calls. Instead, DATE must be a date in one of the two formats:
Scheduled for removal 2016-03-01