RRULE for first Advent - icalendar

I am currently trying to setup my own holiday iCalendar to which I can subscribe on, since I don't want to depend on 3rd party services.
I am currently trying to make the the VEVENTs for Christmas. The 2nd, 3rd and 4th advent, as well as the Christmas holidays are straight forward, however I have big issues to model the 1st advent.
Specifically, the problem is that the first advent can be in November and December (27th November to 3rd Devember)
How can I make a recurring event (or, more specifically, the RRULE) to cover all cases for the 1st advent?
What I've tried
My first idea was this:
FREQ=YEARLY;INTERVAL=1;BYMONTH=11,12;BYMONTHDAY=27,28,29,30,1,2,3;BYDAY=SU
The idea was to just pick the one Sunday in between 27th November and 3rd December. This does of course not work because BYMONTH expands the search to all days in November and December, and BYMONTHDAY limits the search to those days in both months. I.e. November 1st, November 2nd, ... December 27th, December 28th, ..., which is of course not what I want.
Next, I tried to use BYYEARDAY=331,332,333,334,335,336,337 instead of BYMONTHDAY and BYMONTH, but unfortunately my webdav server (Nextcloud, which uses Sabre as far as I know. I got an error message "Invalid BYYEARDAY rule") does not support this.
My next idea was to use multiple RRULEs -- at least I did not see any passage in the RFC stating that only one RRULE is allowed at most. So I ended up with:
RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=SU;BYMONTHDAY=27,28,29,30;BYMONTH=11
RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=SU;BYMONTHDAY=1,2,3;BYMONTH=12
Didn't work as well. My last resort was to create two separate VEVENTs, one with the first RRULE above and one with the second RRULE above, but otherwise identical. This worked, but it left me confused.
Is there no better solution? How would you do it?

unfortunately my webdav server (Nextcloud, which uses Sabre as far as I know. I got an error message "Invalid BYYEARDAY rule") does not support this.
Well I think you should raise a bug report, because as far I can tell your solutions are correct and RFC-compliant.
I tried your solutions 2 and 3 with different libs (my own lib php-rrule, and rrule.js) and both options seems to work just fine.
FREQ=YEARLY;BYDAY=SU;BYYEARDAY=331,332,333,334,335,336,337
or combining 2
FREQ=YEARLY;INTERVAL=1;BYDAY=SU;BYMONTHDAY=27,28,29,30;BYMONTH=11
FREQ=YEARLY;INTERVAL=1;BYDAY=SU;BYMONTHDAY=1,2,3;BYMONTH=12
will both produce:
2018-12-02
2019-12-01
2020-11-29
2021-11-28
2022-11-27
2023-12-03
2024-12-01
2025-11-30
2026-11-29
2027-11-28
which according to Google and Wikipedia are the correct dates for the 1st Advent Sunday in the next 10 years.
Side note
at least I did not see any passage in the RFC stating that only one RRULE is allowed at most.
While not strictly forbidden, in RFC 5545 it's literally written everytime RRULE is mentioned:
;
; The following is OPTIONAL,
; but SHOULD NOT occur more than once.
;
rrule
Appendix A even states in the "New restrictions":
2. The "RRULE" property SHOULD NOT occur more than once in a
component.
That being said, multiple RRULE is a great feature, I don't know why they restricted it.

If I'm not mistaken, the first Advent is always the fifth last Sunday in a year. So the following rule should do the trick:
FREQ=YEARLY;BYDAY=-5SU
See the next 10 results: http://recurrence-expansion-service.appspot.com/reaas?dtstart=20181202&rrule=FREQ%3DYEARLY%3BBYDAY%3D-5SU&max_instances=10
Or to put it another way:
FREQ=YEARLY;BYDAY=SU;BYSETPOS=-5

Related

Days between one date till today. Not difference (Spotfire)

I'm trying to find how many days between a date and today.
I'm able to get the correct number of days but it show as negative.
Integer(DateDiff("day",Date(DateTimeNow()),Date([LAST_RECORD_DT])))
I would like the same result but positive number.
Your answer in your comment is good, but this is better in my opinion:
If LAST_RECORD_DT is in the past (which seems to be the case for you):
Integer(DateDiff("day",Date([LAST_RECORD_DT]),Date(DateTimeNow())))
If LAST_RECORD_DT is in the future:
Integer(DateDiff("day",Date(DateTimeNow()),Date([LAST_RECORD_DT])))
If you want it to always be positive, you can use Abs:
Abs(Integer(DateDiff("day",Date([LAST_RECORD_DT]),Date(DateTimeNow()))))

Python dateutil - bug with choosing closest day with BYMONTHDAY

I am using python's dateutil module to parse recurring rules in my calendar. A problem arises with the following rrule:
from dateutil.rrule import rrulestr
def test():
rrule = 'FREQ=MONTHLY;INTERVAL=1;BYMONTHDAY=30;UNTIL=20180331T2359'
dtstart = datetime.datetime(2018, 1, 1, 18, 0)
dates = list(rrulestr(rrule + ';UNTIL=', dtstart = dtstart ))
This results in the following output (missing February):
datetime: 2018-01-30 18:00:00
datetime: 2018-03-30 18:00:00
Is this a bug in dateutil module and how should I fix it? Or am I doing something wrong?
Per my answer on this equivalent question, this is a deliberate feature of the iCalendar RFC that dateutil is implementing, because dateutil implements RFC 2445 and does not support all (or most) of the features of the updated RFC 5545. The relevant section of RFC 2445:
Recurrence rules may generate recurrence instances with an invalid date (e.g., February 30) or nonexistent local time (e.g., 1:30 AM on a day where the local time is moved forward by an hour at 1:00 AM). Such recurrence instances MUST be ignored and MUST NOT be counted as part of the recurrence set.
February is missing because 2018-02-30 is an invalid date (it's actually the example specified in the RFC).
One thing to note is that this pull request implements the functionality you want, but it is (as of this writing) currently blocked waiting for support of SKIP in BYWEEKNO. After that is merged, you will be able to modify your RRULE:
rrule = ('FREQ=MONTHLY;INTERVAL=1;BYMONTHDAY=30;UNTIL=20180331T2359;'+
'SKIP=BACKWARD;RSCALE=GREGORIAN')
Until then, your best option may be to use a BYMONTHDAY=28 and then add a relativedelta(day=30) to the result, e.g.:
from dateutil.rrule import rrule, MONTHLY
from dateutil.relativedelta import relativedelta
def end_of_month(dtstart, until):
rr = rrule(freq=MONTHLY, interval=1, bymonthday=28,
dtstart=dtstart, until=until)
for dt in rr:
yield dt + relativedelta(day=30)
This works because the 28th exists in all months (so the rrule will always generate it) and relativedelta has the "fall backwards at end of month" behavior that you are looking for. To be 100% safe, you can choose bymonthday=1 instead, it is equivalent in this case.

Schema.org type for a study course

I haven't been able to find any Schema.org type that fits a sheet describing the properties of a course from a university.
The HTML (without any semantic markup using Schema.org) would look more or less like this:
<section>
<h2>Fact sheet</h2>
<p><strong>Formal qualifications:</strong> Bachelor’s Degree in Design</p>
<p><strong>Credits</strong>: 240 ECTS</p>
<p><strong>Duration</strong>: 4 academic years or 240 ECTS</p>
<p><strong>School period</strong>: from October to June</p>
<p><strong>Timetable</strong>: Morning Group: from Monday to Friday from 9am to 2.30pm. Evening Group: from Monday to Friday from 3:30 pm to 9.00 pm * The college reserves the right to modify schedules.</p>
<strong>Price</strong>: 112 €/ 1 ECTS
…
</section>
I thought about using Product, but it lacks lots of things.
Any ideas?
As this thread still appears on search engines, perhaps it's better to update that a Course schema was released lately:
http://schema.org/Course
Google is also endorsing it at this moment:
https://developers.google.com/search/docs/data-types/courses (So far I haven't seen rich snippets "live" though).
I have implemented this and I have to admit that it is not exhaustive and there is still work to be done to improve it. I noticed that Coursera.org is using properties that are not released yet, so I believe that more properties will be coming soon.
For your information!
I would look into the Event part of the schema.org:
An event happening at a certain time and location, such as a concert,
lecture, or festival. Ticketing information may be added via the
'offers' property. Repeated events may be structured as separate Event
objects.
http://schema.org/Event
That seems like it should cover something like a course. (lecture)

Joomla-Tree-menu consisting of categories and entries

I'm searching a plugin for displaying a tree-structure. The first level should be the category names and the second one the entries.
e.g.
- Australia 2012
-- Day 1 (arrival)
-- Day 2 (this and that)
- Kanada 2013
-- Day 1 (arrival)
-- Day 2 (departure)
etc.
where "Australia 2012" and "Kanada 2013" are categories and "Day X" are entries.
Is there a plugin or even a native feature for this purpose? I'm using Joomla 3.2.
there are two modules in the joomla core that might fit your purpose, but you most certainly have to override the layout of the module to make it display like you want to:
/modules/mod_articles_category
/modules/mod_articles_categories
To override the layout, look here or here (there are lots of tutorials for this).
regards Jonas

How to get list of occurrence dates from iCalendar RRULE

I have the iCalendar file with RRULE for occurrences. How to get the list of dates on which the event will be occurring as per given start date and RRULE in the iCal file.
In Java, I want to write a method which should take start date and RRULE and return me the list of occurrence dates. Please help with simple solution or directions.
There is a Java library specifically for parsing RRULEs called google-rfc-2445.
The following link contains an example using the library where you supply a start date along with an RRULE and it prints out the dates.
http://google-rfc-2445.googlecode.com/svn/trunk/README.html
I do not have a chance to read README because of 404 - The requested URL /svn/trunk/README.html was not found on this server. If you have an example to show, please share it. I've found another solution lib-recur. lib-recur is shared via maven repository.