PageRenderTime 48ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/Class-Date-1.1.9/Date.pod

#
Unknown | 797 lines | 576 code | 221 blank | 0 comment | 0 complexity | 14f0136a556bfbdc50a4af3ef45bf277 MD5 | raw file
  1. =head1 NAME
  2. Class::Date - Class for easy date and time manipulation
  3. =head1 SYNOPSIS
  4. use Class::Date qw(:errors date localdate gmdate now -DateParse -EnvC);
  5. # creating absolute date object (local time)
  6. $date = new Class::Date [$year,$month,$day,$hour,$min,$sec];
  7. $date = date [$year,$month,$day,$hour,$min,$sec];
  8. # ^- "date" is an exportable function, the same as Class::Date->new
  9. $date = date { year => $year, month => $month, day => $day,
  10. hour => $hour, min => $min, sec => $sec };
  11. $date = date "2001-11-12 07:13:12";
  12. $date = localdate "2001-12-11";
  13. $date = now; # the same as date(time)
  14. $date = date($other_date_object); # cloning
  15. ...
  16. # creating absolute date object (GMT)
  17. $date = new Class::Date [$year,$month,$day,$hour,$min,$sec],'GMT';
  18. $date = gmdate "2001-11-12 17:13";
  19. ...
  20. # creating absolute date object in any other timezone
  21. $date = new Class::Date [$year,$month,$day,$hour,$min,$sec],'Iceland';
  22. $date = date "2001-11-12 17:13", 'Iceland';
  23. $date2 = $date->new([$y2, $m2, $d2, $h2, $m2, $s2]);
  24. # ^- timezone is inherited from the $date object
  25. # creating relative date object
  26. # (normally you don't need to create this object explicitly)
  27. $reldate = new Class::Date::Rel "3Y 1M 3D 6h 2m 4s";
  28. $reldate = new Class::Date::Rel "6Y";
  29. $reldate = new Class::Date::Rel $secs; # secs
  30. $reldate = new Class::Date::Rel [$year,$month,$day,$hour,$min,$sec];
  31. $reldate = new Class::Date::Rel { year => $year, month => $month, day => $day,
  32. hour => $hour, min => $min, sec => $sec };
  33. $reldate = new Class::Date::Rel "2001-11-12 07:13:12";
  34. $reldate = new Class::Date::Rel "2001-12-11";
  35. # getting values of an absolute date object
  36. $date; # prints the date in default output format (see below)
  37. $date->year; # year, e.g: 2001
  38. $date->_year; # year - 1900, e.g. 101
  39. $date->yr; # 2-digit year 0-99, e.g 1
  40. $date->mon; # month 1..12
  41. $date->month; # same as prev.
  42. $date->_mon; # month 0..11
  43. $date->_month; # same as prev.
  44. $date->day; # day of month
  45. $date->mday; # day of month
  46. $date->day_of_month;# same as prev.
  47. $date->hour;
  48. $date->min;
  49. $date->minute; # same as prev.
  50. $date->sec;
  51. $date->second; # same as prev.
  52. $date->wday; # 1 = Sunday
  53. $date->_wday; # 0 = Sunday
  54. $date->day_of_week; # same as prev.
  55. $date->yday;
  56. $date->day_of_year; # same as prev.
  57. $date->isdst; # DST?
  58. $date->daylight_savings; # same as prev.
  59. $date->epoch; # UNIX time_t
  60. $date->monname; # name of month, eg: March
  61. $date->monthname; # same as prev.
  62. $date->wdayname; # Thursday
  63. $date->day_of_weekname # same as prev.
  64. $date->hms # 01:23:45
  65. $date->ymd # 2000/02/29
  66. $date->mdy # 02/29/2000
  67. $date->dmy # 29/02/2000
  68. $date->meridiam # 01:23 AM
  69. $date->ampm # AM/PM
  70. $date->string # 2000-02-29 12:21:11 (format can be changed, look below)
  71. "$date" # same as prev.
  72. $date->tzoffset # timezone-offset
  73. $date->strftime($format) # POSIX strftime (without the huge POSIX.pm)
  74. $date->tz # returns the base timezone as you specify, eg: CET
  75. $date->tzdst # returns the real timezone with dst information, eg: CEST
  76. ($year,$month,$day,$hour,$min,$sec)=$date->array;
  77. ($year,$month,$day,$hour,$min,$sec)=@{ $date->aref };
  78. # !! $year: 1900-, $month: 1-12
  79. ($sec,$min,$hour,$day,$mon,$year,$wday,$yday,$isdst)=$date->struct;
  80. ($sec,$min,$hour,$day,$mon,$year,$wday,$yday,$isdst)=@{ $date->sref };
  81. # !! $year: 0-, $month: 0-11
  82. $hash=$date->href; # $href can be reused as a constructor
  83. print $hash->{year}."-".$hash->{month}. ... $hash->{sec} ... ;
  84. %hash=$date->hash;
  85. # !! $hash{year}: 1900-, $hash{month}: 1-12
  86. $date->month_begin # First day of the month (date object)
  87. $date->month_end # Last day of the month
  88. $date->days_in_month # 28..31
  89. # constructing new date based on an existing one:
  90. $new_date = $date->clone;
  91. $new_date = $date->clone( year => 1977, sec => 14 );
  92. # valid keys: year, _year, month, mon, _month, _mon, day, mday, day_of_month,
  93. # hour, min, minute, sec, second, tz
  94. # constructing a new date, which is the same as the original, but in
  95. # another timezone:
  96. $new_date = $date->to_tz('Iceland');
  97. # changing date format
  98. {
  99. local $Class::Date::DATE_FORMAT="%Y%m%d%H%M%S";
  100. print $date # result: 20011222000000
  101. $Class::Date::DATE_FORMAT=undef;
  102. print $date # result: Thu Oct 13 04:54:34 1994
  103. $Class::Date::DATE_FORMAT="%Y/%m/%d"
  104. print $date # result: 1994/10/13
  105. }
  106. # error handling
  107. $a = date($date_string);
  108. if ($a) { # valid date
  109. ...
  110. } else { # invalid date
  111. if ($a->error == E_INVALID) { ... }
  112. print $a->errstr;
  113. }
  114. # adjusting DST in calculations (see the doc)
  115. $Class::Date::DST_ADJUST = 1; # this is the default
  116. $Class::Date::DST_ADJUST = 0;
  117. # "month-border adjust" flag
  118. $Class::Date::MONTH_BORDER_ADJUST = 0; # this is the default
  119. print date("2001-01-31")+'1M'; # will print 2001-03-03
  120. $Class::Date::MONTH_BORDER_ADJUST = 1;
  121. print date("2001-01-31")+'1M'; # will print 2001-02-28
  122. # date range check
  123. $Class::Date::RANGE_CHECK = 0; # this is the default
  124. print date("2001-02-31"); # will print 2001-03-03
  125. $Class::Date::RANGE_CHECK = 1;
  126. print date("2001-02-31"); # will print nothing
  127. # getting values of a relative date object
  128. $reldate; # reldate in seconds (assumed 1 month = 2_629_744 secs)
  129. $reldate->year;
  130. $reldate->mon;
  131. $reldate->month; # same as prev.
  132. $reldate->day;
  133. $reldate->hour;
  134. $reldate->min;
  135. $reldate->minute; # same as prev.
  136. $reldate->sec; # same as $reldate
  137. $reldate->second; # same as prev.
  138. $reldate->sec_part; # "second" part of the relative date
  139. $reldate->mon_part; # "month" part of the relative date
  140. # arithmetic with dates:
  141. print date([2001,12,11,4,5,6])->truncate;
  142. # will print "2001-12-11"
  143. $new_date = $date+$reldate;
  144. $date2 = $date+'3Y 2D'; # 3 Years and 2 days
  145. $date3 = $date+[1,2,3]; # $date plus 1 year, 2 months, 3 days
  146. $date4 = $date+'3-1-5' # $date plus 3 years, 1 months, 5 days
  147. $new_date = $date-$reldate;
  148. $date2 = $date-'3Y'; # 3 Yearss
  149. $date3 = $date-[1,2,3]; # $date minus 1 year, 2 months, 3 days
  150. $date4 = $date-'3-1-5' # $date minus 3 years, 1 month, 5 days
  151. $new_reldate = $date1-$date2;
  152. $reldate2 = Class::Date->new('2000-11-12')-'2000-11-10';
  153. $reldate3 = $date3-'1977-11-10';
  154. $days_between = (Class::Date->new('2001-11-12')-'2001-07-04')->day;
  155. # comparison between absolute dates
  156. print $date1 > $date2 ? "I am older" : "I am younger";
  157. # comparison between relative dates
  158. print $reldate1 > $reldate2 ? "I am faster" : "I am slower";
  159. # Adding / Subtracting months and years are sometimes tricky:
  160. print date("2001-01-29") + '1M' - '1M'; # gives "2001-02-01"
  161. print date("2000-02-29") + '1Y' - '1Y'; # gives "2000-03-01"
  162. # Named interface ($date2 does not necessary to be a Class::Date object)
  163. $date1->string; # same as $date1 in scalar context
  164. $date1->subtract($date2); # same as $date1 - $date2
  165. $date1->add($date2); # same as $date1 + $date2
  166. $date1->compare($date2); # same as $date1 <=> $date2
  167. $reldate1->sec; # same as $reldate1 in numeric or scalar context
  168. $reldate1->compare($reldate2);# same as $reldate1 <=> $reldate2
  169. $reldate1->add($reldate2); # same as $reldate1 + $reldate2
  170. $reldate1->neg # used for subtraction
  171. # Disabling Class::Date warnings at load time
  172. BEGIN { $Class::Date::WARNINGS=0; }
  173. use Class::Date;
  174. =head1 DESCRIPTION
  175. This module is intended to provide a general-purpose date and datetime type
  176. for perl. You have a Class::Date class for absolute date and datetime, and have
  177. a Class::Date::Rel class for relative dates.
  178. You can use "+", "-", "<" and ">" operators as with native perl data types.
  179. =head1 USAGE
  180. If you want to use a date object, you need to do the following:
  181. - create a new object
  182. - do some operations (+, -, comparison)
  183. - get result back
  184. =head2 Creating a new date object
  185. You can create a date object by the "date", "localdate" or "gmdate" function,
  186. or by calling the Class::Date constructor.
  187. "date" and "Class::Date->new" are equivalent, both has two arguments: The
  188. date and the timezone.
  189. $date1= date [2000,11,12];
  190. $date2= Class::Date->new([2000,06,11,13,11,22],'GMT');
  191. $date2= $date1->new([2000,06,11,13,11,22]);
  192. If the timezone information is omitted, then it first check if "new" is
  193. called as an object method or a class method. If it is an object method,
  194. then it inherits the timezone from the base object, otherwise the default
  195. timezone is used ($Class::Date::DEFAULT_TIMEZONE), which is usually set to
  196. the local timezone (which is stored in $Class::Date::LOCAL_TIMEZONE). These
  197. two variables are set only once to the value, which is returned by the
  198. Class::Date::local_timezone() function. You can change these values
  199. whenever you want.
  200. "localdate $x" is equivalent to "date $x, $Class::Date::LOCAL_TIMEZONE",
  201. "gmdate $x" is equivalent to "date $x, $Class::Date::GMT_TIMEZONE".
  202. $Class::Date::GMT_TIMEZONE is set to 'GMT' by default.
  203. $date1= localdate [2000,11,12];
  204. $date2= gmdate [2000,4,2,3,33,33];
  205. $date = localdate(time);
  206. The format of the accepted input date can be:
  207. =over 4
  208. =item [$year,$month,$day,$hour,$min,$sec]
  209. An array reference with 6 elements. The missing elements have default
  210. values (year: 2000, month, day: 1, hour, min, sec: 0)
  211. =item { year => $year, month => $month, day => $day, hour => $hour, min => $min, sec => $sec }
  212. A hash reference with the same 6 elements as above.
  213. =item "YYYYMMDDhhmmss"
  214. A mysql-style timestamp value, which consist of at least 14 digit.
  215. =item "973897262"
  216. A valid 32-bit integer: This is parsed as a unix time.
  217. =item "YYYY-MM-DD hh:mm:ss"
  218. A standard ISO(-like) date format. Additional ".fraction" part is ignored,
  219. ":ss" can be omitted.
  220. =item additional input formats
  221. You can specify "-DateParse" as an import parameter, e.g:
  222. use Class::Date qw(date -DateParse);
  223. With this, the module will try to load Date::Parse module, and if it find it then all
  224. these formats can be used as an input. Please refer to the Date::Parse
  225. documentation.
  226. =back
  227. =head2 Operations
  228. =over 4
  229. =item addition
  230. You can add the following to a Class::Date object:
  231. - a valid Class::Date::Rel object
  232. - anything, that can be used for creating a new Class::Date::Rel object
  233. It means that you don't need to create a new Class::Date::Rel object every
  234. time when you add something to the Class::Date object, it creates them
  235. automatically:
  236. $date= Class::Date->new('2001-12-11')+Class::Date::Rel->new('3Y');
  237. is the same as:
  238. $date= date('2001-12-11')+'3Y';
  239. You can provide a Class::Date::Rel object in the following form:
  240. =over 4
  241. =item array ref
  242. The same format as seen in Class::Date format, except the default values are
  243. different: all zero.
  244. =item hash ref
  245. The same format as seen in Class::Date format, except the default values are
  246. different: all zero.
  247. =item "973897262"
  248. A valid 32-bit integer is parsed as seconds.
  249. =item "YYYY-MM-DD hh:mm:ss"
  250. A standard ISO date format, but this is parsed as relative date date and time,
  251. so month, day and year can be zero (and defaults to zero).
  252. =item "12Y 6M 6D 20h 12m 5s"
  253. This special string can be used if you don't want to use the ISO format. This
  254. string consists of whitespace separated tags, each tag consists of a number and
  255. a unit. The units can be:
  256. Y: year
  257. M: month
  258. D: day
  259. h: hour
  260. m: min
  261. s: sec
  262. The number and unit must be written with no space between them.
  263. =back
  264. =item substraction
  265. The same rules are true for substraction, except you can substract
  266. two Class::Date object from each other, and you will get a Class::Date::Rel
  267. object:
  268. $reldate=$date1-$date2;
  269. $reldate=date('2001-11-12 12:11:07')-date('2001-10-07 10:3:21');
  270. In this case, the "month" field of the $reldate object will be 0,
  271. and the other fields will contain the difference between two dates;
  272. =item comparison
  273. You can compare two Class::Date objects, or one Class::Date object and
  274. another data, which can be used for creating a new Class::Data object.
  275. It means that you don't need to bless both objects, one of them can be a
  276. simple string, array ref, hash ref, etc (see how to create a date object).
  277. if ( date('2001-11-12') > date('2000-11-11') ) { ... }
  278. or
  279. if ( date('2001-11-12') > '2000-11-11' ) { ... }
  280. =item truncate
  281. You can chop the time value from this object (set hour, min and sec to 0)
  282. with the "truncate" or "trunc" method. It does not modify the specified
  283. object, it returns with a new one.
  284. =item clone
  285. You can create new date object based on an existing one, by using the "clone"
  286. method. Note, this DOES NOT modify the base object.
  287. $new_date = $date->clone( year => 2001, hour => 14 );
  288. The valid keys are: year, _year, month, mon, _month, _mon, day, mday,
  289. day_of_month, hour, min, minute, sec, second, tz.
  290. There is a "set" method, which does the same as the "clone", it exists
  291. only for compatibility.
  292. =item to_tz
  293. You can use "to_tz" to create a new object, which means the same time as
  294. the base object, but in the different timezone.
  295. Note that $date->clone( tz => 'Iceland') and $date->to_tz('Iceland') is not
  296. the same! Cloning a new object with setting timezone will preserve the
  297. time information (hour, minute, second, etc.), but transfer the time into
  298. other timezone, while to_tz usually change these values based on the
  299. difference between the source and the destination timezone.
  300. =item Operations with Class::Date::Rel
  301. The Class::Date::Rel object consists of a month part and a day part. Most
  302. people only use the "day" part of it. If you use both part, then you can get
  303. these parts with the "sec_part" and "mon_part" method. If you use "sec",
  304. "month", etc. methods or if you use this object in a mathematical conent,
  305. then this object is converted to one number, which is interpreted as second.
  306. The conversion is based on a 30.436 days month. Don't use it too often,
  307. because it is confusing...
  308. If you use Class::Date::Rel in an expression with other Class::Date or
  309. Class::Date::Rel objects, then it does what is expected:
  310. date('2001-11-12')+'1M' will be '2001-12-12'
  311. and
  312. date('1996-02-11')+'2M' will be '1996-04-11'
  313. =back
  314. =head2 Accessing data from a Class::Date and Class::Date::Rel object
  315. You can use the methods methods described at the top of the document
  316. if you want to access parts of the data
  317. which is stored in a Class::Date and Class::Date::Rel object.
  318. =head2 Error handling
  319. If a date object became invalid, then the object will be reblessed to
  320. Class::Date::Invalid. This object is false in boolean environment, so you can
  321. test the date validity like this:
  322. $a = date($input_date);
  323. if ($a) { # valid date
  324. ...
  325. } else { # invalid date
  326. if ($a->error == E_INVALID) { ... }
  327. print $a->errstr;
  328. }
  329. Note even the date is invalid, the expression "defined $a" always returns
  330. true, so the following is wrong:
  331. $a = date($input_date);
  332. if (defined $a) ... # WRONG!!!!
  333. You can test the error by getting the $date->error value. You might import
  334. the ":errors" tag:
  335. use Class::Date qw(:errors);
  336. Possible error values are:
  337. =over 4
  338. =item E_OK
  339. No errors.
  340. =item E_INVALID
  341. Invalid date. It is set when some of the parts of the date are invalid, and
  342. Time::Local functions cannot convert them to a valid date.
  343. =item E_RANGE
  344. This error is set, when parts of the date are valid, but the whole date is
  345. not valid, e.g. 2001-02-31. When the $Class::Date::RANGE_CHECK is not set, then
  346. these date values are automatically converted to a valid date: 2001-03-03,
  347. but the $date->error value are set to E_RANGE. If $Class::Date::RANGE_CHECK
  348. is set, then a date "2001-02-31" became invalid date.
  349. =item E_UNPARSABLE
  350. This error is set, when the constructor cannot be created from a scalar, e.g:
  351. $a = date("4kd sdlsdf lwekrmk");
  352. =item E_UNDEFINED
  353. This error is set, when you want to create a date object from an undefined
  354. value:
  355. $a = new Class::Date (undef);
  356. Note, that localdate(undef) will create a valid object, because it calls
  357. $Class::Date(time).
  358. =back
  359. You can get the error in string form by calling the "errstr" method.
  360. =head1 DST_ADJUST
  361. $DST_ADJUST is an importable variable, and is a very important configuration
  362. option.
  363. If it is set to true (default), then it adjusts the date and time when the
  364. operation switches the border of DST. You will see the difference if you run
  365. this code:
  366. $Class::Date::DST_ADJUST=0;
  367. for (my $date=localdate("2000-06-11");$date<"2001-4-5";$date+='1D') {
  368. print $date."\n";
  369. }
  370. $Class::Date::DST_ADJUST=1;
  371. for (my $date=localdate("2000-06-11");$date<"2001-4-5";$date+='1D') {
  372. print $date."\n";
  373. }
  374. =head1 MONTHS AND YEARS
  375. If you add or subtract "months" and "years" to a date, you may get wrong
  376. dates, e.g when you add one month to 2001-01-31, you expect to get
  377. 2001-02-31, but this date is invalid and converted to 2001-03-03. Thats' why
  378. date("2001-01-31") + '1M' - '1M' != "2001-01-31"
  379. This problem can occur only with months and years, because others can
  380. easily be converted to seconds.
  381. =head1 MONTH_BORDER_ADJUST
  382. $MONTH_BORDER_ADJUST variable is used to switch on or off the
  383. month-adjust feature. This is used only when someone adds months or years to
  384. a date and then the resulted date became invalid. An example: adding one
  385. month to "2001-01-31" will result "2001-02-31", and this is an invalid date.
  386. When $MONTH_BORDER_ADJUST is false, this result simply normalized, and
  387. becomes "2001-03-03". This is the default behaviour.
  388. When $MONTH_BORDER_ADJUST is true, this result becomes "2001-02-28". So when
  389. the date overflows, then it returns the last day insted.
  390. Both settings keeps the time information.
  391. =head1 WORKING WITHOUT A C COMPILER
  392. Class::Date can be used without a C compiler since 1.0.8. If you want to do
  393. this, you only need to copy the "Date.pm" whereever your perl compiler searches
  394. for it. You must make a "Class" directory for it before.
  395. In Debian GNU/Linux system (woody) , a good choice can be the following:
  396. mkdir /usr/local/share/perl/5.6.1/Class
  397. cp Date.pm /usr/local/share/perl/5.6.1/Class
  398. And the module will work.
  399. You can use the $WARNINGS switch to switch off the complains about the missing
  400. XS part from your perl program:
  401. BEGIN { $Class::Date::WARNINGS=0; }
  402. use Class::Date;
  403. ...
  404. =head1 TIMEZONE SUPPORT
  405. Since 1.0.11, Class::Date handle timezones natively on most platforms (see
  406. the BUGS AND LIMITATIONS section for more info).
  407. When the module is loaded, then it determines the local base timezone by
  408. calling the Class::Date::local_timezone() function, and stores these values
  409. into two variables, these are: $Class::Date::LOCAL_TIMEZONE and
  410. $Class::Date::DEFAULT_TIMEZONE. The first value is used, when you call the
  411. "localdate" function, the second value is used, when you call the "date"
  412. function and you don't specify the timezone. There is
  413. a $Class::Date::GMT_TIMEZONE function also, which is used by the "gmdate"
  414. function, this is set to 'GMT'.
  415. You can query the timezone of a date object by calling the $date->tz
  416. method. Note this value returns the timezone as you specify, so if you
  417. create the object with an unknown timezone, you will get this back. If you
  418. want to query the effective timezone, you can call the $date->tzdst method.
  419. This method returns only valid timezones, but it is not necessarily the
  420. timezone, which can be used to create a new object. For example
  421. $date->tzdst can return 'CEST', which is not a valid base timezone, because
  422. it contains daylight savings information also. On Linux systems, you can
  423. see the possible base timezones in the /usr/share/zoneinfo directory.
  424. In Class::Date 1.1.6, a new environment variable is introduced:
  425. $Class::Date::NOTZ_TIMEZONE. This variable stores the local timezone, which
  426. is used, when the TZ environment variable is not set. It is introduced,
  427. because there are some systems, which cannot handle the queried timezone
  428. well. For example the local timezone is CST, it is returned by the tzname()
  429. perl function, but when I set the TZ environment variable to CST, it
  430. works like it would be GMT. The workaround is NOTZ_TIMEZONE: if a date
  431. object has a timezone, which is the same as NOTZ_TIMEZONE, then the TZ
  432. variable will be removed before each calculation. In normal case, it would
  433. be the same as setting TZ to $NOTZ_TIMEZONE, but some systems don't like
  434. it, so I decided to introduce this variable. The
  435. $Class::Date::NOTZ_TIMEZONE variable is set in the initialization of the
  436. module by removing the TZ variable from the environment and querying the
  437. tzname variable.
  438. =head1 INTERNALS
  439. This module uses operator overloading very heavily. I've found it quite stable,
  440. but I am afraid of it a bit.
  441. A Class::Date object is an array reference.
  442. A Class::Date::Rel object is an array reference, which contains month and
  443. second information. I need to store it as an array ref, because array and month
  444. values cannot be converted into seconds, because of our super calendar.
  445. You can add code references to the @Class::Date::NEW_FROM_SCALAR and
  446. @Class::Date::Rel::NEW_FROM_SCALAR. These arrays are iterated through when a
  447. scalar-format date must be parsed. These arrays only have one or two values
  448. at initialization. The parameters which the code references got are the same
  449. as the "new" method of each class. In this way, you can personalize the date
  450. parses as you want.
  451. As of 0.90, the Class::Date has been rewritten. A lot of code and design
  452. decision has been borrowed from Matt Sergeant's Time::Object, and there will
  453. be some incompatibility with the previous public version (0.5). I tried to
  454. keep compatibility methods in Class::Date. If you have problems regarding
  455. this, please drop me an email with the description of the problem, and I will
  456. set the compatibility back.
  457. Invalid dates are Class::Date::Invalid objects. Every method call on this
  458. object and every operation with this object returns undef or 0.
  459. =head1 DEVELOPMENT FOCUS
  460. This module tries to be as full-featured as can be. It currently lacks
  461. business-day calculation, which is planned to be implemented in the 1.0.x
  462. series.
  463. I try to keep this module not to depend on other modules and I want this
  464. module usable without a C compiler.
  465. Currently the module uses the POSIX localtime function very extensively.
  466. This makes the date calculation a bit slow, but provides a rich interface,
  467. which is not provided by any other module. When I tried to redesign the
  468. internals to not depend on localtime, I failed, because there are no other
  469. way to determine the daylight savings information.
  470. =head1 SPEED ISSUES
  471. There are two kind of adjustment in this module, DST_ADJUST and
  472. MONTH_BORDER_ADJUST. Both of them makes the "+" and "-" operations slower. If
  473. you don't need them, switch them off to achieve faster calculations.
  474. In general, if you really need fast date and datetime calculation, don't use
  475. this module. As you see in the previous section, the focus of development is
  476. not the speed in 1.0. For fast date and datetime calculations, use
  477. Date::Calc module instead.
  478. =head1 THREAD SAFETY and MOD_PERL
  479. This module is NOT thread-safe, since it uses C library functions, which
  480. are not thread-safe. Using this module in a multi-threaded environment can
  481. cause timezones to be messed up. I did not put any warning about it, you
  482. have to make sure that you understand this!
  483. Under some circumstances in a mod_perl environment, you require the Env::C
  484. module to set the TZ variable properly before calling the time functions. I
  485. added the -EnvC import option to automatically load this module if it is
  486. not loaded already. Please read the mod_perl documentation about the
  487. environment variables and mod_perl to get the idea why it is required
  488. sometimes:
  489. http://perl.apache.org/docs/2.0/user/troubleshooting/troubleshooting.html#C_Libraries_Don_t_See_C__ENV__Entries_Set_by_Perl_Code
  490. You are sure have this problem if the $Class::Date::NOTZ_TIMEZONE variable
  491. is set to 'UTC', althought you are sure that your timezone is not that. Try
  492. -EnvC in this case, but make sure that you are not using it in a
  493. multi-threaded environment!
  494. =head1 OTHER BUGS AND LIMITATIONS
  495. =over 4
  496. =item *
  497. I cannot manage to get the timezone code working properly on ActivePerl
  498. 5.8.0 on win XP and earlier versions possibly have this problem also. If
  499. you have a system like this, then you will have only two timezones, the
  500. local and the GMT. Every timezone, which is not equal to
  501. $Class::Date::GMT_TIMEZONE is assumed to be local. This seems to be caused
  502. by the win32 implementation of timezone routines. I don't really know how
  503. to make this thing working, so I gave up this issue. If anyone know a
  504. working solution, then I will integrate it into Class::Date, but until
  505. then, the timezone support will not be available for these platforms.
  506. =item *
  507. Perl 5.8.0 and earlier versions has a bug in the strftime code on some
  508. operating systems (for example Linux), which is timezone related. I
  509. recommend using the strftime, which is provided with Class::Date, so don't
  510. try to use the module without the compiled part. The module will not work
  511. with a buggy strftime - the test is hardcoded into the beginning of the
  512. code. If you anyway want to use the module, remove the hardcoded "die" from
  513. the module, but do it for your own risk.
  514. =item *
  515. This module uses the POSIX functions for date and
  516. time calculations, so it is not working for dates beyond 2038 and before 1902.
  517. I don't know what systems support dates in 1902-1970 range, it may not work on
  518. your system. I know it works on the Linux glibc system with perl 5.6.1
  519. and 5.7.2. I know it does not work with perl 5.005_03 (it may be the bug of
  520. the Time::Local module). Please report if you know any system where it does
  521. _not_ work with perl 5.6.1 or later.
  522. I hope that someone will fix this with new time_t in libc. If you really need
  523. dates over 2038 and before 1902, you need to completely rewrite this module or
  524. use Date::Calc or other date modules.
  525. =item *
  526. This module uses Time::Local, and when it croaks, Class::Date returns
  527. "Invalid date or time" error message. Time::Local is different in the 5.005
  528. and 5.6.x (and even 5.7.x) version of perl, so the following code will
  529. return different results:
  530. $a = date("2006-11-11")->clone(year => -1);
  531. In perl 5.6.1, it returns an invalid date with error message "Invali date or
  532. time", in perl 5.005 it returns an invalid date with range check error. Both
  533. are false if you use them in boolean context though, only the error message
  534. is different, but don't rely on the error message in this case. It however
  535. works in the same way if you change other fields than "year" to an invalid
  536. field.
  537. =back
  538. =head1 SUPPORT
  539. Class::Date is free software. IT COMES WITHOUT WARRANTY OF ANY KIND.
  540. If you have questions, you can send questions directly to me:
  541. dlux@dlux.hu
  542. =head1 WIN32 notes
  543. You can get a binary win32 version of Class::Date from Chris Winters' .ppd
  544. repository with the following commands:
  545. For people using PPM2:
  546. c:\> ppm
  547. PPM> set repository oi http://openinteract.sourceforge.net/ppmpackages/
  548. PPM> set save
  549. PPM> install Class-Date
  550. For people using PPM3:
  551. c:\> ppm
  552. PPM> repository http://openinteract.sourceforge.net/ppmpackages/
  553. PPM> install Class-Date
  554. The first steps in PPM only needs to be done at the first time. Next time
  555. you just run the 'install'.
  556. =head1 COPYRIGHT
  557. Copyright (c) 2001 Szab?, Bal?zs (dLux)
  558. All rights reserved. This program is free software; you can redistribute it
  559. and/or modify it under the same terms as Perl itself.
  560. Portions Copyright (c) Matt Sergeant
  561. =head1 AUTHOR
  562. dLux (Szab?, Bal?zs) <dlux@dlux.hu>
  563. =head1 CREDITS
  564. - Matt Sergeant <matt@sergeant.org>
  565. (Lots of code are borrowed from the Time::Object module)
  566. - Tatsuhiko Miyagawa <miyagawa@cpan.org> (bugfixes)
  567. - Stas Bekman <stas@stason.org> (suggestions, bugfix)
  568. - Chris Winters <chris@cwinters.com> (win32 .ppd version)
  569. - Benoit Beausejour <bbeausej@pobox.com>
  570. (Parts of the timezone code is borrowed from his Date::Handler module)
  571. =head1 SEE ALSO
  572. perl(1).
  573. Date::Calc(3pm).
  574. Time::Object(3pm).
  575. Date::Handler(3pm).
  576. =cut