Re: INTERVAL, DTSTART and BYxxx modifiers

Reinhold Kainhofer <[email protected]> Tue, 7 Jun 2005 18:12:23 +0200
Newsgroups gmane.ietf.calendar
Organization FAM, Vienna University of Technology
Message-ID <[email protected]>
--nextPart2532171.HLQYlNQGcM
Content-Type: text/plain;
  charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

On Tuesday 07 June 2005 17:28, Laird Nelson wrote:
> Consider the following arbitrary RRULE, significant mainly for its INTERV=
AL
> rule part:
>
>   DTSTART;TZID=3DUS-Eastern:19970105T083000
>   RRULE:FREQ=3DDAILY;INTERVAL=3D5;BYMONTH=3D1
[...]
> must I first compute the total set of *unmodified* occurrences (e.g. every
> fifth day, period, end of story) and then eliminate all such instances th=
at
> are not "contained" by the BYMONTH modifier? Another way to put this is,=
=20
> sitting here, I'm not sure offhand what day in January 2006 you'll "land
> on" if you iterate over every fifth day, starting from January 1, 1997, so
> I'm not sure offhand which day in January 2006 matches the rule.  Must I
> perform this calculation before applying my BYxxx rule parts?

Yes, exactly.

Actually, there's no need to actually step through all 5-day steps sine Jan=
 5=20
1997. Just calculate the days that have elapsed since Jan 5 1997, and get t=
he=20
next multiple of the frequency. That's the next valid interval on or after=
=20
the date. This works just fine for seconds, minutes, hours, days, weeks,=20
months and years.

E.g. Days from Jan 5, 1997, until June 7, 2005: 3075
So, June 7, 2005, is a valid recurrence interval. Check all BY* parts to se=
e=20
if there are any occurences in this interval. Since there are not, increase=
=20
the date by 5 days.

=46or June 9, you'll have 3077 days since DTSTART, so you'll have to add 3 =
days=20
to get to a multiple of 5. Check all BY* to see if there's a recurrence on=
=20
June 12. If not, add 5 days and start over with checking the BY*. Do this,=
=20
until you have an occurence, or you are outside a date/time range that is o=
f=20
interest (or the loop count exceeds a certain threshold so you can assume t=
he=20
rule is contradictory, but you haven't detected this before).

Of course, you might think of optimizing this by analyzing the BY* parts, a=
nd=20
seeing that only occurences in Jan are allowed, so you can skip all months=
=20
until Jan 1, 2006. This is 3283 days after the DTSTART, so Jan 3, 2006 woul=
d=20
be the next allowed interval. Again, check all BY* parts, etc...=20
But beware of correlations between the BY* parts when trying to optimize=20
things!=20

Reinhold

=2D-=20
=2D-----------------------------------------------------------------
Reinhold Kainhofer, Vienna University of Technology, Austria
email: [email protected], http://reinhold.kainhofer.com/
 * Financial and Actuarial Mathematics, TU Wien, http://www.fam.tuwien.ac.a=
t/
 * K Desktop Environment, http://www.kde.org, KOrganizer / KPilot maintainer

--nextPart2532171.HLQYlNQGcM
Content-Type: application/pgp-signature

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQBCpcdqTqjEwhXvPN0RAnMFAJ45ShVbeFrF55aDsIW/5/dl32qEbACfQQmJ
ub3INZbhRUzlq43crOtUBqw=
=/X1v
-----END PGP SIGNATURE-----

--nextPart2532171.HLQYlNQGcM--