I want to get first day of week for specificid ZonedDateTime in NodaTime.
But week starts Saturday in Persian calendar and Monday in Gregorian calendar.
How can I get first day of week based on calendar of ZonedDateTime?
We don't expose that information, because it's not as cut and dried as you expect it to be. Different cultures and contexts use different week rules - for example, while you've stated that the week starts on Monday in the Gregorian calendar, that's context specific. In many contexts Sunday is used as the first day of the week instead.
See the week numbering part of the Wikipedia article on weeks for examples of this.
It sounds like you'll probably want a Dictionary<CalendarSystem, IsoDayOfWeek> or possibly a Dictionary<CalendarSystem, IWeekYearRule> in your application, depending on what you're trying to achieve.
Related
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.
To correctly setup the calendar on my project, I need to know which day is the first of the week in Tanzania.
Seems like Google doesn't know, do you?
I am referring to the main source of internationalization data in IT-world (used for Java, C# etc.):
There is no explicit entry for TZ (= ISO-3166-2 code of Tanzania) in the weekData-section of CLDR-data. In such a case CLDR-data of unicode corporation says that the code "001" should be selected. And the data for "001" are:
Monday as first day of week and 1 as minimal count of first week in year.
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.
I am trying to build a week view of the month with customized cells, so the Calendar class won't work for me.
I am having trouble knowing on which day the month starts. For example, January 1st was a Friday. Also, I need to know how many days a given month has.
Without telling me the exact code, can you tell me the variables or methods I could use for this?
Look at the actual code for the Calendar class here: http://github.com/codenameone/CodenameOne/
Just set java.util.Calendar to the right date then use the get method to get the day of the week.
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.