iCal Recurring monthly event on the closest weekday possible? [closed] - calendar

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 2 years ago.
Improve this question
I would like to create a recurring event on the 24th of every month and if the day falls on a weekend, schedule it for the closest weekday. If the day falls on a Saturday, I would like to schedule it for the previous weekday (Friday). If the day falls on a Sunday, I would like to schedule it for the next weekday (Monday). Is this something that is possible to do with iCal RRULE?
I have already seen a similar question, but that was for always the next weekday.

I was able to create a recurring event based on your requirements using this combined iCAL RRULE
RRULE:FREQ=MONTHLY;BYDAY=MO,TU,WE,TH,FR;BYMONTHDAY=23,24;BYSETPOS=-1
RRULE:FREQ=MONTHLY;BYDAY=MO,TU,WE,TH,FR;BYMONTHDAY=24,25;BYSETPOS=1
RRULE:FREQ=MONTHLY;BYDAY=MO,TU,WE,TH,FR;BYMONTHDAY=23,24;BYSETPOS=-1
By setting BYSETPOS to -1, this rule will choose the last occurrence within the set occurrences that matched the rule.
If both 23 and 24 falls on weekdays, it will choose the last occurrence which is the 24th day
If 24 falls on a Saturday, only one occurrence will be matched based on the rule, Hence it will choose the 23rd day on Friday
If both 23 and 24 fall on weekends, no event will be created. This is why another rule is needed to resolve this issue.
RRULE:FREQ=MONTHLY;BYDAY=MO,TU,WE,TH,FR;BYMONTHDAY=24,25;BYSETPOS=1
By setting BYSETPOS to 1, this rule will choose the first occurrence within the set occurrences that matched the rule.
If both 24 and 25 falls on weekdays, it will choose the first occurrence which is the 24th day
If 24 falls on a Sunday, only one occurrence will be matched based on the rule, Hence it will choose the 25th day on Monday
If both 24 and 25 fall on weekends, no event will be created based on this rule.

Related

RRule Repeating monthly calendar event on weekday only

I have an recurring event on the 7th of each month but am struggling to find an RRule that I can put into a text editor and import into google calendar. I need the rule to put the event on the last week day if the 7th falls on a weekend. Thanks in advance.
Due to the fallback condition, I don't think you can achieve this only defining a RRULE, unfortunately.
RRULE in Google Calendar follows RFC 5545 specification.
With RFC 5545, regarding monthly recurrences, you can either set the recurring rule for a specific day of the month (e.g. always on the 7th of the month would be RRULE:FREQ=MONTHLY;BYMONTHDAY=7) or a specific offset of day of the week within a month (e.g. second to last weekday of the month would be RRULE:FREQ=MONTHLY;BYDAY=MO,TU,WE,TH,FR;BYSETPOS=-2).
Only using this specification, I don't believe there is a way to select the previous (or next) weekday in reference to the 7th day of the month.
However you can always achieve this by using a script to generate the dates or interpret an existing list you already have before insert them on Google Calendar.

Event every 5th day of mont (or 4th/3rd if it's weekend or holiday) using iCal

In Brazil my payday happen on every 5th day of month.
But if the 5th day is a saturday/sunday, then the payment will happen on the 4th day.
Same if 4th is saturday/sunday: then the payment will happen on 3rd day. And so on.
Is there any way to create a event that will work with Google Calendar and iCal?
You can achieve that with iCalendar, at least as far as it concerns weekends.
Consider the following rule:
DTSTART;TZID=US-Eastern:20160505T000000
RRULE:FREQ=MONTHLY;BYMONTHDAY=1,2,3,4,5;BYDAY=MO,TU,WE,TH,FR;BYSETPOS=-1
The rule is evaluated as follows:
FREQ=MONTHLY;BYMONTHDAY=1,2,3,4,5: expand to the 1st, 2nd, 3rd, 4th and 5th day of each month
BYDAY=MO,TU,WE,TH,FR: filter by week day, retain only work days/remove weekend days
BYSETPOS=-1: retain only the last day of the set
You can verify the result at http://recurrence-expansion-service.appspot.com/
Here are the first 100 instances.
It's not possible to achieve that for holidays though.
Update:
It's actually sufficient to specify
RRULE:FREQ=MONTHLY;BYMONTHDAY=3,4,5;BYDAY=MO,TU,WE,TH,FR;BYSETPOS=-1
Since the weekend is at most 2 days long, payday must fall on one of the 3rd, 4th or 5th day of the month. Again, this does not take holidays into account.
Holidays always need special consideration. Not only does RRULE not support this kind of logic for arbitrary days, sometimes it's difficult or even impossible to express holidays by an RRULE themselves. In some countries certain holidays are always on a specific day, except when the days falls on a weekend, in which case the holiday is on the Friday before or the Monday after the weekend. Or consider the Easter date and holidays relative to the Easter date, they can't be expressed by an RRULE at all.
Not to forget that some holidays may change every now and then (like "King's days" or "Queen's days" in certain countries).
The best you can do is to manage these manually and add an RDATE and an EXDATE if payday would fall on a holiday according to the RRULE above.

Representation of repetitive dates in SQL database

In my program I must manage some holidays. Each holiday can be an exact date, or a repetitive date.
For example:
-6th January of each years
-first day of each month of each year
How would you I save this information on db?
I can't use Datetime because with datetime I can't represent the particular cases like in the above example.
Any suggestion?
If it may concern, I am using TSQL
Sorry for my poor english.
The simple approach, without knowing more about your usage of these data, will be to have three numeric fields day, month, year and interpret them this way: If all three are filled, it's exactly that day and no other day. If year isn't filled, it's the day and month, repeating every year. If only the day is filled, it's the day, repeating every month.
If you have more intricate repetition schemes, you'll need an attribute for the repetition rule, like "every three months".
Of course, every query will need to contain some logic to interpret this scheme, but that's inevitable, unless you decide to have a list of all holidays, say the next 50 years.
I would suggest a 3 column design to store this conditions
Column to Specify whether this is a Day or WeekDay
Column to Specify Day/WeekDay Number (ie 1 to 30/31 for Day, 1 to 7 for WeekDay)
Column to Specify Monthly/Yearly occurrence.(means every month/year)
Eg:- For first day of each month,Something like this : DAY,1,MONTHLY
For Second Saturday of every month : WEEKDAY,14*,MONTHLY (*My Week start is Sunday)
This is not a perfect solution, you may have to add some more column to meet your business logic completely.

How to create a calendar event that repeats weekly for three months every year?

I want to be reminded about something every week every winter. Is that possible to achieve using the ical-/webcal-standard and Google Calender, Apple Calendar/iCal, Android Calender or similar?
(I searched quite extensively for which subdomain this questioned belonged to but the results were inconclusive, with a slight predominance for SO)
It's definitely possible with RFC 5545 recurrence rules.
You can create a WEEKLY RRULE that recurs in specific months only, like so:
FREQ=WEEKLY;BYDAY=MO;BYMONTH=1,2,12
The occurrences of this rule are all Mondays in January, February and December.
Check out the first 100 instances of such an event at http://recurrence-expansion-service.appspot.com/reaas?dtstart=20160104&rrule=FREQ%3DWEEKLY%3BBYDAY%3DMO%3BBYMONTH%3D1%2C2%2C12&skip=&max_instances=100&expansion_window_end=21000104&rfc2445=1
Changing the rule to DAILY would yield the same results, but might be more compatible with actual implementations.
However, I think most calendar UIs don't provide this level of control over recurrence rules.
update:
To create an all day event starting on Dec 15 2015 and recur on the same day of week use:
DTSTART;VALUE=DATE:20151215
RRULE:FREQ=WEEKLY;BYMONTH=1,2,12
The rule doesn't include March itself. To include March just append ,3 to the rule.

Can iCal schedule an event for the first weekday after BYMONTHDAY if BYMONTHDAY is a weekend?

If I have a recurring event on a given day of the month (i.e. the 15th) and that day falls on a Saturday or a Sunday, is it possible for iCal to instead schedule the event to occur on the next available week day?
you cannot set exception but you can use a combination of byday and bymonthday:
something like will give you the monday after a week-end which had either on saturday or sunday a 15th.
RRULE:FREQ=MONTHLY;BYDAY=MO;BYMONTHDAY=16,17
By combining with another event:
RRULE:FREQ=MONTHLY;BYDAY=MO,TU,WE,TH,FR;BYMONTHDAY=15
you'll be there
Using the BYSETPOS=1 rule part, you can accomplish this in a single event:
RRULE:FREQ=MONTHLY;BYDAY=MO,TU,WE,TH,FR;BYMONTHDAY=15,16,17;BYSETPOS=1
This tells iCal to repeat the event monthly; to repeat it only Monday-Friday; to repeat it only on the 15th-17th; and to repeat it only on the first day (per month) that matches the previous rule parts.
BYSETPOS just tells iCal to choose the Nth occurrence of the set of occurrences matched by the other rule parts. It can be set to a comma separated list of values from 1 to 366 or -366 to -1.
For example, modifying the above rule to have BYMONTHDAY=15,16,17,29,29,30,31 and BYSETPOS=1,-1 will cause the event to repeat on the first weekday on or after the 15th, and the last weekday in the month.
Source: RFC 2445

Resources