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
Related
I need a Pipeline to trigger on the Monthend week (Tues, Wed, Thurs and Friday) of a month.
Monthend is defined as,
"Last but one" Friday Or
Second Friday from the end of the month.
For Example, For month of June 2021, 18th is the Monthend (Orange color as shown in the image)
Calendar Image
If its just on Monthend i.e. Second Friday from the end of calendar month, its easy. Just use Occurrance as -2 and day as Friday in the Scheduled trigger and add to a pipeline to trigger,
"schedule": {
"monthlyOccurrences": [
{
"day": "Friday",
"occurrence": -2
}
]
}
but I also need to run on the Tues, Wed and Thurs of the same week, which I find it difficult as these weekdays can be second or third from the end of the calendar month. For example: For June 2021, as shown in the image, I also need to run on 15th (Third Tuesday from the end of calendar month), 16th (Third Wednesday from the end of calendar month), 17th (Second Thursday from the end of calendar month).
Can you let me know if this can be implemented using triggers of Azure data factory? If not, any otherways of implementing? Thank You!
The scheduled trigger alone is not capable of that logic (as of 2021-05-04). Easiest solution would be to use some other scheduling application.
For a purely Data-Factory solution, schedule the trigger for all the days the desired days could possibly occur on. Then modify the pipeline to do logic to determine whether the current day is actually one of the desired days.
Implementation details and sample code
The logic:
Find the last day of the month (First of the next month less 1 day).
Subtract a week so you are in the second-to-last week
Loop over [0,-1,-2,-3,-4,-5,-6] as number of days to add to the date. This produces the dates of each day of the week.
Use the dayOfWeek function to change the date into which day of the week it is
Filter to get the Friday date
Ask whether today is between the Friday date and Friday date - 3 days
I am trying to create an Analytics report and I want to set the date range from Monday to Sunday.
I am setting the Start date to: =today()-7 and the End day to =today()-1, but this shows the last 7 days everytime I run the report (say I run it on wednesday, it will show data from wednesday to tuesday).
How can I set the date range so it shows it from last Monday to Sunday?
Short answer
Use WEEKDAY
Explanation
WEEKDAY returns the day of the week.
To get the Monday's date, use this value to subtract it from today's date.
To get the Sunday's date, add 6 to the monday date.
Example
Today =today() 11/14/2016
Weekday =WEEKDAY(B1,3) 0
Start =B1-B2 11/14/2016
End =B3+6 11/20/2016
I'm working with Swift 2.1 to build an app that sets repeated reminders. This consists mainly of two parts:
The user can select a time at which reminders must begin (e.g. 09:00)
The user can choose to have it repeat every X hours (e.g. if it's six hours, then the reminders would be set at 09:00, 15:00, 21:00, 03:00)
I'm using CVCalendarKit to manipulate certain date units, so part 2 (adding X hours every time) isn't the trouble I'm having.
What I'm trying to figure out is if there's an easy way to create an instance of NSDate with the soonest instance of a certain time.
So, assuming today is 13th of February 2016,
If it's 8:59, the NSDate created should be 2016-02-13 09:00:00
If it's 9:01, the NSDate created should be 2016-02-14 09:00:00
Many thanks in advance.
You can use NSCalendar.nextDateAfterDate()
let calendar = NSCalendar.currentCalendar()
let now = NSDate()
let nextTime = calendar.nextDateAfterDate(now,
matchingHour: 9,
minute: 0,
second: 0,
options: NSCalendarOptions.MatchNextTime)
If you aren't using the open source Swift Foundation libraries, this only works on iOS 8+ or OS X 10.9+
Watch out for changes in daylight savings time.
Quite soon there will a day where one hour is missing. In that case you (or your user) must make two decisions: 1. What happens if the date you are interested in doesn't exist? (For example, there will be one day in the year in the UK where "2:30 am on the next day" doesn't exist). 2. What do you mean by "every six hours"? On one day of the year, "6 hours after 21:00" is "04:00" on the next day.
I have a query where I need, as date criteria, the week ending two months prior.
So for example if I ran the query on Monday (as of right now, the last Monday was 2/1/2016), it would look at 11/29/2015 through 12/5/2015 inclusive (Sunday through Saturday).
And then next week if I ran it, it would focus on 12/6/2015 through 12/12/2015 (Sunday through Saturday).
However I need it to return this exact same date range no matter which weekday of the week I run it. So for example the date range 11/29/2015 through 12/5/2015 would be selected if I ran it on 2/1/2016 through 2/5/2016 (Mon-Fri).
I'm not sure what the best way is to go about this. I've considered somehow trying to find the next Saturday and then clocking that back a few weeks, but there doesn't seem to be a week option in dateadd().
To get the first weekday of a week from Sunday to Saturday:
FirstWeekDate = DateAdd("d", 1 - Weekday(Date()), Date())
To go back, say 8 weeks:
EightWeeksBack = DateAdd("ww", -8, FirstWeekDate)
Then you can just add/subtrack days to get your intervals, for example.
EightWeeksBackLast = DateAdd("d", 6, DateAdd("ww", -8, FirstWeekDate))
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?