Trigger notification weekly Swift 3

You can set your trigger to repeat every monday at 1:05am as follow: import UserNotifications let trigger = UNCalendarNotificationTrigger(dateMatching: DateComponents(hour: 1, minute: 5, weekday: 2), repeats: true) print(trigger.nextTriggerDate() ?? “nil”) let content = UNMutableNotificationContent() content.title = “title” content.body = “body” // make sure you give each request a unique identifier. (nextTriggerDate description) let request = … Read more

NSCalendar first day of week

Edit: This does not check the edge case where the beginning of the week starts in the prior month. Some updated code to cover this: https://stackoverflow.com/a/14688780/308315 In case anyone is still paying attention to this, you need to use ordinalityOfUnit:inUnit:forDate: and set firstWeekday to 2. (1 == Sunday and 7 == Saturday) Here’s the code: … Read more

How to split Fromdate and Todate based on weekdays(Sat,Sun) using linq c#

This should work: DateTime tempStart = StartDate; var list = new List<Splitdate>(); for (DateTime date = StartDate; date.Date <= EndDate.Date; date = date.AddDays(1)) { if (day.DayOfWeek == DayOfWeek.Saturday) { var temp = new Splitdate(); temp.Fromdate = tempStart; temp.Todate = date.AddDays(-1); list.Add(temp); tempStart.AddDays(2); } } if (tempStart <= EndDate) { var temp = new Splitdate(); temp.Fromdate … Read more