=head1 NAME Date::Calc - Gregorian calendar date calculations =head1 MOTTO Keep it small, fast and simple =head1 PREFACE This package consists of a C library and a Perl module (which uses the C library, internally) for all kinds of date calculations based on the Gregorian calendar (the one used in all western countries today), thereby complying with all relevant norms and standards: S, S and, to some extent, S (where applicable). (See also http://www.engelschall.com/u/sb/download/Date-Calc/DIN1355/ for a scan of part of the "S" document (in German)). The module of course handles year numbers of 2000 and above correctly ("Year 2000" or "Y2K" compliance) -- actually all year numbers from 1 to the largest positive integer representable on your system (which is at least 32767) can be dealt with. This is not true, however, for the import/export functions in this package which are an interface to the internal POSIX date and time functions of your system, which can only cover dates in the following ranges: 01-Jan-1970 00:00:00 GMT .. 19-Jan-2038 03:14:07 GMT [Unix etc.] 01-Jan-1904 00:00:00 LT .. 06-Feb-2040 06:28:15 LT [MacOS Classic] (LT = local time) Note that this package projects the Gregorian calendar back until the year S<1 A.D.> -- even though the Gregorian calendar was only adopted in 1582, mostly by the Catholic European countries, in obedience to the corresponding decree of Pope S in that year. Some (mainly protestant) countries continued to use the Julian calendar (used until then) until as late as the beginning of the 20th century. Finally, note that this package is not intended to do everything you could ever imagine automagically for you; it is rather intended to serve as a toolbox (in the best of UNIX spirit and traditions) which should, however, always get you where you want to go. See the section "RECIPES" at the bottom of this document for solutions to common problems! If nevertheless you can't figure out how to solve a particular problem, please let me know! (See e-mail address at the end of this document.) =head1 SYNOPSIS use Date::Calc qw( Days_in_Year Days_in_Month Weeks_in_Year leap_year check_date check_time check_business_date Day_of_Year Date_to_Days Day_of_Week Week_Number Week_of_Year Monday_of_Week Nth_Weekday_of_Month_Year Standard_to_Business Business_to_Standard Delta_Days Delta_DHMS Delta_YMD Delta_YMDHMS Normalize_DHMS Add_Delta_Days Add_Delta_DHMS Add_Delta_YM Add_Delta_YMD Add_Delta_YMDHMS System_Clock Today Now Today_and_Now This_Year Gmtime Localtime Mktime Timezone Date_to_Time Time_to_Date Easter_Sunday Decode_Month Decode_Day_of_Week Decode_Language Decode_Date_EU Decode_Date_US Fixed_Window Moving_Window Compress Uncompress check_compressed Compressed_to_Text Date_to_Text Date_to_Text_Long English_Ordinal Calendar Month_to_Text Day_of_Week_to_Text Day_of_Week_Abbreviation Language_to_Text Language Languages Decode_Date_EU2 Decode_Date_US2 Parse_Date ISO_LC ISO_UC ); use Date::Calc qw(:all); Days_in_Year $days = Days_in_Year($year,$month); Days_in_Month $days = Days_in_Month($year,$month); Weeks_in_Year $weeks = Weeks_in_Year($year); leap_year if (leap_year($year)) check_date if (check_date($year,$month,$day)) check_time if (check_time($hour,$min,$sec)) check_business_date if (check_business_date($year,$week,$dow)) Day_of_Year $doy = Day_of_Year($year,$month,$day); Date_to_Days $days = Date_to_Days($year,$month,$day); Day_of_Week $dow = Day_of_Week($year,$month,$day); Week_Number $week = Week_Number($year,$month,$day); # DEPRECATED Week_of_Year ($week,$year) = Week_of_Year($year,$month,$day); # RECOMMENDED $week = Week_of_Year($year,$month,$day); # DANGEROUS Monday_of_Week ($year,$month,$day) = Monday_of_Week($week,$year); Nth_Weekday_of_Month_Year if (($year,$month,$day) = Nth_Weekday_of_Month_Year($year,$month,$dow,$n)) Standard_to_Business ($year,$week,$dow) = Standard_to_Business($year,$month,$day); Business_to_Standard ($year,$month,$day) = Business_to_Standard($year,$week,$dow); Delta_Days $Dd = Delta_Days($year1,$month1,$day1, $year2,$month2,$day2); Delta_DHMS ($Dd,$Dh,$Dm,$Ds) = Delta_DHMS($year1,$month1,$day1, $hour1,$min1,$sec1, $year2,$month2,$day2, $hour2,$min2,$sec2); Delta_YMD ($Dy,$Dm,$Dd) = Delta_YMD($year1,$month1,$day1, $year2,$month2,$day2); Delta_YMDHMS ($D_y,$D_m,$D_d, $Dh,$Dm,$Ds) = Delta_YMDHMS($year1,$month1,$day1, $hour1,$min1,$sec1, $year2,$month2,$day2, $hour2,$min2,$sec2); Normalize_DHMS ($Dd,$Dh,$Dm,$Ds) = Normalize_DHMS($Dd,$Dh,$Dm,$Ds); Add_Delta_Days ($year,$month,$day) = Add_Delta_Days($year,$month,$day, $Dd); Add_Delta_DHMS ($year,$month,$day, $hour,$min,$sec) = Add_Delta_DHMS($year,$month,$day, $hour,$min,$sec, $Dd,$Dh,$Dm,$Ds); Add_Delta_YM ($year,$month,$day) = Add_Delta_YM($year,$month,$day, $Dy,$Dm); Add_Delta_YMD ($year,$month,$day) = Add_Delta_YMD($year,$month,$day, $Dy,$Dm,$Dd); Add_Delta_YMDHMS ($year,$month,$day, $hour,$min,$sec) = Add_Delta_YMDHMS($year,$month,$day, $hour,$min,$sec, $D_y,$D_m,$D_d, $Dh,$Dm,$Ds); System_Clock ($year,$month,$day, $hour,$min,$sec, $doy,$dow,$dst) = System_Clock([$gmt]); Today ($year,$month,$day) = Today([$gmt]); Now ($hour,$min,$sec) = Now([$gmt]); Today_and_Now ($year,$month,$day, $hour,$min,$sec) = Today_and_Now([$gmt]); This_Year $year = This_Year([$gmt]); Gmtime ($year,$month,$day, $hour,$min,$sec, $doy,$dow,$dst) = Gmtime([time]); Localtime ($year,$month,$day, $hour,$min,$sec, $doy,$dow,$dst) = Localtime([time]); Mktime $time = Mktime($year,$month,$day, $hour,$min,$sec); Timezone ($D_y,$D_m,$D_d, $Dh,$Dm,$Ds, $dst) = Timezone([time]); Date_to_Time $time = Date_to_Time($year,$month,$day, $hour,$min,$sec); Time_to_Date ($year,$month,$day, $hour,$min,$sec) = Time_to_Date([time]); Easter_Sunday ($year,$month,$day) = Easter_Sunday($year); Decode_Month if ($month = Decode_Month($string)) Decode_Day_of_Week if ($dow = Decode_Day_of_Week($string)) Decode_Language if ($lang = Decode_Language($string)) Decode_Date_EU if (($year,$month,$day) = Decode_Date_EU($string)) Decode_Date_US if (($year,$month,$day) = Decode_Date_US($string)) Fixed_Window $year = Fixed_Window($yy); Moving_Window $year = Moving_Window($yy); Compress $date = Compress($year,$month,$day); Uncompress if (($century,$year,$month,$day) = Uncompress($date)) check_compressed if (check_compressed($date)) Compressed_to_Text $string = Compressed_to_Text($date); Date_to_Text $string = Date_to_Text($year,$month,$day); Date_to_Text_Long $string = Date_to_Text_Long($year,$month,$day); English_Ordinal $string = English_Ordinal($number); Calendar $string = Calendar($year,$month[,$orthodox]); Month_to_Text $string = Month_to_Text($month); Day_of_Week_to_Text $string = Day_of_Week_to_Text($dow); Day_of_Week_Abbreviation $string = Day_of_Week_Abbreviation($dow); Language_to_Text $string = Language_to_Text($lang); Language $lang = Language(); Language($lang); $oldlang = Language($newlang); Languages $max_lang = Languages(); Decode_Date_EU2 if (($year,$month,$day) = Decode_Date_EU2($string)) Decode_Date_US2 if (($year,$month,$day) = Decode_Date_US2($string)) Parse_Date if (($year,$month,$day) = Parse_Date($string)) ISO_LC $lower = ISO_LC($string); ISO_UC $upper = ISO_UC($string); Version $string = Date::Calc::Version(); =head1 IMPORTANT NOTES (See the section "RECIPES" at the bottom of this document for solutions to common problems!) =over 2 =item * "Year 2000" ("Y2K") compliance The upper limit for any year number in this module is only given by the size of the largest positive integer that can be represented in a variable of the C type "int" on your system, which is at least 32767, according to the ANSI C standard (exceptions see below). In order to simplify calculations, this module projects the gregorian calendar back until the year S<1 A.D.> -- i.e., back B the year 1582 when this calendar was first decreed by the Catholic Pope S! Therefore, B, for instance, and B, because this will in fact perform a calculation based on the year "98" A.D. and B "1998"! An exception from this rule are the functions which contain the word "compress" in their names (which can only handle years between 1970 and 2069 and also accept the abbreviations "00" to "99"), and the functions whose names begin with "Decode_Date_" (which translate year numbers below 100 using a technique known as "moving window"). If you want to convert a two-digit year number into a full-fledged, four-digit (at least for some years to come C<;-)>) year number, use the two functions "Fixed_Window()" and "Moving_Window()" (see their description further below). Note also that the following import/export functions (which are interfaces to the POSIX functions "time()", "gmtime()", "localtime()" and "mktime()" or (the last two) substitutes for the BSD function "timegm()" and the POSIX function "gmtime()") have a very limited range of representable dates (in contrast to all other functions in this package, which cover virtually any date including and after S): System_Clock() Today() Now() Today_and_Now() This_Year() Gmtime() Localtime() Mktime() Timezone() Date_to_Time() Time_to_Date() These functions can only deal with dates in the range from S<01-Jan-1970 00:00:00 GMT> to S<19-Jan-2038 03:14:07 GMT> (the latter limit is only authoritative on S<32 bit> systems, however, and can (in principle, through a few code changes) be extended somewhat C<:-)> on S<64 bit> systems). On MacOS Classic, the valid range of dates is between (both included) S<01-Jan-1904 00:00:00> (local time) to S<06-Feb-2040 06:28:15> (local time). Note further that the function "Easter_Sunday()" can only be used for years in the range 1583 to 2299. =item * First index B ranges in this module start with "C<1>", B "C<0>"! I.e., the day of month, day of week, day of year, month of year, week of year, first valid year number and language B start counting at one, B zero! The only exception is the function "C", which may in fact return "C<0>" when the given date actually lies in the last week of the B year, and of course the numbers for hours (C<0..23>), minutes (C<0..59>) and seconds (C<0..59>). =item * Function naming conventions Function names completely in lower case indicate a boolean return value. =item * Boolean values Boolean values in this module are always a numeric zero ("C<0>") for "false" and a numeric one ("C<1>") for "true". =item * Exception handling The functions in this module will usually die with a corresponding error message if their input parameters, intermediate results or output values are out of range. The following functions handle errors differently: - check_date() - check_time() - check_business_date() - check_compressed() (which return a "false" return value when the given input does not represent a valid date or time), - Nth_Weekday_of_Month_Year() (which returns an empty list if the requested 5th day of week does not exist), - Decode_Month() - Decode_Day_of_Week() - Decode_Language() - Fixed_Window() - Moving_Window() - Compress() (which return "C<0>" upon failure or invalid input), and - Decode_Date_EU() - Decode_Date_US() - Decode_Date_EU2() - Decode_Date_US2() - Parse_Date() - Uncompress() (which return an empty list upon failure or invalid input). Note that you can always catch an exception thrown by any of the functions in this module and handle it yourself by enclosing the function call in an "C" with curly brackets and checking the special variable "C<$@>" (see L for details). =back =head1 DESCRIPTION =over 2 =item * C =item * C You can either specify the functions you want to import explicitly by enumerating them between the parentheses of the "C" operator, or you can use the "C<:all>" tag instead to import B available functions. =item * C<$days = Days_in_Year($year,$month);> This function returns the sum of the number of days in the months starting with January up to and including "C<$month>" in the given year "C<$year>". I.e., "C" returns "C<31>", "C" returns "C<59>", "C" returns "C<90>", and so on. Note that "C" returns the number of days in the given year "C<$year>", i.e., either "C<365>" or "C<366>". =item * C<$days = Days_in_Month($year,$month);> This function returns the number of days in the given month "C<$month>" of the given year "C<$year>". The year must always be supplied, even though it is only needed when the month is February, in order to determine whether it is a leap year or not. I.e., "C" returns "C<31>", "C" returns "C<28>", "C" returns "C<29>", "C" returns "C<31>", and so on. =item * C<$weeks = Weeks_in_Year($year);> This function returns the number of weeks in the given year "C<$year>", i.e., either "C<52>" or "C<53>". =item * C This function returns "true" ("C<1>") if the given year "C<$year>" is a leap year and "false" ("C<0>") otherwise. =item * C This function returns "true" ("C<1>") if the given three numerical values "C<$year>", "C<$month>" and "C<$day>" constitute a valid date, and "false" ("C<0>") otherwise. =item * C This function returns "true" ("C<1>") if the given three numerical values "C<$hour>", "C<$min>" and "C<$sec>" constitute a valid time (C<0 E= $hour E 24>, C<0 E= $min E 60> and C<0 E= $sec E 60>), and "false" ("C<0>") otherwise. =item * C This function returns "true" ("C<1>") if the given three numerical values "C<$year>", "C<$week>" and "C<$dow>" constitute a valid date in business format, and "false" ("C<0>") otherwise. B that this function does B compute whether a given date is a business day (i.e., Monday to Friday)! To do so, use "C<(Day_of_Week($year,$month,$day) E 6)>" instead. =item * C<$doy = Day_of_Year($year,$month,$day);> This function returns the (relative) number of the day of the given date in the given year. E.g., "C" returns "C<1>", "C" returns "C<32>", and "C" returns either "C<365>" or "C<366>". =item * C<$days = Date_to_Days($year,$month,$day);> This function returns the (absolute) number of the day of the given date, where counting starts at the 1st of January of the year S<1 A.D.> I.e., "C" returns "C<1>", "C" returns "C<365>", "C" returns "C<366>", "C" returns "C<729510>", and so on. This is sometimes also referred to (not quite correctly) as the Julian date (or day). This may cause confusion, because also the number of the day in a year (from 1 to 365 or 366) is frequently called the "Julian date". In fact the calendar that was used B the Gregorian calendar was the Julian calendar - named after famous Julius Caesar, who had instituted it in Roman times. The Julian calendar was less precise because it had too many leap years compared to the true mean length of a year, and because rulers often changed it arbitrarily, in order to lengthen their own reign, for instance. In order to convert the number returned by this function back into a date, use the function "C" (described further below), as follows: $days = Date_to_Days($year,$month,$day); ($year,$month,$day) = Add_Delta_Days(1,1,1, $days - 1); =item * C<$dow = Day_of_Week($year,$month,$day);> This function returns the number of the day of week of the given date. The function returns "C<1>" for Monday, "C<2>" for Tuesday and so on until "C<7>" for Sunday. Note that in the Hebrew calendar (on which the Christian calendar is based), the week starts with Sunday and ends with the Sabbath or Saturday (where according to the Genesis (as described in the Bible) the Lord rested from creating the world). In medieval times, Catholic Popes have decreed the Sunday to be the official day of rest, in order to dissociate the Christian from the Hebrew belief. Nowadays, the Sunday B the Saturday are commonly considered (and used as) days of rest, usually referred to as the "week-end". Consistent with this practice, current norms and standards (such as S, S and S) define the Monday as the first day of the week. =item * C<$week = Week_Number($year,$month,$day);> This function returns the number of the week the given date lies in. If the given date lies in the B week of the B year, "C<0>" is returned. If the given date lies in the B week of the B year, "C" is returned. =item * C<($week,$year) = Week_of_Year($year,$month,$day);> This function returns the number of the week the given date lies in, as well as the year that week belongs to. I.e., if the given date lies in the B week of the B year, "C<(Weeks_in_Year($year-1), $year-1)>" is returned. If the given date lies in the B week of the B year, "C<(1, $year+1)>" is returned. Otherwise, "C<(Week_Number($year,$month,$day), $year)>" is returned. =item * C<$week = Week_of_Year($year,$month,$day);> In scalar context, this function returns just the week number. This allows you to write "C<$week = Week_of_Year($year,$month,$day);>" instead of "C<($week) = Week_of_Year($year,$month,$day);>" (note the parentheses around "C<$week>"). If the given date lies in the B week of the B year, "C" is returned. If the given date lies in the B week of the B year, "C<1>" is returned. Otherwise the return value is identical with that of "C". B that using this function in scalar context is a B feature, because without knowing which year the week belongs to, you might inadvertently assume the wrong one! If for instance you are iterating through an interval of dates, you might assume that the week always belongs to the same year as the given date, which unfortunately is B in some cases! In many years, the 31st of December for instance belongs to week number one of the B year. Assuming that the year is the same as your date (31st of December, in this example), sends you back to the first week of the B year - the Monday of which, by the way, in case of bad luck, might actually lie in the year B the current year! This actually happens in 2002, for example. So you always need to provide the correct corresponding year number by other means, keeping track of it yourself. In case you do not understand this, never mind, but then simply B this function in scalar context! =item * C<($year,$month,$day) = Monday_of_Week($week,$year);> This function returns the date of the first day of the given week, i.e., the Monday. "C<$year>" must be greater than or equal to "C<1>", and "C<$week>" must lie in the range "C<1>" to "C". Note that you can write "C<($year,$month,$day) = Monday_of_Week(Week_of_Year($year,$month,$day));>" in order to calculate the date of the Monday of the same week as the given date. If you want to calculate any other day of week in the same week as a given date, use @date = Add_Delta_Days(Monday_of_Week(Week_of_Year(@date)),$offset); where C<$offset = 1> for Tuesday, C<2> for Wednesday etc. =item * C This function calculates the date of the "C<$n>"th day of week "C<$dow>" in the given month "C<$month>" and year "C<$year>"; such as, for example, the 3rd Thursday of a given month and year. This can be used to send a notification mail to the members of a group which meets regularly on every 3rd Thursday of a month, for instance. (See the section "RECIPES" near the end of this document for a code snippet to actually do so.) "C<$year>" must be greater than or equal to "C<1>", "C<$month>" must lie in the range "C<1>" to "C<12>", "C<$dow>" must lie in the range "C<1>" to "C<7>" and "C<$n>" must lie in the range "C<1>" to "C<5>", or a fatal error (with appropriate error message) occurs. The function returns an empty list when the 5th of a given day of week does not exist in the given month and year. =item * C<($year,$week,$dow) = Standard_to_Business($year,$month,$day);> This function converts a given date from standard notation (year, month, day (of month)) to business notation (year, week, day of week). =item * C<($year,$month,$day) = Business_to_Standard($year,$week,$dow);> This function converts a given date from business notation (year, week, day of week) to standard notation (year, month, day (of month)). =item * C<$Dd = Delta_Days($year1,$month1,$day1, $year2,$month2,$day2);> This function returns the difference in days between the two given dates. The result is positive if the two dates are in chronological order, i.e., if date #1 comes chronologically B date #2, and negative if the order of the two dates is reversed. The result is zero if the two dates are identical. =item * C<($Dd,$Dh,$Dm,$Ds) = Delta_DHMS($year1,$month1,$day1, $hour1,$min1,$sec1, $year2,$month2,$day2, $hour2,$min2,$sec2);> This function returns the difference in days, hours, minutes and seconds between the two given dates with times. All four return values will be positive if the two dates are in chronological order, i.e., if date #1 comes chronologically B date #2, and negative (in all four return values!) if the order of the two dates is reversed. This is so that the two functions "C" and "C" (description see further below) are complementary, i.e., mutually inverse: Add_Delta_DHMS(@date1,@time1, Delta_DHMS(@date1,@time1, @date2,@time2)) yields "C<(@date2,@time2)>" again, whereas Add_Delta_DHMS(@date2,@time2, map(-$_, Delta_DHMS(@date1,@time1, @date2,@time2))) yields "C<(@date1,@time1)>", and Delta_DHMS(@date1,@time1, Add_Delta_DHMS(@date1,@time1, @delta)) yields "C<@delta>" again. The result is zero (in all four return values) if the two dates and times are identical. =item * C<($Dy,$Dm,$Dd) = Delta_YMD($year1,$month1,$day1, $year2,$month2,$day2);> This function returns the vector ( $year2 - $year1, $month2 - $month1, $day2 - $day1 ) An error occurs if any of the two dates is invalid. =item * C<($D_y,$D_m,$D_d, $Dh,$Dm,$Ds) = Delta_YMDHMS($year1,$month1,$day1, $hour1,$min1,$sec1, $year2,$month2,$day2, $hour2,$min2,$sec2);> This function is based on the function "Delta_YMD()" above but additionally calculates the time difference. When a carry over from the time difference occurs, the value of "C<$D_d>" is adjusted accordingly, thus giving the correct total date/time difference. Arguments are expected to be in chronological order to yield a (usually) positive result. In any case, adding the result of this function to the first date/time value (C<$year1,$month1,$day1,> C<$hour1,$min1,$sec1>) always gives the second date/time value (C<$year2,$month2,$day2,> C<$hour2,$min2,$sec2>) again, and adding the negative result (all elements of the result vector negated) to the second date/time value gives the first date/time value. See the function "Add_Delta_YMDHMS()" further below for adding a date/time value and a date/time difference. An error occurs if any of the two date/time values is invalid. =item * C<($Dd,$Dh,$Dm,$Ds) = Normalize_DHMS($Dd,$Dh,$Dm,$Ds);> This function takes four arbitrary values for days, hours, minutes and seconds (which may have different signs) and renormalizes them so that the values for hours, minutes and seconds will lie in the ranges C<[-23..23]>, C<[-59..59]> and C<[-59..59]>, respectively, and so that all four values have the same sign (or are zero). The given values are left untouched, i.e., unchanged. =item * C<($year,$month,$day) = Add_Delta_Days($year,$month,$day, $Dd);> This function has two principal uses: First, it can be used to calculate a new date, given an initial date and an offset (which may be positive or negative) in days, in order to answer questions like "today plus 90 days -- which date gives that?". (In order to add a weeks offset, simply multiply the weeks offset with "C<7>" and use that as your days offset.) Second, it can be used to convert the canonical representation of a date, i.e., the number of that day (where counting starts at the 1st of January in S<1 A.D.>), back into a date given as year, month and day. Because counting starts at "C<1>", you will actually have to subtract "C<1>" from the canonical date in order to get back the original date: $canonical = Date_to_Days($year,$month,$day); ($year,$month,$day) = Add_Delta_Days(1,1,1, $canonical - 1); Moreover, this function is the inverse of the function "C": Add_Delta_Days(@date1, Delta_Days(@date1, @date2)) yields "C<@date2>" again, whereas Add_Delta_Days(@date2, -Delta_Days(@date1, @date2)) yields "C<@date1>", and Delta_Days(@date1, Add_Delta_Days(@date1, $delta)) yields "C<$delta>" again. =item * C<($year,$month,$day, $hour,$min,$sec) = Add_Delta_DHMS($year,$month,$day, $hour,$min,$sec, $Dd,$Dh,$Dm,$Ds);> This function serves to add a days, hours, minutes and seconds offset to a given date and time, in order to answer questions like "today and now plus 7 days but minus 5 hours and then plus 30 minutes, what date and time gives that?": ($y,$m,$d,$H,$M,$S) = Add_Delta_DHMS(Today_and_Now(), +7,-5,+30,0); =item * C<($year,$month,$day) = Add_Delta_YM($year,$month,$day, $Dy,$Dm);> This function can be used to add a year and/or month offset to a given date. In contrast to the function described immediately below ("C"), this function does no "wrapping" into the next month if the day happens to lie outside the valid range for the resulting year and month (after adding the year and month offsets). Instead, it simply truncates the day to the last possible day of the resulting month. Examples: Adding an offset of 0 years, 1 month to the date (1999,1,31) would result in the (invalid) date (1999,2,31). The function replaces this result by the (valid) date (1999,2,28). Adding an offset of 1 year, 1 month to the same date (1999,1,31) as above would result in the (still invalid) date (2000,2,31). The function replaces this result by the valid date (2000,2,29) (because 2000 is a leap year). Note that the year and month offsets can be negative, and that they can have different signs. If you want to additionally add a days offset, use the function "C" before or after calling "C": @date2 = Add_Delta_Days( Add_Delta_YM(@date1, $Dy,$Dm), $Dd ); @date2 = Add_Delta_YM( Add_Delta_Days(@date1, $Dd), $Dy,$Dm ); Note that your result may depend on the order in which you call these two functions! Consider the date (1999,2,28) and the offsets 0 years, 1 month and 1 day: (1999,2,28) plus one month is (1999,3,28), plus one day is (1999,3,29). (1999,2,28) plus one day is (1999,3,1), plus one month is (1999,4,1). (Which is also the reason why the "C" function does not allow to add a days offset, because this would actually require TWO functions: One for adding the days offset BEFORE and one for adding it AFTER applying the year/month offsets.) An error occurs if the initial date is not valid. Note that "C" will not, in general, return the original date "C<@date>" (consider the examples given above!). =item * C<($year,$month,$day) = Add_Delta_YMD($year,$month,$day, $Dy,$Dm,$Dd);> This function serves to add a years, months and days offset to a given date. (In order to add a weeks offset, simply multiply the weeks offset with "C<7>" and add this number to your days offset.) Note that the three offsets for years, months and days are applied independently from each other. This also allows them to have different signs. The years and months offsets are applied first, and the days offset is applied last. If the resulting date happens to fall on a day after the end of the resulting month, like the 32nd of April or the 30th of February, then the date is simply counted forward into the next month (possibly also into the next year) by the number of excessive days (e.g., the 32nd of April will become the 2nd of May). B that this behaviour differs from that of previous versions of this module! In previous versions, the day was simply truncated to the maximum number of days in the resulting month. If you want the previous behaviour, use the new function "C" (described immediately above) plus the function "C" instead. B also that because a year and a month offset is not equivalent to a fixed number of days, the transformation performed by this function is B! This is in contrast to the functions "C" and "C", which are fully and truly reversible (with the help of the functions "C" and "C", for instance). Note that for this same reason, @date = Add_Delta_YMD( Add_Delta_YMD(@date, $Dy,$Dm,$Dd), -$Dy,-$Dm,-$Dd); will in general B return the initial date "C<@date>". Note that this is B a program bug but B so because of the variable lengths of years and months! =item * C<($year,$month,$day, $hour,$min,$sec) = Add_Delta_YMDHMS($year,$month,$day, $hour,$min,$sec, $D_y,$D_m,$D_d, $Dh,$Dm,$Ds);> Same as the function above, except that a time offset may be given in addition to the year, month and day offset. =item * C<($year,$month,$day, $hour,$min,$sec, $doy,$dow,$dst) = System_Clock([$gmt]);> If your operating system supports the corresponding system calls ("C" and "C" or "C"), this function will return the information provided by your system clock, i.e., the current date and time, the number of the day of year, the number of the day of week and a flag signaling whether daylight savings time is currently in effect or not. The ranges of values returned (and their meanings) are as follows: $year : 1970..2038 (or more) [Unix etc.] $year : 1904..2040 [MacOS Classic] $month : 1..12 $day : 1..31 $hour : 0..23 $min : 0..59 $sec : 0..59 (0..61 on some systems) $doy : 1..366 $dow : 1..7 $dst : -1..1 "C<$doy>" is the day of year, sometimes also referred to as the "julian date", which starts at "C<1>" and goes up to the number of days in that year. The day of week ("C<$dow>") will be "C<1>" for Monday, "C<2>" for Tuesday and so on until "C<7>" for Sunday. The daylight savings time flag ("C<$dst>") will be "C<-1>" if this information is not available on your system, "C<0>" for no daylight savings time (i.e., winter time) and "C<1>" when daylight savings time is in effect. If your operating system does not provide the necessary system calls, calling this function will result in a fatal "not available on this system" error message. If you want to handle this exception yourself, use "C" as follows: eval { ($year,$month,$day, $hour,$min,$sec, $doy,$dow,$dst) = System_Clock(); }; if ($@) { # Handle missing system clock # (For instance, ask user to enter this information manually) } Note that curlies ("{" and "}") are used here to delimit the statement to be "eval"ed (which is the way to catch exceptions in Perl), and not quotes (which is a way to evaluate Perl expressions at runtime). If the optional (boolean) input parameter "C<$gmt>" is given, a "true" value ("C<1>") will cause "C" to be used instead of "C", internally, thus returning Greenwich Mean Time (GMT, or UTC) instead of local time. =item * C<($year,$month,$day) = Today([$gmt]);> This function returns a subset of the values returned by the function "C" (see above for details), namely the current year, month and day. A fatal "not available on this system" error message will appear if the corresponding system calls are not supported by your current operating system. If the optional (boolean) input parameter "C<$gmt>" is given, a "true" value ("C<1>") will cause "C" to be used instead of "C", internally, thus returning Greenwich Mean Time (GMT, or UTC) instead of local time. =item * C<($hour,$min,$sec) = Now([$gmt]);> This function returns a subset of the values returned by the function "C" (see above for details), namely the current time (hours, minutes and full seconds). A fatal "not available on this system" error message will appear if the corresponding system calls are not supported by your current operating system. If the optional (boolean) input parameter "C<$gmt>" is given, a "true" value ("C<1>") will cause "C" to be used instead of "C", internally, thus returning Greenwich Mean Time (GMT, or UTC) instead of local time. =item * C<($year,$month,$day, $hour,$min,$sec) = Today_and_Now([$gmt]);> This function returns a subset of the values returned by the function "C" (see above for details), namely the current date (year, month, day) and time (hours, minutes and full seconds). A fatal "not available on this system" error message will appear if the corresponding system calls are not supported by your current operating system. If the optional (boolean) input parameter "C<$gmt>" is given, a "true" value ("C<1>") will cause "C" to be used instead of "C", internally, thus returning Greenwich Mean Time (GMT, or UTC) instead of local time. =item * C<$year = This_Year([$gmt]);> This function returns the current year, according to local time. A fatal "not available on this system" error message will appear if the corresponding system calls are not supported by your current operating system. If the optional (boolean) input parameter "C<$gmt>" is given, a "true" value ("C<1>") will cause "C" to be used instead of "C", internally, thus returning Greenwich Mean Time (GMT, or UTC) instead of local time. However, this will only make a difference within a few hours around New Year (unless you are on a Pacific island, where this can be almost 24 hours). =item * C<($year,$month,$day, $hour,$min,$sec, $doy,$dow,$dst) = Gmtime([time]);> This is Date::Calc's equivalent of Perl's built-in "gmtime()" function. See also L. The ranges of values returned (and their meanings) are as follows: $year : 1970..2038 (or more) [Unix etc.] $year : 1904..2040 [MacOS Classic] $month : 1..12 $day : 1..31 $hour : 0..23 $min : 0..59 $sec : 0..59 $doy : 1..366 $dow : 1..7 $dst : -1..1 "C<$doy>" is the day of year, sometimes also referred to as the "julian date", which starts at "C<1>" and goes up to the number of days in that year. The day of week ("C<$dow>") will be "C<1>" for Monday, "C<2>" for Tuesday and so on until "C<7>" for Sunday. The daylight savings time flag ("C<$dst>") will be "C<-1>" if this information is not available on your system, "C<0>" for no daylight savings time (i.e., winter time) and "C<1>" when daylight savings time is in effect. A fatal "time out of range" error will occur if the given time value is out of range C<[0..(~0EE1)]>. If the time value is omitted, the "time()" function is called instead, internally. =item * C<($year,$month,$day, $hour,$min,$sec, $doy,$dow,$dst) = Localtime([time]);> This is Date::Calc's equivalent of Perl's built-in "localtime()" function. See also L. The ranges of values returned (and their meanings) are as follows: $year : 1970..2038 (or more) [Unix etc.] $year : 1904..2040 [MacOS Classic] $month : 1..12 $day : 1..31 $hour : 0..23 $min : 0..59 $sec : 0..59 $doy : 1..366 $dow : 1..7 $dst : -1..1 "C<$doy>" is the day of year, sometimes also referred to as the "julian date", which starts at "C<1>" and goes up to the number of days in that year. The day of week ("C<$dow>") will be "C<1>" for Monday, "C<2>" for Tuesday and so on until "C<7>" for Sunday. The daylight savings time flag ("C<$dst>") will be "C<-1>" if this information is not available on your system, "C<0>" for no daylight savings time (i.e., winter time) and "C<1>" when daylight savings time is in effect. A fatal "time out of range" error will occur if the given time value is out of range C<[0..(~0EE1)]>. If the time value is omitted, the "time()" function is called instead, internally. =item * C<$time = Mktime($year,$month,$day, $hour,$min,$sec);> This function converts a date into a time value, i.e., into the number of seconds since whatever moment in time your system considers to be the "epoch". On Unix and most other systems this is the number of seconds since January 1st 1970 at midnight (GMT). On MacOS Classic this is the number of seconds since January 1st 1904 at midnight (local time). The function is similar to the "POSIX::mktime()" function (see L for more details), but in contrast to the latter, it expects dates in the usual ranges used throughout this module: The year 2001 stays year 2001, and months are numbered from 1 to 12. A fatal "date out of range" error will occur if the given date cannot be expressed in terms of seconds since the epoch (this happens for instance when the date lies before the epoch, or if it is later than S<19-Jan-2038 03:14:07 GMT> on S<32 bit> Unix systems, or later than S<06-Feb-2040 06:28:15> (local time) on a Macintosh with MacOS Classic). Just like the "POSIX::mktime()" function, this function uses the "mktime()" system call, internally. This means that the given date and time is considered to be in local time, and that the value returned by this function will depend on your machine's local settings such as the time zone, whether daylight savings time is (or was, at the time) in effect, and the system clock itself. B that "mktime()" does not always return the same time value as fed into "localtime()", when you feed the output of "localtime()" back into "mktime()", on some systems! I.e., "C" will not always return the same value as given in "C<$time>"! =item * C<($D_y,$D_m,$D_d, $Dh,$Dm,$Ds, $dst) = Timezone([time]);> This function returns the difference between "C" and "C", which is the timezone offset in effect for the current location and the given "C