| 1 | .\" Automatically generated by Pod::Man v1.34, Pod::Parser v1.13 |
| 2 | .\" |
| 3 | .\" Standard preamble: |
| 4 | .\" ======================================================================== |
| 5 | .de Sh \" Subsection heading |
| 6 | .br |
| 7 | .if t .Sp |
| 8 | .ne 5 |
| 9 | .PP |
| 10 | \fB\\$1\fR |
| 11 | .PP |
| 12 | .. |
| 13 | .de Sp \" Vertical space (when we can't use .PP) |
| 14 | .if t .sp .5v |
| 15 | .if n .sp |
| 16 | .. |
| 17 | .de Vb \" Begin verbatim text |
| 18 | .ft CW |
| 19 | .nf |
| 20 | .ne \\$1 |
| 21 | .. |
| 22 | .de Ve \" End verbatim text |
| 23 | .ft R |
| 24 | .fi |
| 25 | .. |
| 26 | .\" Set up some character translations and predefined strings. \*(-- will |
| 27 | .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left |
| 28 | .\" double quote, and \*(R" will give a right double quote. | will give a |
| 29 | .\" real vertical bar. \*(C+ will give a nicer C++. Capital omega is used to |
| 30 | .\" do unbreakable dashes and therefore won't be available. \*(C` and \*(C' |
| 31 | .\" expand to `' in nroff, nothing in troff, for use with C<>. |
| 32 | .tr \(*W-|\(bv\*(Tr |
| 33 | .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' |
| 34 | .ie n \{\ |
| 35 | . ds -- \(*W- |
| 36 | . ds PI pi |
| 37 | . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch |
| 38 | . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch |
| 39 | . ds L" "" |
| 40 | . ds R" "" |
| 41 | . ds C` "" |
| 42 | . ds C' "" |
| 43 | 'br\} |
| 44 | .el\{\ |
| 45 | . ds -- \|\(em\| |
| 46 | . ds PI \(*p |
| 47 | . ds L" `` |
| 48 | . ds R" '' |
| 49 | 'br\} |
| 50 | .\" |
| 51 | .\" If the F register is turned on, we'll generate index entries on stderr for |
| 52 | .\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index |
| 53 | .\" entries marked with X<> in POD. Of course, you'll have to process the |
| 54 | .\" output yourself in some meaningful fashion. |
| 55 | .if \nF \{\ |
| 56 | . de IX |
| 57 | . tm Index:\\$1\t\\n%\t"\\$2" |
| 58 | .. |
| 59 | . nr % 0 |
| 60 | . rr F |
| 61 | .\} |
| 62 | .\" |
| 63 | .\" For nroff, turn off justification. Always turn off hyphenation; it makes |
| 64 | .\" way too many mistakes in technical documents. |
| 65 | .hy 0 |
| 66 | .if n .na |
| 67 | .\" |
| 68 | .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). |
| 69 | .\" Fear. Run. Save yourself. No user-serviceable parts. |
| 70 | . \" fudge factors for nroff and troff |
| 71 | .if n \{\ |
| 72 | . ds #H 0 |
| 73 | . ds #V .8m |
| 74 | . ds #F .3m |
| 75 | . ds #[ \f1 |
| 76 | . ds #] \fP |
| 77 | .\} |
| 78 | .if t \{\ |
| 79 | . ds #H ((1u-(\\\\n(.fu%2u))*.13m) |
| 80 | . ds #V .6m |
| 81 | . ds #F 0 |
| 82 | . ds #[ \& |
| 83 | . ds #] \& |
| 84 | .\} |
| 85 | . \" simple accents for nroff and troff |
| 86 | .if n \{\ |
| 87 | . ds ' \& |
| 88 | . ds ` \& |
| 89 | . ds ^ \& |
| 90 | . ds , \& |
| 91 | . ds ~ ~ |
| 92 | . ds / |
| 93 | .\} |
| 94 | .if t \{\ |
| 95 | . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" |
| 96 | . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' |
| 97 | . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' |
| 98 | . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' |
| 99 | . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' |
| 100 | . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' |
| 101 | .\} |
| 102 | . \" troff and (daisy-wheel) nroff accents |
| 103 | .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' |
| 104 | .ds 8 \h'\*(#H'\(*b\h'-\*(#H' |
| 105 | .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] |
| 106 | .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' |
| 107 | .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' |
| 108 | .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] |
| 109 | .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] |
| 110 | .ds ae a\h'-(\w'a'u*4/10)'e |
| 111 | .ds Ae A\h'-(\w'A'u*4/10)'E |
| 112 | . \" corrections for vroff |
| 113 | .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' |
| 114 | .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' |
| 115 | . \" for low resolution devices (crt and lpr) |
| 116 | .if \n(.H>23 .if \n(.V>19 \ |
| 117 | \{\ |
| 118 | . ds : e |
| 119 | . ds 8 ss |
| 120 | . ds o a |
| 121 | . ds d- d\h'-1'\(ga |
| 122 | . ds D- D\h'-1'\(hy |
| 123 | . ds th \o'bp' |
| 124 | . ds Th \o'LP' |
| 125 | . ds ae ae |
| 126 | . ds Ae AE |
| 127 | .\} |
| 128 | .rm #[ #] #H #V #F C |
| 129 | .\" ======================================================================== |
| 130 | .\" |
| 131 | .IX Title "OBJECT 1" |
| 132 | .TH OBJECT 1 "2002-09-28" "perl v5.8.0" "User Contributed Perl Documentation" |
| 133 | .SH "NAME" |
| 134 | Date::Calc::Object \- Object\-oriented add\-on for Date::Calc with overloaded operators |
| 135 | .SH "MOTTO" |
| 136 | .IX Header "MOTTO" |
| 137 | Make frequent things easy and infrequent or hard things possible |
| 138 | .SH "PREFACE" |
| 139 | .IX Header "PREFACE" |
| 140 | Note that you do \fB\s-1NOT\s0\fR need to "\f(CW\*(C`use Date::Calc qw(...);\*(C'\fR" in |
| 141 | addition to this module. |
| 142 | .PP |
| 143 | Simply |
| 144 | .PP |
| 145 | .Vb 1 |
| 146 | \& use Date::Calc::Object qw(...); |
| 147 | .Ve |
| 148 | .PP |
| 149 | \&\fB\s-1INSTEAD\s0 \s-1OF\s0\fR |
| 150 | .PP |
| 151 | .Vb 1 |
| 152 | \& use Date::Calc qw(...); |
| 153 | .Ve |
| 154 | .PP |
| 155 | with the same "\f(CW\*(C`qw(...)\*(C'\fR\*(L" as you would with the \*(R"Date::Calc\*(L" |
| 156 | module, and then forget about \*(R"Date::Calc::Object" altogether. |
| 157 | .PP |
| 158 | The rest of your existing code doesn't change at all. |
| 159 | .PP |
| 160 | Note also that in order to create a new date object, you do not |
| 161 | need to use |
| 162 | .PP |
| 163 | .Vb 1 |
| 164 | \& $date_object = Date::Calc::Object->new(...); |
| 165 | .Ve |
| 166 | .PP |
| 167 | (but you may), and should use |
| 168 | .PP |
| 169 | .Vb 1 |
| 170 | \& $date_object = Date::Calc->new(...); |
| 171 | .Ve |
| 172 | .PP |
| 173 | instead (saves you some typing and is a trifle faster). |
| 174 | .SH "SYNOPSIS" |
| 175 | .IX Header "SYNOPSIS" |
| 176 | .Sh "Export tags" |
| 177 | .IX Subsection "Export tags" |
| 178 | .Vb 3 |
| 179 | \& :all - all functions from Date::Calc |
| 180 | \& :aux - auxiliary functions shift_* |
| 181 | \& :ALL - both :all and :aux |
| 182 | .Ve |
| 183 | .Sh "Functions" |
| 184 | .IX Subsection "Functions" |
| 185 | See \fIDate::Calc\fR\|(3) for a list of available functions. |
| 186 | .PP |
| 187 | .Vb 4 |
| 188 | \& $year = shift_year(\e@_); |
| 189 | \& ($year,$mm,$dd) = shift_date(\e@_); |
| 190 | \& ($hrs,$min,$sec) = shift_time(\e@_); |
| 191 | \& ($year,$mm,$dd,$hrs,$min,$sec) = shift_datetime(\e@_); |
| 192 | .Ve |
| 193 | .Sh "Methods" |
| 194 | .IX Subsection "Methods" |
| 195 | .Vb 5 |
| 196 | \& $old = Date::Calc->accurate_mode([FLAG]); |
| 197 | \& $old = Date::Calc->number_format([NUMBER|CODEREF]); |
| 198 | \& $old = Date::Calc->delta_format([NUMBER|CODEREF]); # global default |
| 199 | \& $old = Date::Calc->date_format([NUMBER|CODEREF]); # global default |
| 200 | \& $old = Date::Calc->language([LANGUAGE]); # global default |
| 201 | .Ve |
| 202 | .PP |
| 203 | .Vb 5 |
| 204 | \& $old = $date->accurate_mode([FLAG]); # is global nevertheless! |
| 205 | \& $old = $date->number_format([NUMBER|CODEREF]); # is global nevertheless! |
| 206 | \& $old = $date->delta_format([NUMBER|CODEREF]); # individual override |
| 207 | \& $old = $date->date_format([NUMBER|CODEREF]); # individual override |
| 208 | \& $old = $date->language([LANGUAGE]); # individual override |
| 209 | .Ve |
| 210 | .PP |
| 211 | .Vb 5 |
| 212 | \& $flag = $date->is_delta(); |
| 213 | \& $flag = $date->is_date(); |
| 214 | \& $flag = $date->is_short(); # i.e., has no time part |
| 215 | \& $flag = $date->is_long(); # i.e., has time part |
| 216 | \& $flag = $date->is_valid(); |
| 217 | .Ve |
| 218 | .PP |
| 219 | .Vb 6 |
| 220 | \& $date = Date::Calc->new([TYPE]); |
| 221 | \& $date = Date::Calc->new([TYPE,]YEAR,MONTH,DAY[,HRS,MIN,SEC]); |
| 222 | \& $date = Date::Calc->new($arrayref); |
| 223 | \& $newdate = $somedate->new([TYPE]); |
| 224 | \& $newdate = $somedate->new([TYPE,]YEAR,MONTH,DAY[,HRS,MIN,SEC]); |
| 225 | \& $newdate = $somedate->new($arrayref); |
| 226 | .Ve |
| 227 | .PP |
| 228 | .Vb 4 |
| 229 | \& $datecopy = $date->clone(); |
| 230 | \& $targetdate->copy($sourcedate); |
| 231 | \& $targetdate->copy($arrayref); |
| 232 | \& $targetdate->copy(@list); |
| 233 | .Ve |
| 234 | .PP |
| 235 | .Vb 6 |
| 236 | \& ($year,$month,$day) = $date->date([TYPE]); |
| 237 | \& ($year,$month,$day) = $date->date([TYPE,]YEAR,MONTH,DAY[,HRS,MIN,SEC]); |
| 238 | \& ($year,$month,$day) = $date->date($arrayref); |
| 239 | \& ([$hrs,$min,$sec]) = $date->time([TYPE]); |
| 240 | \& ($hrs,$min,$sec) = $date->time([TYPE,]HRS,MIN,SEC); |
| 241 | \& ([$hrs,$min,$sec]) = $date->time($arrayref); |
| 242 | .Ve |
| 243 | .PP |
| 244 | .Vb 4 |
| 245 | \& ($year,$month,$day,$hrs,$min,$sec) = |
| 246 | \& $date->datetime([TYPE]); |
| 247 | \& ($year,$month,$day,$hrs,$min,$sec) = |
| 248 | \& $date->datetime([TYPE,]YEAR,MONTH,DAY[,HRS,MIN,SEC]); |
| 249 | .Ve |
| 250 | .PP |
| 251 | .Vb 7 |
| 252 | \& $date = Date::Calc->today([FLAG]); |
| 253 | \& $date = Date::Calc->now([FLAG]); # shorthand for --+ |
| 254 | \& $date = Date::Calc->today_and_now([FLAG]); # <-----+ |
| 255 | \& $date = Date::Calc->gmtime([time]); # UTC/GMT |
| 256 | \& $date = Date::Calc->localtime([time]); # local time |
| 257 | \& $delta = Date::Calc->tzoffset([time]); |
| 258 | \& $date = Date::Calc->time2date([time]); # UTC/GMT |
| 259 | .Ve |
| 260 | .PP |
| 261 | .Vb 7 |
| 262 | \& $date->today([FLAG]); # updates the date part only |
| 263 | \& $date->now([FLAG]); # updates the time part only |
| 264 | \& $date->today_and_now([FLAG]); # updates both date and time |
| 265 | \& $date->gmtime([time]); # updates both date and time (UTC/GMT) |
| 266 | \& $date->localtime([time]); # updates both date and time (local time) |
| 267 | \& $delta->tzoffset([time]); # updates both date and time |
| 268 | \& $date->time2date([time]); # updates both date and time (UTC/GMT) |
| 269 | .Ve |
| 270 | .PP |
| 271 | .Vb 2 |
| 272 | \& $time = Date::Calc->mktime(); # same as "$time = CORE::time();" |
| 273 | \& $time = Date::Calc->date2time(); # same as "$time = CORE::time();" |
| 274 | .Ve |
| 275 | .PP |
| 276 | .Vb 2 |
| 277 | \& $time = $date->mktime(); # converts into Unix time (local time) |
| 278 | \& $time = $date->date2time(); # converts into Unix time (UTC/GMT) |
| 279 | .Ve |
| 280 | .PP |
| 281 | .Vb 6 |
| 282 | \& $year = $date->year([YEAR]); |
| 283 | \& $month = $date->month([MONTH]); |
| 284 | \& $day = $date->day([DAY]); |
| 285 | \& $hours = $date->hours([HRS]); |
| 286 | \& $minutes = $date->minutes([MIN]); |
| 287 | \& $seconds = $date->seconds([SEC]); |
| 288 | .Ve |
| 289 | .PP |
| 290 | .Vb 2 |
| 291 | \& $number = $date->number([NUMBER|CODEREF]); |
| 292 | \& $string = $date->string([NUMBER|CODEREF][,LANGUAGE]); |
| 293 | .Ve |
| 294 | .PP |
| 295 | .Vb 1 |
| 296 | \& $delta->normalize(); # renormalizes a delta vector |
| 297 | .Ve |
| 298 | .Sh "Overloaded Operators" |
| 299 | .IX Subsection "Overloaded Operators" |
| 300 | .Vb 4 |
| 301 | \& ##################################################### |
| 302 | \& # Scalar operands are always converted into a delta # |
| 303 | \& # vector with that many days, i.e., [1,0,0,SCALAR] # |
| 304 | \& ##################################################### |
| 305 | .Ve |
| 306 | .Sh "Comparison Operators:" |
| 307 | .IX Subsection "Comparison Operators:" |
| 308 | .Vb 6 |
| 309 | \& if ($date1 < $date2) { # compares date part only |
| 310 | \& if ($date1 <= $date2) { # compares date part only |
| 311 | \& if ($date1 > $date2) { # compares date part only |
| 312 | \& if ($date1 >= $date2) { # compares date part only |
| 313 | \& if ($date1 == $date2) { # compares date part only |
| 314 | \& if ($date1 != $date2) { # compares date part only |
| 315 | .Ve |
| 316 | .PP |
| 317 | .Vb 1 |
| 318 | \& $comp = $date1 <=> $date2; # compares date part only |
| 319 | .Ve |
| 320 | .PP |
| 321 | .Vb 6 |
| 322 | \& if ($date1 lt $date2) { # compares both date and time |
| 323 | \& if ($date1 le $date2) { # compares both date and time |
| 324 | \& if ($date1 gt $date2) { # compares both date and time |
| 325 | \& if ($date1 ge $date2) { # compares both date and time |
| 326 | \& if ($date1 eq $date2) { # compares both date and time |
| 327 | \& if ($date1 ne $date2) { # compares both date and time |
| 328 | .Ve |
| 329 | .PP |
| 330 | .Vb 1 |
| 331 | \& $comp = $date1 cmp $date2; # compares both date and time |
| 332 | .Ve |
| 333 | .PP |
| 334 | Note that you can of course also compare two deltas, |
| 335 | but not a date and a delta! |
| 336 | .PP |
| 337 | .Vb 4 |
| 338 | \& ################################################## |
| 339 | \& # Default TYPE for array refs in comparisons is: # |
| 340 | \& # Same as other operand # |
| 341 | \& ################################################## |
| 342 | .Ve |
| 343 | .PP |
| 344 | .Vb 2 |
| 345 | \& if ([2000,4,1] == $date) { |
| 346 | \& if ($today > [2000,4,1]) { |
| 347 | .Ve |
| 348 | .PP |
| 349 | .Vb 1 |
| 350 | \& if ($now ge [2000,3,26,2,0,0]) { |
| 351 | .Ve |
| 352 | .PP |
| 353 | .Vb 2 |
| 354 | \& if ($delta == [18,0,0]) { |
| 355 | \& if ($delta == -1) { |
| 356 | .Ve |
| 357 | .Sh "Plus:" |
| 358 | .IX Subsection "Plus:" |
| 359 | .Vb 5 |
| 360 | \& $date2 = $date1 + $delta; |
| 361 | \& $date2 = $delta + $date1; |
| 362 | \& $date += $delta; |
| 363 | \& $this = $date++; |
| 364 | \& $next = ++$date; |
| 365 | .Ve |
| 366 | .PP |
| 367 | .Vb 5 |
| 368 | \& $delta3 = $delta1 + $delta2; |
| 369 | \& $delta1 += $delta2; |
| 370 | \& $delta += $date; # beware of implicit type change! |
| 371 | \& $delta++; |
| 372 | \& ++$delta; |
| 373 | .Ve |
| 374 | .PP |
| 375 | .Vb 4 |
| 376 | \& ##################################################### |
| 377 | \& # Default TYPE for array refs in '+' operations is: # |
| 378 | \& # Opposite of other operand # |
| 379 | \& ##################################################### |
| 380 | .Ve |
| 381 | .PP |
| 382 | .Vb 6 |
| 383 | \& $date2 = [2000,3,26] + $delta; |
| 384 | \& $date2 = $date1 + [+1,0,0]; |
| 385 | \& $date2 = [0,0,-1] + $date1; |
| 386 | \& $date2 = $date1 + 1; |
| 387 | \& $date += [0,0,+1]; |
| 388 | \& $date += 2; |
| 389 | .Ve |
| 390 | .PP |
| 391 | .Vb 6 |
| 392 | \& $delta3 = [1,+1,0,-1] + $delta2; |
| 393 | \& $delta3 = $delta1 + [1,0,0,+1]; |
| 394 | \& $delta3 = $delta1 + 1; |
| 395 | \& $delta += [1,0,+1,0]; |
| 396 | \& $delta += [2000,3,26]; # beware of implicit type change! |
| 397 | \& $delta += 7; |
| 398 | .Ve |
| 399 | .Sh "Unary Minus:" |
| 400 | .IX Subsection "Unary Minus:" |
| 401 | .Vb 1 |
| 402 | \& $delta2 = -$delta1; |
| 403 | .Ve |
| 404 | .Sh "Minus:" |
| 405 | .IX Subsection "Minus:" |
| 406 | .Vb 6 |
| 407 | \& $delta = $date2 - $date1; |
| 408 | \& $date2 = $date1 - $delta; |
| 409 | \& $date -= $delta; |
| 410 | \& $date2 -= $date1; # beware of implicit type change! |
| 411 | \& $this = $date--; |
| 412 | \& $prev = --$date; |
| 413 | .Ve |
| 414 | .PP |
| 415 | .Vb 4 |
| 416 | \& $delta3 = $delta2 - $delta1; |
| 417 | \& $delta2 -= $delta1; |
| 418 | \& $delta--; |
| 419 | \& --$delta; |
| 420 | .Ve |
| 421 | .PP |
| 422 | .Vb 4 |
| 423 | \& ##################################################### |
| 424 | \& # Default TYPE for array refs in '-' operations is: # |
| 425 | \& # Always a date # |
| 426 | \& ##################################################### |
| 427 | .Ve |
| 428 | .PP |
| 429 | .Vb 8 |
| 430 | \& $delta = $today - [2000,3,26]; |
| 431 | \& $delta = [2000,4,1] - $date; |
| 432 | \& $date2 = [2000,3,26] - $delta; |
| 433 | \& $date2 = $date1 - [1,0,0,+7]; |
| 434 | \& $date2 = $date1 - 7; |
| 435 | \& $date -= [1,0,0,+1]; # better add [0,0,-1] instead! |
| 436 | \& $date2 -= [2000,3,26]; # beware of implicit type change! |
| 437 | \& $date2 -= 1; |
| 438 | .Ve |
| 439 | .PP |
| 440 | .Vb 4 |
| 441 | \& $delta3 = [1,0,+1,0] - $delta1; |
| 442 | \& $delta3 = $delta2 - [1,0,0,-1]; |
| 443 | \& $delta -= [1,0,0,+1]; |
| 444 | \& $delta -= 7; |
| 445 | .Ve |
| 446 | .Sh "Miscellaneous Operators:" |
| 447 | .IX Subsection "Miscellaneous Operators:" |
| 448 | .Vb 2 |
| 449 | \& $string = "$date"; |
| 450 | \& $string = "$delta"; |
| 451 | .Ve |
| 452 | .PP |
| 453 | .Vb 2 |
| 454 | \& print "$date\en"; |
| 455 | \& print "$delta\en"; |
| 456 | .Ve |
| 457 | .PP |
| 458 | .Vb 2 |
| 459 | \& if ($date) { # date is valid |
| 460 | \& if ($delta) { # delta is valid |
| 461 | .Ve |
| 462 | .PP |
| 463 | .Vb 2 |
| 464 | \& $days = abs($date); |
| 465 | \& $diff = abs($delta); # can be negative! |
| 466 | .Ve |
| 467 | .PP |
| 468 | .Vb 1 |
| 469 | \& $diff = abs(abs($delta)); # always positive |
| 470 | .Ve |
| 471 | .SH "DESCRIPTION" |
| 472 | .IX Header "DESCRIPTION" |
| 473 | .IP "\(bu" 2 |
| 474 | \&\s-1FLAG\s0 |
| 475 | .Sp |
| 476 | \&\*(L"\s-1FLAG\s0\*(R" is either 0 (for \*(L"false\*(R") or 1 (for \*(L"true\*(R"). |
| 477 | .Sp |
| 478 | In the case of "\f(CW\*(C`accurate_mode()\*(C'\fR\*(L", this switches \*(R"accurate mode" |
| 479 | on and off (see further below for an explanation of what that is). |
| 480 | .Sp |
| 481 | In the case of "\f(CW\*(C`today()\*(C'\fR\*(L", \*(R"\f(CW\*(C`now()\*(C'\fR\*(L" and \*(R"\f(CW\*(C`today_and_now()\*(C'\fR\*(L", |
| 482 | a \*(R"true\*(L" value indicates \*(R"\s-1GMT\s0" (Greenwich Mean Time), as opposed |
| 483 | to local time, which is the default. |
| 484 | .IP "\(bu" 2 |
| 485 | \&\s-1NUMBER\s0 |
| 486 | .Sp |
| 487 | \&\*(L"\s-1NUMBER\s0\*(R" is a number between 0 and 2 (for \*(L"\fInumber_format()\fR\*(R" and \*(L"\fInumber()\fR\*(R") |
| 488 | or between 0 and 3 (for \*(L"\fIdelta_format()\fR\*(R", \*(L"\fIdate_format()\fR\*(R" and \*(L"\fIstring()\fR\*(R"), |
| 489 | indicating which of the three/four predefined formats, respectively, |
| 490 | should be used for converting a date into numeric representation |
| 491 | (needed for comparing dates, for instance) or string representation. |
| 492 | .Sp |
| 493 | Format #0 is the default at startup and the simplest of all (and |
| 494 | should be fastest to calculate, too). |
| 495 | .Sp |
| 496 | The string representation of dates in format #0 also has the advantage of |
| 497 | being sortable in chronological order (and of complying with \s-1ISO\s0\ 8601). |
| 498 | .Sp |
| 499 | (The numeric formats are (trivially) always sortable in chronological |
| 500 | order of course.) |
| 501 | .Sp |
| 502 | The other formats are increasingly more sophisticated (in terms of |
| 503 | esthetics and computation time) with increasing number: |
| 504 | .Sp |
| 505 | .Vb 1 |
| 506 | \& Delta number formats (short): |
| 507 | .Ve |
| 508 | .Sp |
| 509 | .Vb 3 |
| 510 | \& 0 13603 |
| 511 | \& 1 13603 |
| 512 | \& 2 13603 |
| 513 | .Ve |
| 514 | .Sp |
| 515 | .Vb 1 |
| 516 | \& Delta string formats (short): |
| 517 | .Ve |
| 518 | .Sp |
| 519 | .Vb 4 |
| 520 | \& 0 '+0+0+13603' |
| 521 | \& 1 '+0 +0 +13603' |
| 522 | \& 2 '+0Y +0M +13603D' |
| 523 | \& 3 '+0 Y +0 M +13603 D' |
| 524 | .Ve |
| 525 | .Sp |
| 526 | .Vb 1 |
| 527 | \& Date number formats (short): |
| 528 | .Ve |
| 529 | .Sp |
| 530 | .Vb 3 |
| 531 | \& 0 20010401 |
| 532 | \& 1 730576 |
| 533 | \& 2 730576 |
| 534 | .Ve |
| 535 | .Sp |
| 536 | .Vb 1 |
| 537 | \& Date string formats (short): |
| 538 | .Ve |
| 539 | .Sp |
| 540 | .Vb 4 |
| 541 | \& 0 '20010401' |
| 542 | \& 1 '01-Apr-2001' |
| 543 | \& 2 'Sun 1-Apr-2001' |
| 544 | \& 3 'Sunday, April 1st 2001' |
| 545 | .Ve |
| 546 | .Sp |
| 547 | .Vb 1 |
| 548 | \& Delta number formats (long): |
| 549 | .Ve |
| 550 | .Sp |
| 551 | .Vb 3 |
| 552 | \& 0 13603.012959 |
| 553 | \& 1 13603.012959 |
| 554 | \& 2 13603.0624884259 |
| 555 | .Ve |
| 556 | .Sp |
| 557 | .Vb 1 |
| 558 | \& Delta string formats (long): |
| 559 | .Ve |
| 560 | .Sp |
| 561 | .Vb 4 |
| 562 | \& 0 '+0+0+13603+1+29+59' |
| 563 | \& 1 '+0 +0 +13603 +1 +29 +59' |
| 564 | \& 2 '+0Y +0M +13603D +1h +29m +59s' |
| 565 | \& 3 '+0 Y +0 M +13603 D +1 h +29 m +59 s' |
| 566 | .Ve |
| 567 | .Sp |
| 568 | .Vb 1 |
| 569 | \& Date number formats (long): |
| 570 | .Ve |
| 571 | .Sp |
| 572 | .Vb 3 |
| 573 | \& 0 20010401.082959 |
| 574 | \& 1 730576.082959 |
| 575 | \& 2 730576.354155093 |
| 576 | .Ve |
| 577 | .Sp |
| 578 | .Vb 1 |
| 579 | \& Date string formats (long): |
| 580 | .Ve |
| 581 | .Sp |
| 582 | .Vb 4 |
| 583 | \& 0 '20010401082959' |
| 584 | \& 1 '01-Apr-2001 08:29:59' |
| 585 | \& 2 'Sun 1-Apr-2001 08:29:59' |
| 586 | \& 3 'Sunday, April 1st 2001 08:29:59' |
| 587 | .Ve |
| 588 | .Sp |
| 589 | If a number outside of the permitted range is specified, or if the value |
| 590 | is not a code reference (see also the next section below for more details), |
| 591 | the default format #0 is used instead. |
| 592 | .IP "\(bu" 2 |
| 593 | \&\s-1CODEREF\s0 |
| 594 | .Sp |
| 595 | \&\*(L"\s-1CODEREF\s0\*(R" is the reference of a subroutine which can be passed to the |
| 596 | methods \*(L"\fInumber_format()\fR\*(R", \*(L"\fIdelta_format()\fR\*(R" and \*(L"\fIdate_format()\fR\*(R" in order |
| 597 | to install a callback function which will be called subsequently whenever |
| 598 | a date (or delta) object needs to be (implicitly) converted into a number |
| 599 | or string. |
| 600 | .Sp |
| 601 | This happens for instance when you compare two date objects, or when you |
| 602 | put a date object reference in a string between double quotes. |
| 603 | .Sp |
| 604 | Such a \*(L"\s-1CODEREF\s0\*(R" can also be passed to the methods \*(L"\fInumber()\fR\*(R" and |
| 605 | \&\*(L"\fIstring()\fR\*(R" for explicitly converting a date object as desired. |
| 606 | .IP "\(bu" 2 |
| 607 | \&\s-1LANGUAGE\s0 |
| 608 | .Sp |
| 609 | \&\*(L"\s-1LANGUAGE\s0\*(R" is either a number in the range \f(CW\*(C`[1..Languages()]\*(C'\fR, |
| 610 | or one of the strings "\f(CW\*(C`Language_to_Text(1..Languages())\*(C'\fR" |
| 611 | (see also \fIDate::Calc\fR\|(3)). |
| 612 | .IP "\(bu" 2 |
| 613 | \&\s-1TYPE\s0 |
| 614 | .Sp |
| 615 | \&\*(L"\s-1TYPE\s0\*(R" is 0 for a regular date and 1 for a delta vector (a list of |
| 616 | year, month, day and optionally hours, minutes and seconds offsets). |
| 617 | .IP "\(bu" 2 |
| 618 | Storage |
| 619 | .Sp |
| 620 | \&\*(L"Date::Calc\*(R" objects are implemented as two nested arrays. |
| 621 | .Sp |
| 622 | The \*(L"blessed\*(R" array (whose reference is the object reference |
| 623 | you receive when calling the \*(L"\fInew()\fR\*(R" method) contains an |
| 624 | anonymous array at position zero and the object's data in |
| 625 | its remaining fields. |
| 626 | .Sp |
| 627 | The embedded anonymous array is used for storing the object's |
| 628 | attributes (flags). |
| 629 | .Sp |
| 630 | Dates and delta vectors always comprise either 3 or 6 data values: |
| 631 | Year, month, day plus (optionally) hours, minutes and seconds. |
| 632 | .Sp |
| 633 | These values are stored in the \*(L"blessed\*(R" array at positions 1..3 |
| 634 | or 1..6, respectively. |
| 635 | .Sp |
| 636 | An object without the time values is therefore called \*(L"short\*(R", |
| 637 | and an object having time values is called \*(L"long\*(R" throughout |
| 638 | this manual. |
| 639 | .Sp |
| 640 | Hint: Whenever possible, if you do not need the time values, omit |
| 641 | them, i.e., always use the \*(L"short\*(R" form of the object if possible, |
| 642 | this will speed up calculations a little (the short form uses |
| 643 | different (faster) functions for all calculations internally). |
| 644 | .Sp |
| 645 | The embedded anonymous array contains various flags: |
| 646 | .Sp |
| 647 | At position zero, it contains the \*(L"\s-1TYPE\s0\*(R" indicator which determines |
| 648 | whether the object is a date or a delta vector. |
| 649 | .Sp |
| 650 | At position 1, the object stores the \*(L"\s-1NUMBER\s0\*(R" of one of the delta |
| 651 | vector formats, or the reference of a callback function which converts |
| 652 | the contents of the object into string representation if it's a delta |
| 653 | vector, or \*(L"undef\*(R" if the global settings apply. |
| 654 | .Sp |
| 655 | At position 2, the object stores the \*(L"\s-1NUMBER\s0\*(R" of one of the date formats, |
| 656 | or the reference of a callback function which converts the contents of |
| 657 | the object into string representation if it's a date, or \*(L"undef\*(R" if the |
| 658 | global settings apply. |
| 659 | .Sp |
| 660 | At position 3, the object stores the \*(L"\s-1LANGUAGE\s0\*(R" to be used for all |
| 661 | conversions into strings (where applicable), or \*(L"undef\*(R" if the global |
| 662 | language setting applies. |
| 663 | .Sp |
| 664 | Note that your callback functions (see the section \*(L"Callback Functions\*(R" |
| 665 | further below for more details) do not need to pay attention to the |
| 666 | value at position 3, the language (of the \*(L"Date::Calc\*(R" module) |
| 667 | will automatically be set to this value whenever the callback |
| 668 | functions are called, and automatically reset to its former value |
| 669 | after the callback. |
| 670 | .Sp |
| 671 | So if your callback functions use the \*(L"*_to_Text*\*(R" functions from |
| 672 | the \*(L"Date::Calc\*(R" module, they will automatically use the correct |
| 673 | language. |
| 674 | .Sp |
| 675 | Be reminded though that you should \fB\s-1NEVER\s0\fR access the object's |
| 676 | internal data directly, i.e., through their positional numbers, |
| 677 | but \fB\s-1ALWAYS\s0\fR through their respective accessor methods, e.g.: |
| 678 | .Sp |
| 679 | .Vb 16 |
| 680 | \& year() |
| 681 | \& month() |
| 682 | \& day() |
| 683 | \& hours() |
| 684 | \& minutes() |
| 685 | \& seconds() |
| 686 | \& date() |
| 687 | \& time() |
| 688 | \& datetime() |
| 689 | \& is_delta() |
| 690 | \& is_date() |
| 691 | \& is_short() |
| 692 | \& is_long() |
| 693 | \& delta_format() |
| 694 | \& date_format() |
| 695 | \& language() |
| 696 | .Ve |
| 697 | .Sp |
| 698 | And although position 4 and onward in the embedded anonymous array is |
| 699 | currently unused, it might not stay so in future releases of this module. |
| 700 | .Sp |
| 701 | Therefore, in case you need more attributes in a subclass of the |
| 702 | \&\*(L"Date::Calc[::Object]\*(R" class, I suggest using values starting at |
| 703 | positions a bit further up, e.g. 6, 8 or 10. |
| 704 | .IP "\(bu" 2 |
| 705 | Invalid Dates |
| 706 | .Sp |
| 707 | Only \*(L"\fInew()\fR\*(R" allows to create objects containing possibly invalid |
| 708 | dates (needed for reading in and evaluating user input, for example). |
| 709 | .IP "\(bu" 2 |
| 710 | Usage |
| 711 | .Sp |
| 712 | The methods |
| 713 | .Sp |
| 714 | .Vb 14 |
| 715 | \& accurate_mode() |
| 716 | \& number_format() |
| 717 | \& delta_format() |
| 718 | \& date_format() |
| 719 | \& language() |
| 720 | \& date() |
| 721 | \& time() |
| 722 | \& datetime() |
| 723 | \& year() |
| 724 | \& month() |
| 725 | \& day() |
| 726 | \& hours() |
| 727 | \& minutes() |
| 728 | \& seconds() |
| 729 | .Ve |
| 730 | .Sp |
| 731 | are used for reading as well as for setting attributes. They simply |
| 732 | return the values in question if they are called without parameters. |
| 733 | .Sp |
| 734 | The methods |
| 735 | .Sp |
| 736 | .Vb 5 |
| 737 | \& accurate_mode() |
| 738 | \& number_format() |
| 739 | \& delta_format() |
| 740 | \& date_format() |
| 741 | \& language() |
| 742 | .Ve |
| 743 | .Sp |
| 744 | always return the previous value if a new value is set. This allows |
| 745 | you to change these values temporarily and to restore their old value |
| 746 | afterwards more easily (but you can also override the \*(L"format\*(R" and |
| 747 | \&\*(L"language\*(R" settings directly when calling the \*(L"\fInumber()\fR\*(R" or \*(L"\fIstring()\fR\*(R" |
| 748 | method). |
| 749 | .Sp |
| 750 | The methods |
| 751 | .Sp |
| 752 | .Vb 9 |
| 753 | \& date() |
| 754 | \& time() |
| 755 | \& datetime() |
| 756 | \& year() |
| 757 | \& month() |
| 758 | \& day() |
| 759 | \& hours() |
| 760 | \& minutes() |
| 761 | \& seconds() |
| 762 | .Ve |
| 763 | .Sp |
| 764 | always return the new values when the corresponding values have |
| 765 | been changed. |
| 766 | .Sp |
| 767 | The method \*(L"\fIdate()\fR\*(R" \s-1NEVER\s0 returns the time values (hours, minutes, |
| 768 | seconds) even if they have just been set using this method (which |
| 769 | the method optionally allows). Otherwise it would be very hard to |
| 770 | predict the exact number of values it returns, which might lead |
| 771 | to errors (wrong number of parameters) elsewhere in your program. |
| 772 | .Sp |
| 773 | The method \*(L"\fIdatetime()\fR\*(R" \s-1ALWAYS\s0 returns the time values (hours, |
| 774 | minutes, seconds) even if the object in question lacks a time |
| 775 | part. In that case, zeros are returned for hours, minutes and |
| 776 | seconds instead (but the stored time part is left unchanged, |
| 777 | whether it exists or not). |
| 778 | .Sp |
| 779 | If you do not provide values for hours, minutes and seconds when |
| 780 | using the method \*(L"\fIdate()\fR\*(R" to set the values for year, month and |
| 781 | day, the time part will not be changed (whether it exists or not). |
| 782 | .Sp |
| 783 | If you do not provide values for hours, minutes and seconds when |
| 784 | using the method \*(L"\fIdatetime()\fR\*(R" to set the values for year, month |
| 785 | and day, the time part will be filled with zeros (the time part |
| 786 | will be created if necessary). |
| 787 | .Sp |
| 788 | If the object is short, i.e., if it does not have any time values, |
| 789 | the method \*(L"\fItime()\fR\*(R" returns an empty list. |
| 790 | .Sp |
| 791 | If the object is short and the methods \*(L"\fIhours()\fR\*(R", \*(L"\fIminutes()\fR\*(R" or |
| 792 | \&\*(L"\fIseconds()\fR\*(R" are used to set any of these time values, the object |
| 793 | is automatically promoted to the \*(L"long\*(R" form, and the other two |
| 794 | time values are filled with zeros. |
| 795 | .Sp |
| 796 | The following methods can also return \*(L"undef\*(R" under certain |
| 797 | circumstances: |
| 798 | .Sp |
| 799 | .Vb 13 |
| 800 | \& delta_format() |
| 801 | \& date_format() |
| 802 | \& language() |
| 803 | \& is_delta() |
| 804 | \& is_date() |
| 805 | \& is_short() |
| 806 | \& is_long() |
| 807 | \& is_valid() |
| 808 | \& hours() |
| 809 | \& minutes() |
| 810 | \& seconds() |
| 811 | \& number() |
| 812 | \& string() |
| 813 | .Ve |
| 814 | .Sp |
| 815 | The methods \*(L"\fIdelta_format()\fR\*(R", \*(L"\fIdate_format()\fR\*(R" and \*(L"\fIlanguage()\fR\*(R" |
| 816 | return \*(L"undef\*(R" when they are called as object methods and no |
| 817 | individual override has been defined for the object in question. |
| 818 | .Sp |
| 819 | The \*(L"is_*()\*(R" predicate methods return \*(L"undef\*(R" if the object in |
| 820 | question does not have the expected internal structure. This can |
| 821 | happen for instance when you create an empty object with \*(L"\fInew()\fR\*(R". |
| 822 | .Sp |
| 823 | When called without parameters, the methods \*(L"\fIhours()\fR\*(R", \*(L"\fIminutes()\fR\*(R" |
| 824 | and \*(L"\fIseconds()\fR\*(R" return \*(L"undef\*(R" if the object in question does not |
| 825 | have a time part. |
| 826 | .Sp |
| 827 | The methods \*(L"\fInumber()\fR\*(R" and \*(L"\fIstring()\fR\*(R" return \*(L"undef\*(R" if the object |
| 828 | in question is not valid (i.e., if \*(L"\fIis_valid()\fR\*(R" returns \*(L"undef\*(R" or |
| 829 | false). |
| 830 | .Sp |
| 831 | And finally, the methods |
| 832 | .Sp |
| 833 | .Vb 9 |
| 834 | \& copy() |
| 835 | \& today() |
| 836 | \& now() |
| 837 | \& today_and_now() |
| 838 | \& gmtime() |
| 839 | \& localtime() |
| 840 | \& tzoffset() |
| 841 | \& time2date() |
| 842 | \& normalize() |
| 843 | .Ve |
| 844 | .Sp |
| 845 | return the object reference of the (target) object in question |
| 846 | for convenience. |
| 847 | .IP "\(bu" 2 |
| 848 | Import/Export |
| 849 | .Sp |
| 850 | Note that you can import and export Unix \*(L"time\*(R" values using the |
| 851 | methods \*(L"\fIgmtime()\fR\*(R", \*(L"\fIlocaltime()\fR\*(R", \*(L"\fImktime()\fR\*(R", \*(L"\fIdate2time()\fR\*(R" and |
| 852 | \&\*(L"\fItime2date()\fR\*(R", both as local time or as \s-1UTC/GMT\s0. |
| 853 | .IP "\(bu" 2 |
| 854 | Accurate Mode |
| 855 | .Sp |
| 856 | The method \*(L"\fIaccurate_mode()\fR\*(R" controls the internal flag which |
| 857 | determines which of two modes of operation is used. |
| 858 | .Sp |
| 859 | When set to true (the default at startup), delta vectors are |
| 860 | calculated to give the exact difference in days between two |
| 861 | dates. The \*(L"year\*(R" and \*(L"month\*(R" entries in the resulting delta |
| 862 | vector are always zero in that case. |
| 863 | .Sp |
| 864 | If \*(L"accurate mode\*(R" is switched off (when the corresponding |
| 865 | flag is set to false), delta vectors are calculated with |
| 866 | year and month differences. |
| 867 | .Sp |
| 868 | E.g., the difference between \f(CW\*(C`[1999,12,6]\*(C'\fR and \f(CW\*(C`[2000,6,24]\*(C'\fR |
| 869 | is \f(CW\*(C`[+0 +0 +201]\*(C'\fR (plus 201 days) in accurate mode and |
| 870 | \&\f(CW\*(C`[+1 \-6 +18]\*(C'\fR (plus one year, minus 6 months, plus 18 days) |
| 871 | when accurate mode is switched off. |
| 872 | .Sp |
| 873 | (The delta vector is calculated by simply taking the difference |
| 874 | in years, the difference in months and the difference in days.) |
| 875 | .Sp |
| 876 | Because years and months have varying lengths in terms of days, |
| 877 | the latter is less accurate than the former because it depends |
| 878 | on the context of the two dates of which it represents the |
| 879 | difference. Added to a different date, the latter delta vector |
| 880 | may yield a different offset in terms of days. |
| 881 | .Sp |
| 882 | Beware also that \- for the same reason \- the absolute value |
| 883 | ("\f(CW\*(C`abs()\*(C'\fR\*(L") of a delta vector returns a fictitious number |
| 884 | of days if the delta vector contains non-zero values for |
| 885 | \&\*(R"year\*(L" and/or \*(R"month" (see also next section below for |
| 886 | more details). |
| 887 | .Sp |
| 888 | Example: |
| 889 | .Sp |
| 890 | The difference between \f(CW\*(C`[2000,1,1]\*(C'\fR and \f(CW\*(C`[2000,3,1]\*(C'\fR is |
| 891 | \&\f(CW\*(C`[+0 +0 +60]\*(C'\fR in accurate mode and \f(CW\*(C`[+0 +2 +0]\*(C'\fR else (one |
| 892 | could also call this \*(L"year\-month\-day mode\*(R" or \*(L"\s-1YMD\s0 mode\*(R" for |
| 893 | short). |
| 894 | .Sp |
| 895 | When added to the date \f(CW\*(C`[2000,4,1]\*(C'\fR, the \*(L"accurate\*(R" delta |
| 896 | vector yields the date \f(CW\*(C`[2000,5,31]\*(C'\fR, whereas the other delta |
| 897 | vector yields the date \f(CW\*(C`[2000,6,1]\*(C'\fR. |
| 898 | .Sp |
| 899 | Moreover, when added to the date \f(CW\*(C`[1999,1,1]\*(C'\fR, the \*(L"accurate\*(R" |
| 900 | delta vector yields the date \f(CW\*(C`[1999,3,2]\*(C'\fR, whereas the \*(L"inaccurate\*(R" |
| 901 | delta vector yields the date \f(CW\*(C`[1999,3,1]\*(C'\fR. |
| 902 | .Sp |
| 903 | Depending on what you want, the one or the other mode may suit |
| 904 | you better. |
| 905 | .IP "\(bu" 2 |
| 906 | Absolute Value |
| 907 | .Sp |
| 908 | Note that "\f(CW\*(C`abs($date)\*(C'\fR\*(L" and \*(R"\f(CW\*(C`abs($delta)\*(C'\fR\*(L" are just shorthands |
| 909 | for \*(R"\f(CW\*(C`$date\->number()\*(C'\fR\*(L" and \*(R"\f(CW\*(C`$delta\->number()\*(C'\fR". |
| 910 | .Sp |
| 911 | The operator "\f(CW\*(C`abs()\*(C'\fR", when applied to a date or delta vector, |
| 912 | returns the corresponding number of days (see below for an exception |
| 913 | to this), with the time part (if available) represented by a fraction |
| 914 | after the decimal point. |
| 915 | .Sp |
| 916 | In the case of dates, the absolute value (to the left of the |
| 917 | decimal point) is the number of days since the 1st of January |
| 918 | 1\ A.D. (by extrapolating the Gregorian calendar back beyond |
| 919 | its \*(L"natural\*(R" limit of 1582 A.D.) \fB\s-1PLUS\s0 \s-1ONE\s0\fR. |
| 920 | .Sp |
| 921 | (I.e., the absolute value of the 1st of January 1 A.D. is 1.) |
| 922 | .Sp |
| 923 | Exception: |
| 924 | .Sp |
| 925 | If the \*(L"\s-1NUMBER\s0\*(R" or \*(L"\fInumber_format()\fR\*(R" is set to 0 (the default |
| 926 | setting), the absolute value of a date to the left of the decimal |
| 927 | point is \*(L"yyyymmdd\*(R", i.e., the number in which the uppermost four |
| 928 | digits correspond to the year, the next lower two digits to the |
| 929 | month and the lowermost two digits to the day. |
| 930 | .Sp |
| 931 | In the case of delta vectors, the absolute value (to the left |
| 932 | of the decimal point) is simply the difference in days (but |
| 933 | see also below). |
| 934 | .Sp |
| 935 | Note that the absolute value of a delta vector can be negative! |
| 936 | .Sp |
| 937 | If you want a positive value in all cases, apply the "\f(CW\*(C`abs()\*(C'\fR\*(L" |
| 938 | operator again, i.e., \*(R"\f(CW\*(C`$posdiff = abs(abs($delta));\*(C'\fR". |
| 939 | .Sp |
| 940 | If the delta vector contains non-zero values for \*(L"year\*(R" and/or |
| 941 | \&\*(L"month\*(R" (see also the discussion of \*(L"Accurate Mode\*(R" in the section |
| 942 | above), an exact representation in days cannot be calculated, |
| 943 | because years and months do not have fixed equivalents in days. |
| 944 | .Sp |
| 945 | If nevertheless you attempt to calculate the absolute value of |
| 946 | such a delta vector, a fictitious value is returned, which is |
| 947 | calculated by simply multiplying the year difference with 12, |
| 948 | adding the month difference, multiplying this sum with 31 and |
| 949 | finally adding the day difference. |
| 950 | .Sp |
| 951 | Beware that because of this, the absolute values of delta |
| 952 | vectors are not necessarily contiguous. |
| 953 | .Sp |
| 954 | Moreover, since there is more than one way to express the |
| 955 | difference between two dates, comparisons of delta vectors |
| 956 | may not always yield the expected result. |
| 957 | .Sp |
| 958 | Example: |
| 959 | .Sp |
| 960 | The difference between the two dates \f(CW\*(C`[2000,4,30]\*(C'\fR and |
| 961 | \&\f(CW\*(C`[2001,5,1]\*(C'\fR can be expressed as \f(CW\*(C`[+1 +1 \-29]\*(C'\fR, or as |
| 962 | \&\f(CW\*(C`[+1 +0 +1]\*(C'\fR. |
| 963 | .Sp |
| 964 | The first delta vector has an absolute value of 374, |
| 965 | whereas the latter delta vector has an absolute value |
| 966 | of only 373 (while the true difference in days between |
| 967 | the two dates is 366). |
| 968 | .Sp |
| 969 | If the date or delta vector has a time part, the time is returned |
| 970 | as a fraction of a full day after the decimal point as follows: |
| 971 | .Sp |
| 972 | If the \*(L"\s-1NUMBER\s0\*(R" or \*(L"\fInumber_format()\fR\*(R" is set to 0 (the default |
| 973 | setting) or 1, this fraction is simply \*(L".hhmmss\*(R", i.e., the |
| 974 | two digits after the decimal point represent the hours, the |
| 975 | next two digits the minutes and the last two digits the seconds. |
| 976 | .Sp |
| 977 | Note that you cannot simply add and subtract these values to |
| 978 | yield meaningful dates or deltas again, you can only use them |
| 979 | for comparisons (equal, not equal, less than, greater than, |
| 980 | etc.). If you want to add/subtract, read on: |
| 981 | .Sp |
| 982 | Only when the \*(L"\s-1NUMBER\s0\*(R" or \*(L"\fInumber_format()\fR\*(R" is set to 2, this |
| 983 | fraction will be the equivalent number of seconds (i.e., |
| 984 | \&\f(CW\*(C`(((hours * 60) + minutes) * 60) + seconds\*(C'\fR) divided by the |
| 985 | number of seconds in a full day (i.e., \f(CW\*(C`24*60*60 = 86400\*(C'\fR), |
| 986 | or \f(CW\*(C`0/86400\*(C'\fR, \f(CW\*(C`1/86400\*(C'\fR, ... , \f(CW\*(C`86399/86400\*(C'\fR. |
| 987 | .Sp |
| 988 | In other words, the (mathematically correct) fraction of a day. |
| 989 | .Sp |
| 990 | You can safely perform arithmetics with these values as far |
| 991 | as the internal precision of your vendor's implementation |
| 992 | of the C run-time library (on which Perl depends) will permit. |
| 993 | .IP "\(bu" 2 |
| 994 | Renormalizing Delta Vectors |
| 995 | .Sp |
| 996 | When adding or subtracting delta vectors to/from one another, |
| 997 | the addition or subtraction takes place component by component. |
| 998 | .Sp |
| 999 | Example: |
| 1000 | .Sp |
| 1001 | .Vb 2 |
| 1002 | \& [+0 +0 +0 +3 +29 +50] + [+0 +0 +0 +0 +55 +5] = [+0 +0 +0 +3 +84 +55] |
| 1003 | \& [+0 +0 +0 +3 +29 +50] - [+0 +0 +0 +0 +55 +5] = [+0 +0 +0 +3 -26 +45] |
| 1004 | .Ve |
| 1005 | .Sp |
| 1006 | This may result in time values outside the usual ranges (\f(CW\*(C`[\-23..+23]\*(C'\fR |
| 1007 | for hours and \f(CW\*(C`[\-59..+59]\*(C'\fR for minutes and seconds). |
| 1008 | .Sp |
| 1009 | Note that even though the delta value for days will often become quite large, |
| 1010 | it is impossible to renormalize this value because there is no constant |
| 1011 | conversion factor from days to months (should it be 28, 29, 30 or 31?). |
| 1012 | .Sp |
| 1013 | If accurate mode (see further above for what that is) is switched off, |
| 1014 | delta vectors can also contain non-zero values for years and months. If |
| 1015 | you add or subtract these, the value for months can lie outside the |
| 1016 | range \f(CW\*(C`[\-11..11]\*(C'\fR, which isn't wrong, but may seem funny. |
| 1017 | .Sp |
| 1018 | Therefore, the \*(L"\fInormalize()\fR\*(R" method will also renormalize the \*(L"months\*(R" |
| 1019 | value, if and only if accurate mode has been switched off. (!) |
| 1020 | .Sp |
| 1021 | (Hence, switch accurate mode \fB\s-1ON\s0\fR temporarily if you \fB\s-1DON\s0'T\fR want |
| 1022 | the renormalization of the \*(L"months\*(R" value to happen.) |
| 1023 | .Sp |
| 1024 | If you want to force the time values from the example above back into |
| 1025 | their proper ranges, use the \*(L"\fInormalize()\fR\*(R" method as follows: |
| 1026 | .Sp |
| 1027 | .Vb 3 |
| 1028 | \& print "[$delta]\en"; |
| 1029 | \& $delta->normalize(); |
| 1030 | \& print "[$delta]\en"; |
| 1031 | .Ve |
| 1032 | .Sp |
| 1033 | This will print |
| 1034 | .Sp |
| 1035 | .Vb 2 |
| 1036 | \& [+0 +0 +0 +3 +84 +55] |
| 1037 | \& [+0 +0 +0 +4 +24 +55] |
| 1038 | .Ve |
| 1039 | .Sp |
| 1040 | for the first and |
| 1041 | .Sp |
| 1042 | .Vb 2 |
| 1043 | \& [+0 +0 +0 +3 -26 +45] |
| 1044 | \& [+0 +0 +0 +2 +34 +45] |
| 1045 | .Ve |
| 1046 | .Sp |
| 1047 | for the second delta vector from the example further above. |
| 1048 | .Sp |
| 1049 | Note that the values for days, hours, minutes and seconds are |
| 1050 | guaranteed to have the same sign after the renormalization. |
| 1051 | .Sp |
| 1052 | Under \*(L"normal\*(R" circumstances, i.e., when accurate mode is on (the |
| 1053 | default), this method only has an effect on the time part of the |
| 1054 | delta vector. |
| 1055 | .Sp |
| 1056 | If the delta vector in question does not have a time part, nothing |
| 1057 | is done. |
| 1058 | .Sp |
| 1059 | If accurate mode is off, the \*(L"months\*(R" value is also normalized, |
| 1060 | i.e., if it lies outside of the range \f(CW\*(C`[\-11..11]\*(C'\fR, integer |
| 1061 | multiples of 12 are added to the \*(L"years\*(R" value and subtracted |
| 1062 | from the \*(L"months\*(R" value. Moreover, the \*(L"months\*(R" value is |
| 1063 | guaranteed to have the same sign as the values for days, |
| 1064 | hours, minutes and seconds, unless the \*(L"months\*(R" value is zero |
| 1065 | or the values for days, hours, minutes and seconds are all zero. |
| 1066 | .Sp |
| 1067 | If the object in question is a date and if warnings are enabled, |
| 1068 | the message \*(L"normalizing a date is a no\-op\*(R" will be printed to |
| 1069 | \&\s-1STDERR\s0. |
| 1070 | .Sp |
| 1071 | If the object in question is not a valid \*(L"Date::Calc\*(R" object, |
| 1072 | nothing is done. |
| 1073 | .Sp |
| 1074 | The method returns its object's reference, which allows chaining |
| 1075 | of method calls, as in the following example: |
| 1076 | .Sp |
| 1077 | .Vb 1 |
| 1078 | \& @time = $delta->normalize()->time(); |
| 1079 | .Ve |
| 1080 | .IP "\(bu" 2 |
| 1081 | Callback Functions |
| 1082 | .Sp |
| 1083 | Note that you are not restricted to the built-in formats |
| 1084 | (numbered from 0 to 2 for \*(L"\fInumber_format()\fR\*(R" and \*(L"\fInumber()\fR\*(R" |
| 1085 | and from 0 to 3 for \*(L"\fIdelta_format()\fR\*(R", \*(L"\fIdate_format()\fR\*(R" and |
| 1086 | \&\*(L"\fIstring()\fR\*(R") for converting a date or delta object into a |
| 1087 | number or string. |
| 1088 | .Sp |
| 1089 | You can also provide your own function(s) for doing so, in |
| 1090 | order to suit your own taste or needs, by passing a subroutine |
| 1091 | reference to the appropriate method, i.e., \*(L"\fInumber_format()\fR\*(R", |
| 1092 | \&\*(L"\fInumber()\fR\*(R", \*(L"\fIdelta_format()\fR\*(R", \*(L"\fIdate_format()\fR\*(R" and \*(L"\fIstring()\fR\*(R". |
| 1093 | .Sp |
| 1094 | You can pass a handler to only one or more of these methods, |
| 1095 | or to all of them, as you like. You can use different callback |
| 1096 | functions, or the same for all. |
| 1097 | .Sp |
| 1098 | In order to facilitate the latter, and in order to make the |
| 1099 | decoding of the various cases easier for you, the callback |
| 1100 | function receives a uniquely identifying function code as |
| 1101 | its second parameter: |
| 1102 | .Sp |
| 1103 | .Vb 8 |
| 1104 | \& 0 = TO_NUMBER | IS_DATE | IS_SHORT (number[_format]) |
| 1105 | \& 1 = TO_NUMBER | IS_DATE | IS_LONG (number[_format]) |
| 1106 | \& 2 = TO_NUMBER | IS_DELTA | IS_SHORT (number[_format]) |
| 1107 | \& 3 = TO_NUMBER | IS_DELTA | IS_LONG (number[_format]) |
| 1108 | \& 4 = TO_STRING | IS_DATE | IS_SHORT (string|date_format) |
| 1109 | \& 5 = TO_STRING | IS_DATE | IS_LONG (string|date_format) |
| 1110 | \& 6 = TO_STRING | IS_DELTA | IS_SHORT (string|delta_format) |
| 1111 | \& 7 = TO_STRING | IS_DELTA | IS_LONG (string|delta_format) |
| 1112 | .Ve |
| 1113 | .Sp |
| 1114 | The first parameter of the callback function is of course the |
| 1115 | handle of the object in question itself (therefore, the callback |
| 1116 | function can actually be an object method \- but not a class method, |
| 1117 | for obvious reasons). |
| 1118 | .Sp |
| 1119 | The handler should return the resulting number or string, as |
| 1120 | requested. |
| 1121 | .Sp |
| 1122 | \&\s-1BEWARE\s0 that you should \s-1NEVER\s0 rely upon any knowledge of the |
| 1123 | object's internal structure, as this may be subject to change! |
| 1124 | .Sp |
| 1125 | \&\s-1ALWAYS\s0 use the test and access methods provided by this module! |
| 1126 | .Sp |
| 1127 | Example: |
| 1128 | .Sp |
| 1129 | .Vb 3 |
| 1130 | \& sub handler |
| 1131 | \& { |
| 1132 | \& my($self,$code) = @_; |
| 1133 | .Ve |
| 1134 | .Sp |
| 1135 | .Vb 48 |
| 1136 | \& if ($code == 0) # TO_NUMBER | IS_DATE | IS_SHORT |
| 1137 | \& { |
| 1138 | \& return Date_to_Days( $self->date() ); |
| 1139 | \& } |
| 1140 | \& elsif ($code == 1) # TO_NUMBER | IS_DATE | IS_LONG |
| 1141 | \& { |
| 1142 | \& return Date_to_Days( $self->date() ) + |
| 1143 | \& ( ( $self->hours() * 60 + |
| 1144 | \& $self->minutes() ) * 60 + |
| 1145 | \& $self->seconds() ) / 86400; |
| 1146 | \& } |
| 1147 | \& elsif ($code == 2) # TO_NUMBER | IS_DELTA | IS_SHORT |
| 1148 | \& { |
| 1149 | \& return ( $self->year() * 12 + |
| 1150 | \& $self->month() ) * 31 + |
| 1151 | \& $self->day(); |
| 1152 | \& } |
| 1153 | \& elsif ($code == 3) # TO_NUMBER | IS_DELTA | IS_LONG |
| 1154 | \& { |
| 1155 | \& return ( $self->year() * 12 + |
| 1156 | \& $self->month() ) * 31 + |
| 1157 | \& $self->day() + |
| 1158 | \& ( ( $self->hours() * 60 + |
| 1159 | \& $self->minutes() ) * 60 + |
| 1160 | \& $self->seconds() ) / 86400; |
| 1161 | \& } |
| 1162 | \& elsif ($code == 4) # TO_STRING | IS_DATE | IS_SHORT |
| 1163 | \& { |
| 1164 | \& return join( "/", $self->date() ); |
| 1165 | \& } |
| 1166 | \& elsif ($code == 5) # TO_STRING | IS_DATE | IS_LONG |
| 1167 | \& { |
| 1168 | \& return join( "/", $self->date() ) . " " . |
| 1169 | \& join( ":", $self->time() ); |
| 1170 | \& } |
| 1171 | \& elsif ($code == 6) # TO_STRING | IS_DELTA | IS_SHORT |
| 1172 | \& { |
| 1173 | \& return join( "|", $self->date() ); |
| 1174 | \& } |
| 1175 | \& elsif ($code == 7) # TO_STRING | IS_DELTA | IS_LONG |
| 1176 | \& { |
| 1177 | \& return join( "|", $self->datetime() ); |
| 1178 | \& } |
| 1179 | \& else |
| 1180 | \& { |
| 1181 | \& die "internal error"; |
| 1182 | \& } |
| 1183 | \& } |
| 1184 | .Ve |
| 1185 | .Sp |
| 1186 | .Vb 3 |
| 1187 | \& Date::Calc->number_format(\e&handler); |
| 1188 | \& Date::Calc->delta_format(\e&handler); |
| 1189 | \& Date::Calc->date_format(\e&handler); |
| 1190 | .Ve |
| 1191 | .Sp |
| 1192 | This sets our handler to take care of all automatic conversions, |
| 1193 | such as needed when comparing dates or when interpolating a string |
| 1194 | in double quotes which contains a date object. |
| 1195 | .Sp |
| 1196 | To deactivate a handler, simply pass a valid format number to the |
| 1197 | method in question, e.g.: |
| 1198 | .Sp |
| 1199 | .Vb 3 |
| 1200 | \& Date::Calc->number_format(0); |
| 1201 | \& Date::Calc->delta_format(2); |
| 1202 | \& Date::Calc->date_format(3); |
| 1203 | .Ve |
| 1204 | .Sp |
| 1205 | When calling the \*(L"\fInumber()\fR\*(R" or \*(L"\fIstring()\fR\*(R" method explicitly, you can |
| 1206 | pass a different format number (than the global setting), like this: |
| 1207 | .Sp |
| 1208 | .Vb 2 |
| 1209 | \& $number = $date->number(2); |
| 1210 | \& $string = $date->string(1); |
| 1211 | .Ve |
| 1212 | .Sp |
| 1213 | You can also pass a handler's reference, like so: |
| 1214 | .Sp |
| 1215 | .Vb 2 |
| 1216 | \& $number = $date->number(\e&handler); |
| 1217 | \& $string = $date->string(\e&handler); |
| 1218 | .Ve |
| 1219 | .Sp |
| 1220 | This overrides the global setting for the duration of the call of |
| 1221 | \&\*(L"\fInumber()\fR\*(R" or \*(L"\fIstring()\fR\*(R" (but doesn't change the global setting |
| 1222 | itself). |
| 1223 | .Sp |
| 1224 | Moreover, you can also define individual overrides for the date and |
| 1225 | the delta vector formats (but not the number format) for individual |
| 1226 | objects, e.g.: |
| 1227 | .Sp |
| 1228 | .Vb 2 |
| 1229 | \& $date->delta_format(1); |
| 1230 | \& $date->date_format(2); |
| 1231 | .Ve |
| 1232 | .Sp |
| 1233 | .Vb 2 |
| 1234 | \& $date->delta_format(\e&handler); |
| 1235 | \& $date->date_format(\e&handler); |
| 1236 | .Ve |
| 1237 | .Sp |
| 1238 | In order to deactivate an individual handler for an object, and/or |
| 1239 | in order to deactivate any override altogether (so that the global |
| 1240 | settings apply again), you have to pass \*(L"undef\*(R" explicitly to the |
| 1241 | method in question: |
| 1242 | .Sp |
| 1243 | .Vb 2 |
| 1244 | \& $date->delta_format(undef); |
| 1245 | \& $date->date_format(undef); |
| 1246 | .Ve |
| 1247 | .Sp |
| 1248 | You can also define a language for individual objects (see the |
| 1249 | next section immediately below for more details). |
| 1250 | .Sp |
| 1251 | If such an individual language override has been set, and if your |
| 1252 | callback handlers only use the \*(L"*_to_Text*\*(R" functions from the |
| 1253 | \&\*(L"Date::Calc\*(R" module to produce any text, the text produced will |
| 1254 | automatically be in the desired language. |
| 1255 | .Sp |
| 1256 | This is because the language is set to the value determined by |
| 1257 | the individual override before the callback handler is executed, |
| 1258 | and reset to its previous value afterwards. |
| 1259 | .IP "\(bu" 2 |
| 1260 | Languages |
| 1261 | .Sp |
| 1262 | Note that this module is completely transparent to the setting |
| 1263 | of a language in \*(L"Date::Calc\*(R". This means that you can choose a |
| 1264 | language in \*(L"Date::Calc\*(R" (with the \*(L"\fILanguage()\fR\*(R" function) and all |
| 1265 | dates subsequently printed by this module will automatically be |
| 1266 | in that language \- provided that you use the built-in formats of |
| 1267 | this module, or that you use the \*(L"*to_Text*\*(R" functions from the |
| 1268 | \&\*(L"Date::Calc\*(R" module in your formatting handler (callback function). |
| 1269 | .Sp |
| 1270 | However, this global language setting can be overridden for |
| 1271 | individual date (or delta) objects by using the \fB\s-1OBJECT\s0\fR method |
| 1272 | .Sp |
| 1273 | .Vb 1 |
| 1274 | \& $oldlang = $date->language($newlang); |
| 1275 | .Ve |
| 1276 | .Sp |
| 1277 | (The global setting is not altered by this in any way.) |
| 1278 | .Sp |
| 1279 | In order to deactivate such an individual language setting |
| 1280 | (so that the global setting applies again), simply pass the |
| 1281 | value \*(L"undef\*(R" explicitly to the \*(L"\fIlanguage()\fR\*(R" object method: |
| 1282 | .Sp |
| 1283 | .Vb 1 |
| 1284 | \& $date->language(undef); |
| 1285 | .Ve |
| 1286 | .Sp |
| 1287 | The \fB\s-1CLASS\s0\fR method |
| 1288 | .Sp |
| 1289 | .Vb 1 |
| 1290 | \& $oldlang = Date::Calc->language($newlang); |
| 1291 | .Ve |
| 1292 | .Sp |
| 1293 | is just a convenient wrapper around the \*(L"\fILanguage()\fR\*(R" function, |
| 1294 | which allows you to enter language numbers (as returned by the |
| 1295 | \&\*(L"\fIDecode_Language()\fR\*(R" function) or strings (as returned by the |
| 1296 | \&\*(L"\fILanguage_to_Text()\fR\*(R" function), at your option. |
| 1297 | .Sp |
| 1298 | The \*(L"\fIlanguage()\fR\*(R" method (both class and object) always returns |
| 1299 | the \fB\s-1NAME\s0\fR (one of "\f(CW\*(C`Language_to_Text(1..Languages())\*(C'\fR") of |
| 1300 | the current setting (and never its number). |
| 1301 | .IP "\(bu" 2 |
| 1302 | Exported Functions |
| 1303 | .Sp |
| 1304 | The \*(L"Date::Calc::Object\*(R" package imports \*(L":all\*(R" functions exported |
| 1305 | by the \*(L"Date::Calc\*(R" module and re-exports them, for conveniency. |
| 1306 | .Sp |
| 1307 | This allows you to write |
| 1308 | .Sp |
| 1309 | .Vb 1 |
| 1310 | \& use Date::Calc::Object qw(...); |
| 1311 | .Ve |
| 1312 | .Sp |
| 1313 | instead of |
| 1314 | .Sp |
| 1315 | .Vb 1 |
| 1316 | \& use Date::Calc qw(...); |
| 1317 | .Ve |
| 1318 | .Sp |
| 1319 | but with exactly the same semantics. The difference is that |
| 1320 | the object-oriented frontend is loaded additionally in the |
| 1321 | first case. |
| 1322 | .Sp |
| 1323 | As with \*(L"Date::Calc\*(R" you can use the \*(L":all\*(R" tag to import all |
| 1324 | of \*(L"Date::Calc\*(R"'s functions: |
| 1325 | .Sp |
| 1326 | .Vb 1 |
| 1327 | \& use Date::Calc::Object qw(:all); |
| 1328 | .Ve |
| 1329 | .Sp |
| 1330 | In addition to the functions exported by \*(L"Date::Calc\*(R", the |
| 1331 | \&\*(L"Date::Calc::Object\*(R" package offers some utility functions |
| 1332 | of its own for export: |
| 1333 | .Sp |
| 1334 | .Vb 4 |
| 1335 | \& $year = shift_year(\e@_); |
| 1336 | \& ($year,$mm,$dd) = shift_date(\e@_); |
| 1337 | \& ($hrs,$min,$sec) = shift_time(\e@_); |
| 1338 | \& ($year,$mm,$dd,$hrs,$min,$sec) = shift_datetime(\e@_); |
| 1339 | .Ve |
| 1340 | .Sp |
| 1341 | These functions enable your subroutines or methods to accept |
| 1342 | a \*(L"Date::Calc\*(R" (or subclass) date object, an (anonymous) array |
| 1343 | or a list (containing the necessary values) as parameters |
| 1344 | \&\fB\s-1INTERCHANGEABLY\s0\fR. |
| 1345 | .Sp |
| 1346 | You can import all of these auxiliary functions by using an |
| 1347 | \&\*(L":aux\*(R" tag: |
| 1348 | .Sp |
| 1349 | .Vb 1 |
| 1350 | \& use Date::Calc::Object qw(:aux); |
| 1351 | .Ve |
| 1352 | .Sp |
| 1353 | If you want to import both all of the \*(L"Date::Calc\*(R" functions |
| 1354 | as well as all these auxiliary functions, use the \*(L":ALL\*(R" tag: |
| 1355 | .Sp |
| 1356 | .Vb 1 |
| 1357 | \& use Date::Calc::Object qw(:ALL); |
| 1358 | .Ve |
| 1359 | .IP "\(bu" 2 |
| 1360 | Subclassing |
| 1361 | .Sp |
| 1362 | In case you want to subclass \*(L"Date::Calc\*(R" objects and to add |
| 1363 | new attributes of your own, it is recommended that you proceed |
| 1364 | as follows (the following will be considered as a part of the |
| 1365 | module's \*(L"contract of use\*(R" \- which might be subject to change |
| 1366 | in the future, however): |
| 1367 | .Sp |
| 1368 | Define a constant for the index of each attribute you want to |
| 1369 | add, currently starting no lower than \*(L"4\*(R", at the top of your |
| 1370 | subclass: |
| 1371 | .Sp |
| 1372 | .Vb 4 |
| 1373 | \& use constant ATTRIB1 => 4; |
| 1374 | \& use constant ATTRIB2 => 5; |
| 1375 | \& use constant ATTRIB3 => 6; |
| 1376 | \& ... |
| 1377 | .Ve |
| 1378 | .Sp |
| 1379 | It is recommended that you use constants (which are easy to |
| 1380 | change), because I someday might want to require the element |
| 1381 | with index \*(L"4\*(R" for a new attribute of my own... \f(CW\*(C`:\-)\*(C'\fR |
| 1382 | .Sp |
| 1383 | Then access your attributes like so (e.g. after calling |
| 1384 | "\f(CW\*(C`$self = SUPER\->new();\*(C'\fR" in your constructor method): |
| 1385 | .Sp |
| 1386 | .Vb 4 |
| 1387 | \& $self->[0][ATTRIB1] = 'value1'; |
| 1388 | \& $self->[0][ATTRIB2] = 'value2'; |
| 1389 | \& $self->[0][ATTRIB3] = 'value3'; |
| 1390 | \& ... |
| 1391 | .Ve |
| 1392 | .Sp |
| 1393 | Beware that if you put anything other than numbers or strings |
| 1394 | into your attributes, the methods \*(L"\fIclone()\fR\*(R" and \*(L"\fIcopy()\fR\*(R" might |
| 1395 | not work as expected anymore! |
| 1396 | .Sp |
| 1397 | Especially if your attributes contain references to other data |
| 1398 | structures, only the references will be copied, but not the data |
| 1399 | structures themselves. |
| 1400 | .Sp |
| 1401 | This may not be what you want. |
| 1402 | .Sp |
| 1403 | (You will have to override these two methods and write some |
| 1404 | of your own if not.) |
| 1405 | .Sp |
| 1406 | In order for the overloaded operators and the \*(L"shift_*()\*(R" |
| 1407 | auxiliary functions from the \*(L"Date::Calc::Object\*(R" package |
| 1408 | to work properly (the latter of which are heavily used in |
| 1409 | the \*(L"Date::Calendar[::Year]\*(R" modules, for instance), the |
| 1410 | package name of your subclass (= the one your objects will |
| 1411 | be blessed into) is \fB\s-1REQUIRED\s0\fR to contain a \*(L"::\*(R". |
| 1412 | .Sp |
| 1413 | Note that you should \fB\s-1ONLY\s0\fR subclass \*(L"Date::Calc\*(R", \fB\s-1NEVER\s0\fR |
| 1414 | \&\*(L"Date::Calc::Object\*(R", since subclassing the latter is less |
| 1415 | efficient (because \*(L"Date::Calc::Object\*(R" is just an empty class |
| 1416 | which inherits from \*(L"Date::Calc\*(R" \- subclassing \*(L"Date::Calc::Object\*(R" |
| 1417 | would thus just introduce an additional name space layer to search |
| 1418 | during Perl's runtime method binding process). |
| 1419 | .Sp |
| 1420 | If you give your subclass a package name below/inside the |
| 1421 | \&\*(L"Date::\*(R" namespace, you will also benefit from the fact that |
| 1422 | all error messages produced by the \*(L"Date::Calc[::Object]\*(R" module |
| 1423 | (and also the \*(L"Date::Calendar[::Year]\*(R" modules, by the way) |
| 1424 | will appear to have originated from the place outside of all |
| 1425 | "\f(CW\*(C`/^Date::/\*(C'\fR\*(L" modules (including yours) where one of the \*(R"Date::\*(L" |
| 1426 | modules was first called \- i.e., all errors are always blamed |
| 1427 | on the user, no matter how deeply nested inside the \*(R"Date::\*(L" |
| 1428 | modules they occur, and do not usually refer to places inside |
| 1429 | any of the \*(R"Date::\*(L" modules (this assumes that there are no |
| 1430 | bugs in the \*(R"Date::" modules, and that all errors are always |
| 1431 | the user's fault \f(CW\*(C`:\-)\*(C'\fR). |
| 1432 | .Sp |
| 1433 | Moreover, your module's own error messages will behave in the |
| 1434 | same way if you "\f(CW\*(C`use Carp::Clan qw(^Date::);\*(C'\fR\*(L" at the top of |
| 1435 | your module and if you produce all error messages using \*(R"\fIcarp()\fR\*(L" |
| 1436 | and \*(R"\fIcroak()\fR\*(L" (instead of \*(R"\fIwarn()\fR\*(L" and \*(R"\fIdie()\fR", respectively). |
| 1437 | .SH "EXAMPLES" |
| 1438 | .IX Header "EXAMPLES" |
| 1439 | .IP "1)" 3 |
| 1440 | .Vb 7 |
| 1441 | \& # Switch to summer time: |
| 1442 | \& $now = Date::Calc->now(); |
| 1443 | \& if (($now ge [2000,3,26,2,0,0]) and |
| 1444 | \& ($now lt [2000,3,26,3,0,0])) |
| 1445 | \& { |
| 1446 | \& $now += [0,0,0,1,0,0]; |
| 1447 | \& } |
| 1448 | .Ve |
| 1449 | .IP "2)" 3 |
| 1450 | .Vb 1 |
| 1451 | \& use Date::Calc::Object qw(:all); |
| 1452 | .Ve |
| 1453 | .Sp |
| 1454 | .Vb 1 |
| 1455 | \& Date::Calc->date_format(3); |
| 1456 | .Ve |
| 1457 | .Sp |
| 1458 | .Vb 21 |
| 1459 | \& $date = 0; |
| 1460 | \& while (!$date) |
| 1461 | \& { |
| 1462 | \& print "Please enter the date of your birthday (day-month-year): "; |
| 1463 | \& $date = Date::Calc->new( Decode_Date_EU( scalar(<STDIN>) ) ); |
| 1464 | \& if ($date) |
| 1465 | \& { |
| 1466 | \& $resp = 0; |
| 1467 | \& while ($resp !~ /^\es*[YyNn]/) |
| 1468 | \& { |
| 1469 | \& print "Your birthday is: $date\en"; |
| 1470 | \& print "Is that correct? (yes/no) "; |
| 1471 | \& $resp = <STDIN>; |
| 1472 | \& } |
| 1473 | \& $date = 0 unless ($resp =~ /^\es*[Yy]/) |
| 1474 | \& } |
| 1475 | \& else |
| 1476 | \& { |
| 1477 | \& print "Unable to parse your birthday. Please try again.\en"; |
| 1478 | \& } |
| 1479 | \& } |
| 1480 | .Ve |
| 1481 | .Sp |
| 1482 | .Vb 4 |
| 1483 | \& if ($date + [18,0,0] <= [Today()]) |
| 1484 | \& { print "Ok, you are over 18.\en"; } |
| 1485 | \& else |
| 1486 | \& { print "Sorry, you are under 18!\en"; } |
| 1487 | .Ve |
| 1488 | .PP |
| 1489 | For more examples, see the \*(L"examples\*(R" subdirectory in this distribution, |
| 1490 | and their descriptions in the file \*(L"\s-1EXAMPLES\s0.txt\*(R". |
| 1491 | .SH "SEE ALSO" |
| 1492 | .IX Header "SEE ALSO" |
| 1493 | \&\fIDate::Calc\fR\|(3), \fIDate::Calendar\fR\|(3), |
| 1494 | \&\fIDate::Calendar::Year\fR\|(3), \fIDate::Calendar::Profiles\fR\|(3). |
| 1495 | .SH "VERSION" |
| 1496 | .IX Header "VERSION" |
| 1497 | This man page documents \*(L"Date::Calc::Object\*(R" version 5.3. |
| 1498 | .SH "AUTHOR" |
| 1499 | .IX Header "AUTHOR" |
| 1500 | .Vb 3 |
| 1501 | \& Steffen Beyer |
| 1502 | \& mailto:sb@engelschall.com |
| 1503 | \& http://www.engelschall.com/u/sb/download/ |
| 1504 | .Ve |
| 1505 | .SH "COPYRIGHT" |
| 1506 | .IX Header "COPYRIGHT" |
| 1507 | Copyright (c) 2000 \- 2002 by Steffen Beyer. All rights reserved. |
| 1508 | .SH "LICENSE" |
| 1509 | .IX Header "LICENSE" |
| 1510 | This package is free software; you can redistribute it and/or |
| 1511 | modify it under the same terms as Perl itself, i.e., under the |
| 1512 | terms of the \*(L"Artistic License\*(R" or the \*(L"\s-1GNU\s0 General Public License\*(R". |
| 1513 | .PP |
| 1514 | Please refer to the files \*(L"Artistic.txt\*(R" and \*(L"\s-1GNU_GPL\s0.txt\*(R" |
| 1515 | in this distribution for details! |
| 1516 | .SH "DISCLAIMER" |
| 1517 | .IX Header "DISCLAIMER" |
| 1518 | This package is distributed in the hope that it will be useful, |
| 1519 | but \s-1WITHOUT\s0 \s-1ANY\s0 \s-1WARRANTY\s0; without even the implied warranty of |
| 1520 | \&\s-1MERCHANTABILITY\s0 or \s-1FITNESS\s0 \s-1FOR\s0 A \s-1PARTICULAR\s0 \s-1PURPOSE\s0. |
| 1521 | .PP |
| 1522 | See the \*(L"\s-1GNU\s0 General Public License\*(R" for more details. |