How to find a Friday after last Wednesday of month? - icalendar

What iCal RRULE expression should I use to find a Friday after last Wednesday of month? So I need (RRULE:FREQ=MONTHLY;BYDAY=-1WE) + 2 days...

I agree with Evert that this is not possible with a single RRULE.
You can, however, achieve that with a combination of multiple RRULEs.
That way you can split your event into multiple events each one having one of the RRULEs below:
If Wednesday falls on the last or second last day of a month, our Friday will be the 1st or 2nd of the next month
FREQ=MONTHLY;BYMONTHDAY=1,2;BYDAY=1FR
In months with 31 days the earliest date for the last Wednesday is the 25th, so the next Friday will be one of day 27-31:
FREQ=MONTHLY;BYMONTH=1,3,5,7,8,10,12;BYMONTHDAY=27,28,29,30,31;BYDAY=FR
In months with 30 days the earliest date for the last Wednesday is the 24th, so the next Friday will be one of day 26-30:
FREQ=MONTHLY;BYMONTH=4,6,9,11;BYMONTHDAY=26,27,28,29,30;BYDAY=FR
February is a tricky one, because in non-leap years the the Friday we want will be between the 24th and 28th, but in leap years it's between the 25th and 29th. However, within the next 50 years there is only one leap year in which February 24th is a Friday, which is 2040 (check out the result of FREQ=MONTHLY;BYMONTHDAY=24;BYMONTH=2;BYDAY=FR), so the following RRULE will be correct until 2040:
FREQ=MONTHLY;BYMONTH=2;BYMONTHDAY=24,25,26,27,28,29;BYDAY=FR
If you're concerned about the leap years, add an EXDATE like below and you're good for the next 100 years (make these DATE-TIME values if your start date has a time):
EXDATE;VALUE=DATE:20400224,20680224,20960224,21080224
If you know for sure that your clients support multiple RRULEs (which has been deprecated halfheartedly in RFC 5545 but still was perfectly valid in RFC 2445) you could add them into a single event as well, but I wouldn't recommend that.

Related

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.

How can I write an ICS file for the Friday before the first Saturday of the month?

I've seen How can an ICS file be written for a recurring event? but I've got a rather complex recurrence and can't figure out a rule after looking at the syntax of RRULEs.
I want an event that happens on the Friday preceding the first Saturday of each month. This Friday-before-the-first-Saturday may of course be in the previous month. I assume that if I can get this to work, similar (but not identical) events for Friday-before-the-second-Saturday, and -third- and -fourth-, with Friday before 5th Saturdays undefined.
Obviously I'd have RRULE:FREQ=MONTHLY;BYDAY=FR; but if I try to follow some of the examples using BYMONTHDAY I run into trouble: 28 would be a valid Friday-before-a-first-Saturday in February, but in any other month, Friday 28th would be the Friday before a 5th Saturday. Similarly for 29 (in a leap year), 30 and 31.
The goal is to include this in a Google Calendar, which I know supports display of ICS RRULEs it can't edit. So, assuming it's possible, how can I create an RRULE for this event? I've considered a separate event and accompanying rule for each month length. 31: Jan, Mar, May, Jul, Aug, Oct, Dec and 30: Apr, Jun, Sep, Nov are OK, but leap years are still an issue: 28 Feb could be a Friday before a first Saturday or a 5th Saturday (e.g. 2020 so one of my first two cases fails).
You're on the right track with having to use BYDAY=FR, AND since you can do negative BYMONTHDAY, the following should do the trick:
RRULE:FREQ=MONTHLY;BYDAY=FR;BYMONTHDAY=-1,1,2,3,4,5,6

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

What is the first/last week of a month? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
If someone were to say something happens in the first or last week of some month, how would you define that span?
Background
I'm working on a library that needs to handle this kind of thing in an intuitive way, but my intuition doesn't claim one case or the other.
I can make it select different behavior but still need a good default.
For a concrete example I'll just to pick an random month: July 2008
s m t w r f s
--------------------
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
(Note: I'll assume the week starts with Sunday but the question could be asked re Monday as well)
What span is the first week of the month?
June 29 - July 5 -- the week that includes the first
July 6 - 12 -- the first week that is all the way into the month
The second week is just the 7 days following the first right?
What span is the last week of the month?
July 27 - Aug 2 -- ditto but the last day
July 20 - 26 -- ditto but the last week
Non wiki comments welcome
There is no answer because it varies even inside a country.
However, this source seems to think it's defined by the ISO standard as the first week that contains a thursday. However the above source says that the ISO standard does not list a specification for 'first week of the month'
More than 300 chars - sorry!
The ISO 8601 standard defines the first week of the YEAR as:
calendar week number
ordinal number which identifies a calendar week within its calendar year according to the rule that the first
calendar week of a year is that one which includes the first Thursday of that year and that the last calendar
week of a calendar year is the week immediately preceding the first calendar week of the next calendar year
There is nothing in ISO 8601 about the first week of the month because, as has been noted, the definition varies by country (and even by company, for example). Oh, and the standard says that weeks start on Monday.
If you are building a library, you should allow the user to choose how they want to handle it either by having methods that return the first/last full/partial week of the month or by passing an argument that indicates whether you want the full/partial week. Clearly document whichever is the default if you provide methods that don't require the specification.
public Week GetFirstFullWeekOfMonth( DateTime forDate ) { }
public Week GetFirstPartialWeekOfMonth( DateTime forDate ) { }
Or
public Week GetFirstWeekOfMonth( DateTime forDate, bool includePartial ) {}
The first week of the month is the first week that is all the way int the month
July 6 - 12
The first week of the month is the week that includes the first
June 29 - July 5
The last week of the month is the week that includes the last day
July 27 - Aug 2
The last week of the month is the last week that is all the way int the month
July 20 - 26
My definition would be the first week is the week of the first working day in the month,
and likewise the last week is the week of the last working day in the month.
The first week of the month is the first week that owns 4 or more days of the defined week period. (Not really but I thought I'd throw it in as an option)
The first week of the month is week 0 - the week that has the first day of the month.
The last week is the week with the last day of the month
Hence the weeknumber of the last week of july IS THE SAME as the weeknumber of the first week of august
** UNLESS **
the month in question ends on the last day of the last week, in wich case the following month would start on the first day of the new week and have a different weeknumber
:)
There's a fairly obvious option you are missing. The first week of the month is the seven days starting with the first day of the month. Hence, in your example, the first week would be Tuesday, the 1st through Monday, the 7th. This way, the first through 4th weeks would always be fully contained within the month, and only the 5th week would cross over.
Talk to your users and ask them what they think it means when the program says to them "First week of the month" and "Last week of the month".