1Date::ICal(3)         User Contributed Perl Documentation        Date::ICal(3)
2
3
4

NAME

6       Date::ICal - Perl extension for ICalendar date objects.
7

VERSION

9       $Revision: 1.72 $
10

SYNOPSIS

12           use Date::ICal;
13
14           $ical = Date::ICal->new( ical => '19971024T120000' );
15           $ical = Date::ICal->new( epoch => time );
16           $ical = Date::ICal->new( year => 1964,
17               month => 10, day => 16, hour => 16,
18               min => 12, sec => 47 );
19
20           $hour = $ical->hour;
21           $year = $ical->year;
22
23           $ical_string = $ical->ical;
24           $epoch_time = $ical->epoch;
25
26           $ical2 = $ical + $duration;
27
28       (Where $duration is either a duration string, like 'P2W3DT7H9M', or a
29       Date::ICal::Duration (qv) object.
30
31           $ical += 'P6DT12H';
32
33           $duration = $ical1 - $ical2;
34           $ical3 = $ical1 - $duration;
35

DESCRIPTION

37       Date::ICal talks the ICal date format, and is intended to be a base
38       class for other date/calendar modules that know about ICal time format
39       also.
40
41       See http://dates.rcbowen.com/unified.txt for details
42

AUTHOR

44       Rich Bowen, and the Reefknot team (www.reefknot)
45
46       Last touched by $Author: rbowen $
47

METHODS

49       Date::ICal has the following methods available:
50
51   new
52       A new Date::ICal object can be created with any valid ICal string:
53
54           my $ical = Date::ICal->new( ical => '19971024T120000' );
55           # will default to the timezone specified in $TZ, see below
56
57       Or with any epoch time:
58
59           my $ical = Date::ICal->new( epoch => time );
60
61       Or, better still, create it with components
62
63           my $date = Date::ICal->new(
64                                  day => 25,
65                                  month => 10,
66                                  year => 1066,
67                                  hour => 7,
68                                  min => 15,
69                                  sec => 47
70                                  );
71
72       If you call new without any arguments, you'll get a Date::ICal object
73       that is set to the time right now.
74
75           my $ical = Date::ICal->new();
76
77       If you already have an object in Date::ICal, or some other subclass
78       thereof, you can create a new Date::ICal (or subclass) object using
79       that object to start with. This is particularly useful for converting
80       from one calendar to another:
81
82          # Direct conversion from Discordian to ISO dates
83          my $disco = Date::Discordian->new( disco => '12 Chaos, YOLD 3177' );
84          my $iso = Date::ISO->new( $disco );
85          print $iso->iso;
86
87       new() handles timezones. It defaults times to UTC (Greenwich Mean Time,
88       also called Zulu). If you want to set up a time that's in the US
89       "Pacific" timezone, which is GMT-8, use something like:
90
91           my $ical = Date::ICal->new( ical => '19971024T120000',
92                                       offset => "-0800");
93
94       Note that as of version 1.44, new() tries to be intelligent about
95       figuring out your local time zone. If you enter a time that's not
96       *explicitly* in UTC, it looks at the environment variable $TZ, if it
97       exists, to determine your local offset. If $TZ isn't set, new() will
98       complain.
99
100   ical
101           $ical_string = $ical->ical;
102
103       Retrieves, or sets, the date on the object, using any valid ICal
104       date/time string. Output is in UTC (ends with a "Z") by default. To get
105       output in localtime relative to the current machine, do:
106
107           $ical_string = $ical->ical( localtime => 1 );
108
109       To get output relative to an arbitrary offset, do:
110
111           $ical_string = $ical->ical( offset => '+0545' );
112
113   epoch
114           $epoch_time = $ical->epoch;
115
116           $ical->epoch( 98687431 );
117
118       Sets, or retrieves, the epoch time represented by the object, if it is
119       representable as such. (Dates before 1971 or after 2038 will not have
120       an epoch representation.)
121
122       Internals note: The ICal representation of the date is considered the
123       only authoritative one. This means that we may need to reconstruct the
124       epoch time from the ICal representation if we are not sure that they
125       are in synch. We'll need to do clever things to keep track of when the
126       two may not be in synch.  And, of course, the same will go for any
127       subclasses of this class.
128
129   offset_to_seconds
130           $seconds_plus_or_minus = offset_to_seconds($offset);
131
132       Changes -0600 to -21600. Not object method, no side-effects.
133
134   offset_from_seconds
135           $seconds_plus_or_minus = offset_from_seconds($offset_in_seconds);
136
137       Changes -18000 (seconds) to -0600 (hours, minutes).  Not object method,
138       no side-effects.
139
140   offset
141           $offset = $ical->offset;
142
143           # We need tests for these.
144           $ical->offset( '+1100' ); # a number of hours and minutes: UTC+11
145           $ical->offset( 0 );       # reset to UTC
146
147       Sets or retrieves the offset from UTC for this time. This allows
148       timezone support, assuming you know what your local (or non-local) UTC
149       offset is. Defaults to 0.
150
151       Internals note: all times are internally stored in UTC, even though
152       they may have some offset information. Offsets are internally stored in
153       signed integer seconds.
154
155       BE CAREFUL about using this function on objects that were initialized
156       with an offset. If you started an object with:
157
158           my $d = new(ical=>'19700101120000', offset=>'+0100');
159
160       and you then call:
161
162           $d->offset('+0200');
163
164       you'll be saying "Yeah, I know I *said* it was in +0100, but really I
165       want it to be in +0200 now and forever." Which may be your intention,
166       if you're trying to transpose a whole set of dates to another
167       timezone--- but you can also do that at the presentation level, with
168       the ical() method. Either way will work.
169
170   add
171           $self->add( year => 3, month => 2, week => 1, day => 12,
172                       hour => 1, minute => 34, sec => 59 );
173           $date->add( duration => 'P1WT1H1M1S' ); # add 1 wk, 1 hr, 1 min, and 1 sec
174
175       Adds a duration to a Date::ICal object.
176
177       Supported paraters are: duration, eom_mode, year, month, week, day,
178       hour, min, sec or seconds.
179
180       'duration' is a ICalendar duration string (see duration_value).
181
182       If a value is undefined or omitted, 1 is assumed:
183
184           $ical->add( 'minute' ); # add a minute
185
186       The result will be normalized. That is, the output time will have
187       meaningful values, rather than being 48:73 pm on the 34th of
188       hexadecember.
189
190       Adding months or years can be done via three different methods,
191       specified by the eom_mode parameter, which then applies to all
192       additions (or subtractions) of months or years following it in the
193       parameter list.
194
195       The default, eom_mode => 'wrap', means adding months or years that
196       result in days beyond the end of the new month will roll over into the
197       following month.  For instance, adding one year to Feb 29 will result
198       in Mar 1.
199
200       If you specify eom_mode => 'limit', the end of the month is never
201       crossed.  Thus, adding one year to Feb 29, 2000 will result in Feb 28,
202       2001.  However, adding three more years will result in Feb 28, 2004,
203       not Feb 29.
204
205       If you specify eom_mode => 'preserve', the same calculation is done as
206       for 'limit' except that if the original date is at the end of the month
207       the new date will also be.  For instance, adding one month to Feb 29,
208       2000 will result in Mar 31, 2000.
209
210       All additions are performed in the order specified.  For instance, with
211       the default setting of eom_mode => 'wrap', adding one day and one month
212       to Feb 29 will result in Apr 1, while adding one month and one day will
213       result in Mar 30.
214
215   add_overload
216           $date = $date1 + $duration;
217
218       Where $duration is either a duration string, or a Date::ICal::Duration
219       object.
220
221           $date += 'P2DT4H7M';
222
223       Adds a duration to a date object. Returns a new object, or, in the case
224       of +=, modifies the existing object.
225
226   duration_value
227       Given a duration string, this function returns the number of days,
228       seconds, and months represented by that duration. In that order. Seems
229       odd to me. This should be considered an internal function, and you
230       should expect the API to change in the very near future.
231
232   subtract
233         $duration = $date1 - $date2;
234
235       Subtract one Date::ICal object from another to give a duration - the
236       length of the interval between the two dates. The return value is a
237       Date::ICal::Duration object (qv) and allows you to get at each of the
238       individual components, or the entire duration string:
239
240           $d = $date1 - $X;
241
242       Note that $X can be any of the following:
243
244       If $X is another Date::ICal object (or subclass thereof) then $d will
245       be a Date::ICal::Duration object.
246
247           $week = $d->weeks; # how many weeks apart?
248           $days = $d->as_days; # How many days apart?
249
250       If $X is a duration string, or a Date::ICal::Diration object, then $d
251       will be an object in the same class as $date1;
252
253           $newdate = $date - $duration;
254
255   clone
256           $copy = $date->clone;
257
258       Returns a replica of the date object, including all attributes.
259
260   compare
261           $cmp = $date1->compare($date2);
262
263           @dates = sort {$a->compare($b)} @dates;
264
265       Compare two Date::ICal objects. Semantics are compatible with sort;
266       returns -1 if $a < $b, 0 if $a == $b, 1 if $a > $b.
267
268   day
269           my $day = $date->day;
270
271       Returns the day of the month.
272
273       Day is in the range 1..31
274
275   month
276           my $month = $date->month;
277
278       Returns the month of the year.
279
280       Month is returned as a number in the range 1..12
281
282   year
283           my $year = $date->year;
284
285       Returns the year.
286
287   jd2greg
288           ($year, $month, $day) = jd2greg( $jd );
289
290           Convert number of days on or after Jan 1, 1 CE (Gregorian) to
291           gregorian year,month,day.
292
293   greg2jd
294           $jd = greg2jd( $year, $month, $day );
295
296           Convert gregorian year,month,day to days on or after Jan 1, 1 CE
297           (Gregorian).  Normalization is performed (e.g. month of 28 means
298           April two years after given year) for month < 1 or > 12 or day < 1
299           or > last day of month.
300
301   days_this_year
302         $yday = Date::ICal::days_this_year($day, $month, $year);
303
304       Returns the number of days so far this year. Analogous to the yday
305       attribute of gmtime (or localtime) except that it works outside of the
306       epoch.
307
308   day_of_week
309           my $day_of_week = $date->day_of_week
310
311       Returns the day of week as 0..6 (0 is Sunday, 6 is Saturday).
312
313   hour
314           my $hour = $date->hour
315
316       Returns the hour of the day.
317
318       Hour is in the range 0..23
319
320   min
321           my $min = $date->min;
322
323       Returns the minute.
324
325       Minute is in the range 0..59
326
327   sec
328           my $sec = $date->sec;
329
330       Returns the second.
331
332       Second is in the range 0..60. The value of 60 is (maybe) needed for
333       leap seconds. But I'm not sure if we're going to go there.
334
335   julian
336         my $jd = $date->jd;
337
338       Returns a listref, containing two elements. The date as a julian day,
339       and the time as the number of seconds since midnight. This should not
340       be thought of as a real julian day, because it's not. The module is
341       internally consistent, and that's enough.
342
343       This method really only is here for compatibility with previous
344       versions, as the jd method is now thrown over for plain hash
345       references.
346
347       See the file INTERNALS for more information about this internal format.
348

TODO

350       - add gmtime and localtime methods, perhaps?
351       - Fix the INTERNALS file so that it actually reflects reality
352

INTERNALS

354       Please see the file INTERNALS for discussion on the internals.
355

AUTHOR

357       Rich Bowen (DrBacchus) rbowen@rcbowen.com
358
359       And the rest of the Reefknot team. See the source for a full list of
360       patch contributors and version-by-version notes.
361

SEE ALSO

363       datetime@perl.org mailing list
364
365       http://reefknot.org/
366
367       http://dates.rcbowen.com/
368
369       Time::Local
370
371       Net::ICal
372
373
374
375perl v5.12.0                      2003-01-18                     Date::ICal(3)
Impressum