What is the difference between kCFCalendarUnitWeekday and kCFCalendarUnitDay? - iphone

From the documentation:
kCFCalendarUnitDay
Specifies the day unit.
and
kCFCalendarUnitWeekday
Specifies the weekday unit. The
weekday units are the numbers 1-N
(where for the Gregorian calendar N=7
and 1 is Sunday).
I wanted an alarm to go off from Monday to Friday and I thought that kCFCalendarUnitWeekday was what I needed, until I woke up this Saturday :) Can someone explain what is the difference between these two, as the documentation doesn't seem very helpful to me.

kCFCalendarUnitDay specifies the day of the month, i.e. a number between 1 and 31 in the Gregorian Calendar.
kCFCalendarUnitWeekday specifies the day of the week, i.e. a number between 1 (Sunday) and 7 (Saturday) in the Gregorian Calendar.
until I woke up this Saturday
Can you show us some code?

Related

I'm trying to calculate 3 days from today, but not include weekend or holidays, but

The workday function should work for this. I have a Range called "Holidays". The problem is that workdays doesn't count the weekend days. I need to count the weekend days. BUT, if the 3rd day comes on a weekend or a holiday choose the next non-weekend or non-holiday day. A2 is the Effective Date of the contract, which is the start date. I'm trying to calculate the day on which the Earnest Money is due. See the attached chart as to how it should calculate.
=if(OR(A5="",A5>workday(A2,3,Holidays)),workday(A2,3,Holidays),"") is the formula I have but it works for Effective dates that fall on a Sunday, Monday, Tuesday and Wednesday, but not for Effective dates that fall on a Thursday, Friday, Saturday.
Starting from Today
Use this formula to get the dates starting from today
={ArrayFormula(
VLOOKUP(WEEKDAY(SEQUENCE(7,1,TODAY(),1),2),
{SEQUENCE(7),{"Monday";"Tuesday";"Wednesday";"Thursday";"Friday";"Saturday";"Sunday"}},2)),
BYROW(SEQUENCE(7,1,TODAY(),1),
LAMBDA(d, VLOOKUP(WEEKDAY(IF(IFNA(MATCH(d+3,F2:F13*1,0),"")="",d+3,d+4),2),
{SEQUENCE(7),{"Monday";"Tuesday";"Wednesday";"Thursday";"Friday";"Saturday";"Sunday"}},2)))}
Starting from Monday
={ArrayFormula(
VLOOKUP(WEEKDAY(SEQUENCE(7,1,TODAY()-WEEKDAY(TODAY(),3),1),2),
{SEQUENCE(7),{"Monday";"Tuesday";"Wednesday";"Thursday";"Friday";"Saturday";"Sunday"}},2)),
BYROW(SEQUENCE(7,1,TODAY()-WEEKDAY(TODAY(),3),1),
LAMBDA(d, VLOOKUP(WEEKDAY(IF(IFNA(MATCH(d+3,F2:F13*1,0),"")="",d+3,d+4),2),
{SEQUENCE(7),{"Monday";"Tuesday";"Wednesday";"Thursday";"Friday";"Saturday";"Sunday"}},2)))}
Starting from Monday using Lambda
Starting from the current week monday.
=ArrayFormula(LAMBDA(vl,wd,
{VLOOKUP(WEEKDAY(wd,2),vl,2),
BYROW(wd,LAMBDA(d, VLOOKUP(WEEKDAY(IF(IFNA(MATCH(d+3,F2:F13*1,0),"")="",d+3,d+4),2),vl,2)))})
({SEQUENCE(7),{"Monday";"Tuesday";"Wednesday";"Thursday";"Friday";"Saturday";"Sunday"}},
SEQUENCE(7,1,TODAY()-WEEKDAY(TODAY(),3),1)))
Explanation
You need the Calendar Year 20xx Legal Public Holidays to skip one day if matched the legal holidays date after adding 3 days.
Used formulas help
BYROW - SEQUENCE - TODAY - LAMBDA - VLOOKUP - IF - IFNA - MATCH - ARRAYFORMULA

What day of the week dose the week start with?

Maybe I'm overthinking this. I want to send a local notification every Monday at 9am until some condition is met. I know this can be done by setting the weekday and hour components of a DateComponents. The problem I'm having is the value would I pass to weekday depends on the Calendar the DateComponents is using. Which if I understand correctly depends on the user's settings. For instance if the user's calendar week starts on a Sunday I would pass a 1 to weekday but if the week starts on a Saturday I would pass 2.
My question is how do I account for things like timezone, daylight savings, and week start day?
Weekday units are the number go 1 through 7, where 1 is Sunday, 2 is Monday... And this won't never change.
When user changes setting, only the calendar.firstWeekday will change.
E.g. if the user's calendar week starts on Sunday, firstWeekday = 1 else if start on Monday, firstWeekday = 2

How to calculate the weekend when counting a date range in Google Sheets?

I have the below columns
StartDate EndDate CountDay
01 May 20 05 May 20 ?
As you see, 01 May is Friday, so from 01-05 May if we count all days including weekend it will be 4 days.
What I want is on column "CountDay" it only counts the Workdays, not the weekend.
SO the expected result would be 2.
Anyone know how to do it using a formula in Google Sheets?
Do you consider Fridays as part of the weekend?
If yes, then you could also try the following formula:
=NETWORKDAYS.INTL(A10, B10,"0000111")
If not, please use this formula:
=NETWORKDAYS.INTL(A10, B10)
How the formulas work.
By using the function NETWORKDAYS.INTL we can "adjust" the weekend (non-working weekdays) to our liking.
In this case we account Fridays as our non-working weekdays by using as the 3rd parameter 0000111 instead of the default 0000011 where every 0 represents a working weekday and every 1 a non-working weekday.
(Very useful for people working part-time)
Someone who has part-time work on only Mondays, Wednesdays and Fridays and wants to calculate the working days Friday, 1 May 2020 - Tuesday, 30 June 2020 could adjust the formula to:
=NETWORKDAYS.INTL(A10, B10,"0101011")
As explained on the official Google help page for NETWORKDAYS.INTL
weekend – [ OPTIONAL – 1 by default ] – A number or string representing which days of the week are considered weekends.
String method: Weekends can be specified using seven 0s and 1s, where the first number in the set represents Monday and the last number is for Sunday. A zero means that the day is a work day, a 1 means that the day is a weekend. For example, “0000011” would mean Saturday and Sunday are weekends.
Number method: Instead of using the string method above, a single number can be used. 1 = Saturday/Sunday are weekends, 2 = Sunday/Monday and this pattern repeats until 7 = Friday/Saturday. 11 = Sunday is the only weekend day, 12 = Monday is the only weekend day and this pattern repeats until 17 = Saturday is the only weekend day.
I just found how to do it:
=if(weeknum(A10)<weeknum(B10),B10-A10-2*(weeknum(B10)-weeknum(A10)),B10-A10)
something like that

swift 4 weekday in iso8601

It's 8th of October, 2017, Sunday.
var weekday = Calendar(identifier: .iso8601).component(.weekday, from: Date())
weekday is 1, but should be 7. What's the problem?
First of all: This has nothing to do with Swift. NSCalendar is a part of Cocoa. (And written in Objective-C, by the way.)
In general:
Even in most western countries the "business week" starts with monday (aka 1st day of week), traditionally in hebrew and christian calendar the sunday is the first day of week. (Beside this, for christians it is the day of god. Of course, this is the first day. Can you give god another place?)
Therefore it is quite usual to get 1 or 0 (aka the lowest valid index) for sunday on western calendars.
ISO8601
However, ISO8601 positively defines the monday as the first day of a week. But this has nothing to do with indexing the weekdays, but with calculating with weeks, i. e. for "first week of a year". weekday is a simple index, nothing else.

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