Recurring calendar event on First of the month - icalendar

I have a recurring calendar event on 1st of each month, when 1st falls on Sat/Sun is it possible for iCal to schedule it for last working day Fri?

If I understood you correctly the following RRULE should do the trick:
FREQ=MONTHLY;BYDAY=1MO,1TU,1WE,1TH,1FR,-1FR;BYMONTHDAY=1,-1,-2
See the next 100 instances
It basically does two things:
Iterate the first weekday that falls on the 1st day of the month
Iterate the last Friday of each month that falls on the last or 2nd last day of the month (in which cases the 1st of the next month falls on Saturday or Sunday).
A slightly shorter version that should yield the same results is
FREQ=MONTHLY;BYDAY=1MO,1TU,1WE,1TH,FR;BYMONTHDAY=1,-1,-2
This just iterates every Friday, but only keeps the ones that fall on the first, last and 2nd last day of each month. Though it looks like the recurrence expansion service above disagrees. That's probably a bug.

I'm assuming you mean "the last working day Friday of the previous month", in which case I don't think it possible. It would mean that some months have 2 occurrences when others have 0, which doesn't really work.
You could easily do the first working day of the month (the 1st, or the first Monday):
FREQ=MONTHLY;BYDAY=MO,TU,WE,TH,FR;BYSETPOS=1
Or, you could do always the last working day of the month:
FREQ=MONTHLY;BYDAY=MO,TU,WE,TH,FR;BYSETPOS=-1

Related

RRULE for every other week except last week of month

I need an RRULE for every other Saturday except the last week of the month. I tried to create one with a weekly frequency, but didn't know how to apply an exception for the last week of the month:
RRULE:FREQ=MONTHLY;INTERVAL=1;BYDAY=SA
I also tried creating a rule with a monthly frequency, which allowed me to skip the last week of the month, but I didn't know how to make it every other week:
RRULE:FREQ=MONTHLY;INTERVAL=1;BYDAY=SA;BYSETPOS=-2,-3,-4,-5
I looked through the specification, but I'm not seeing anything that makes this possible.
The secret to the solution here is that BYMONTHDAY can be negative like BYSETPOS. This allows one to exclude the last 7 days of each month even though the number of days in the month varies. Your DTSTART should be on a SATURDAY, so one doesn't really need the BYDAY=SA
This rrule works in google calendar (if DTSTART is on Saturday and generally for any every 2nd week but not the last week rule for any day of week specified by the DTSTART):
RRULE:FREQ=WEEKLY;INTERVAL=2;BYMONTHDAY=-8,-9,-10,-11,-12,-13,-14,-15,-16,-17,-18,-19,-20,-21,-22,-23,-24,-25,-26,-27,-28,-29,-30,-31
See test calendar:
https://calendar.google.com/calendar/u/0?cid=ZXBwdWE4N2RwZm5xODVic3JydDJzaXFsY3NAZ3JvdXAuY2FsZW5kYXIuZ29vZ2xlLmNvbQ
Spec: https://datatracker.ietf.org/doc/html/rfc2445#page-43
and
https://icalevents.com/2447-need-to-know-the-possible-combinations-for-repeating-dates-an-ical-cheatsheet/ for the expansion & contraction (limiting) rules & combinations

iCalendar repeat rule for x days before the 2nd Tuesday in the month

I have a meeting on every 2nd Tuesday of the month.
I need 10 days to prepare that meeting - this means I would need a recurring event "10 days before the 2nd Tuesday of the month"
(added via ical file)
I found iCalendar repeat rule for "the day after the second monday of the month" but I'm not sure how/if this applies to my situation/how to remodel it to fit my needs.
The issue is that since it's 10 days prior it may even be in the previous month in some cases (e.g. if the first day of the month is a Tuesday)
What is the correct command for this?
EDIT: the time is always from 8-10am just so it can be included.

RRULE for the weekend including the first sunday of a month

We have a event every year on the weekend (Fr-Su) that includes the first Sunday of June. How would I create a iCalendar Event that expresses these three days (whole day events)?
Creating a rule for the first Sunday is easy. But for the Saturday and Friday, I did not succeed to create a rule that counts backwards (RFC 5545 says INTERVAL, COUNT must be positive]. Moreover I could not think of a different expression that would start from the Friday - it could be the last Friday of May, but also the first in June.
The RRRULE specification in RFC 5545 is lacking in this regard. The INTERVAL and COUNT values are for the repeating events, not the event itself. I've come across a similar issue when trying to define the USA day "Black Friday", the day after the 4th Thursday in November (Friday after Thanksgiving). The 4th Friday in November could occur the day after the 4th Thursday, or the prior week. There is not a way that I have found to make a RRULE for this situation.
I believe you will need to code the events individually instead of using a recurring rule.
RRULE:FREQ=YEARLY;BYDAY=FR;BYMONTH=5,6;BYSETPOS=2;BYMONTHDAY=-2,-1,1,2,3,4,5,6,7' seems to do the trick.
How can I write an ICS file for the Friday before the first Saturday of the month? led me to the right track: with 'BYMONTHDAY' I can count backwards from the end of the month.
The Friday before the first Sunday of the next month can be the last or the second to last day of the previous month, or up to the 5th day of the month. If I include May and June, I will get a set that includes the day. 'BYSETPOS' allows me to choose the second of the found Fridays. To always have the second in the set being my desired day, I include the 6th and 7th day of the month, which gives me a stable first Friday in May. Possibly matched additional Fridays in June are discarded by 'BYSETPOS' anyway.
Extending this to Saturday is simple, and the first Sunday of June is trivial.
I developed the rule with rrule.js
https://jakubroztocil.github.io/rrule/#/rfc/RRULE:BYDAY=FR;BYMONTH=5,6;BYSETPOS=2;BYMONTHDAY=-2,-1,1,2,3,4,5,6,7

ical RRULE for "second week of January"?

What ical RRULE lets me choose the second (not necessarily full) week of January (for example)?
More specifically, the Sunday that starts the second week of January?
Usually, "1SU" would work, but if the month starts with Sunday itself, it would be "2SU", so I don't see an obvious solution here?
If you want the Sunday that starts the second week in January, you have to say that that Sunday can be any month day except the first (and obviously, only can be below the 8th day of the month).
The way to do this is to specify a RRULE with FREQ=YEARLY;BYMONTH=1 to specify January, BYDAY=SU to specify Sundays, BYMONTHDAY=2,3,4,5,6,7,8 to specify that your Sunday cannot be the 1st of the month and that you are only interested in the one starting the 2nd week of the month.
To summarize:
RRULE:FREQ=YEARLY;BYMONTH=1;BYDAY=SU;BYMONTHDAY=2,3,4,5,6,7,8

Representing repetitive dates

Repetitive Dates:
Billing cycles come in a lot of different formats, for example: "the first of the month", "third Friday of the month", or "first weekday on or after 21st day after the 13th of the month" (thanks visa!). My goal is to be able to represent these different billing cycles in one easily parsed database text field.
You forgot weekend processing. If my bill is due on a Sunday, I want it to show up on Friday. That kind of thing. I think there are three possibilities:
Always before the weekend
Always after the weekend
If it's Saturday, Friday, and if it's Sunday, Monday
Current solution:
YYYY/MM/DD+YY/MM/DD+DOW
all blocks (delimited by +) are optional as well as all parts of each block.
first block denotes the starting date
if blank - denotes today
if missing portion - denotes all... ie "//12" would denote the 12th of the month every month.
negative denotes counting from the end of the period.. ie "//-1" denotes the last day of the month
overruns are carried into the next month ie "//40" would be 40 days after the first of the month
second block denotes the change in date between repetitions
if blank - set date (from first block)
Add present portions - ie "/1/" means every month after the given starting date
third block denotes the day of the week the calculated date should be moved to
available are [m,t,w,r,f,s,d,b] (7 days of the week, "business day")
Calculation:
Calculation start on the date specified in the first block, filling in the missing portions with the date the record is added.
the DOW is then added to get a valid starting date. This is the first date of the event.
the next date is calculated by adding the second block to the last calculated first block and adding the DOW to get the next date.
Examples:
on march 12th, 2008 - "2008/3/12"
the first of the month every month - "//1+/1/"
third Friday of the month every month - "//21+/1/+f"
first weekday on or after 21st day after the 13th of the month - "//34+/1/+b"
every 2 weeks from today - "+//14"
last day of every second month starting with march - "/3/-1+/2/"