ISO 8601 Repeating Interval
Asked Answered
M

3

18

Wikipedia gives an example of an ISO 8601 example of a repeating interval:

R5/2008-03-01T13:00:00Z/P1Y2M10DT2H30M

This is what this means:

  • R5 means that the interval after the slash is repeated 5 times.
  • 2008-03-01T13:00:00Z means that the interval begins at this given datetime.
  • P1Y2M10DT2H30M means that the interval lasts for
    • 1 year
    • 2 months
    • 10 days
    • 2 hours
    • 30 minutes

My problem is that I do not know exactly what is being repeated here. Does the repetition occur immediately after the interval ends? Can I specify that every Monday something happens from 13:00 to 14:00?

Milker answered 7/9, 2011 at 19:23 Comment(3)
For "intervals" without a specific start or end date, I've created a format based on ISO 8601. It is used in these JavaScript and PHP libraries. "every Monday at 13:00:00" in your example is written as "F1D/WT13H0M0S". The 1h interval (duration) can be stored independently.Doreathadoreen
@Doreathadoreen Do you have a document that outlines your extensions? If so, I would really like to read it, if not, let's make one!Milker
I've been reading into RFC 5545's RRULE (of iCalendar) based on Mu Mind's answer. My format depends on external filter functions for more advanced operations (e.g. F(odd)W/ET10H0M0S for every day at 10:00:00 in odd weeks). RRULE allows you to specify everything inline but it's not readable by humans (without knowledge of the rfc). In my use-cases it's a trade-off I'm willing to make. So I'll rewrite both libraries using this existing standard.Doreathadoreen
P
10

The standard itself doesn't clarify, but the only obvious interpretation here is that the interval repeats back-to-back. So this recurring interval:

R2/2008-03-01T13:00:00Z/P1Y2M10DT2H30M

Will be equivalent to these non-recurring intervals:

2008-03-01T13:00:00Z/P1Y2M10DT2H30M
2009-05-01T15:30:00Z/P1Y2M10DT2H30M

(Note: my reading is that the number of repetitions does include the first occurrence)

There is no way to represent "every Monday from 13:00 to 14:00" inside of ISO 8601, but it's natural to do for a VEVENT in the iCalendar format. (If you could do that entirely within ISO 8601, then that would give rise to a slew of further feature requests)

Pyrochemical answered 17/9, 2011 at 16:46 Comment(4)
And how would you interpret "R2/P1M/2008-03-01T13:00:00Z" (duration and end date)? Do you think it is the same as "R2/2008-02-01T13:00:00Z/P1M" ?Euchromosome
Nope. It would mean that the repeating ends on that date, but goes on for infinity into the past.Gratitude
Since the number of [n] is specified, I interpret it to mean it doesn't go back infinitely in time.Selectman
Representing "every Monday from 13:00 to 14:00" is possible since ISO 8601-2-2019 with Selections used in Recurring time intervals with repeat rules (Chapter 13).Enravish
N
2

Yes, ISO8601 does define a regular repeating interval (or as regular as a "month" can be as one of the units).

R5/2008-03-01T13:00:00Z/P1Y2M10DT2H30M

Should generate these times:

2009-05-11T15:30:00Z
2010-07-21T18:00:00Z
2011-10-01T20:30:00Z
2012-12-11T23:00:00Z
2014-02-22T00:30:00Z

It doesn't define a "start time" and "end time" like RFC5545 (iCalendar) does, or even irregular repetition like RRULE or crontab can.

You should be able to specify a weekly repetition using the ISO Week Date as a starting point, but you'll need separate repetitions for "start" and "end" times:

R/2021-W01-1T13:00:00Z/P1W
R/2021-W01-1T14:00:00Z/P1W

The first interval is for the start times: Mondays at 13:00 (starting in 2021), and the second is for the end times: Mondays at 14:00 (starting in 2021).

Nitroglycerin answered 7/4, 2021 at 20:9 Comment(0)
Z
1

I'm probably being an idiot (Long Covid Brain) but isn't the obvious extension to ISO-8601 a second duration part? In the absence of the second duration, the repeats are back to back, in its presence what is actually repeating is a smaller duration event at the start of each period. e.g.

R/2021-W01-1T13:00:00Z/P1W/P1H

  • indefinite weekly repeat of hour long slots every Monday 1pm starting week 1 2021.

EDIT: Maybe you could even nest them ...

R/2021-W01-1T09:00:00Z/P1W/R5/P1D/P8H

  • Mon to Fri, 9am to 5pm, every week? Ok I'll get my coat
Zildjian answered 20/2, 2022 at 12:17 Comment(1)
This is absolutely the correct answer. The interval that's part of the repetition specifies time between the starts of repetitions. Just use a second duration or interval, separate from the repetition, if you need to specify how long each repetition is. It's outside the scope of ISO8601 exactly how you combine two or more of the things ISO8601 defines into one string, because the right way to do that depends on what you're doing and where you're using it. Just use something that's unambiguous and easy to parse.Offwhite

© 2022 - 2024 — McMap. All rights reserved.