Commit 6137bc0b by Sebastián Katzer

Scheduling notifications with repeat is triggered at wrong date [fixes #1493]

parent 108905cc
...@@ -25,6 +25,9 @@ ...@@ -25,6 +25,9 @@
@import CoreLocation; @import CoreLocation;
@import UserNotifications; @import UserNotifications;
// Maps these crap where Sunday is the 1st day of the week
static NSInteger WEEKDAYS[8] = { 0, 2, 3, 4, 5, 6, 7, 1 };
@interface APPNotificationOptions () @interface APPNotificationOptions ()
// The dictionary which contains all notification properties // The dictionary which contains all notification properties
...@@ -421,9 +424,7 @@ ...@@ -421,9 +424,7 @@
*/ */
- (UNCalendarNotificationTrigger*) triggerWithDateMatchingComponents:(BOOL)repeats - (UNCalendarNotificationTrigger*) triggerWithDateMatchingComponents:(BOOL)repeats
{ {
NSCalendar* cal = [[NSCalendar alloc] NSCalendar* cal = [self calendarWithMondayAsFirstDay];
initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
NSDateComponents *date = [cal components:[self repeatInterval] NSDateComponents *date = [cal components:[self repeatInterval]
fromDate:[self triggerDate]]; fromDate:[self triggerDate]];
...@@ -440,9 +441,7 @@ ...@@ -440,9 +441,7 @@
*/ */
- (UNCalendarNotificationTrigger*) triggerWithCustomDateMatchingComponents - (UNCalendarNotificationTrigger*) triggerWithCustomDateMatchingComponents
{ {
NSCalendar* cal = [[NSCalendar alloc] NSCalendar* cal = [self calendarWithMondayAsFirstDay];
initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
NSDateComponents *date = [self customDateComponents]; NSDateComponents *date = [self customDateComponents];
date.calendar = cal; date.calendar = cal;
...@@ -548,7 +547,7 @@ ...@@ -548,7 +547,7 @@
date.day = value; date.day = value;
} else } else
if ([key isEqualToString:@"weekday"]) { if ([key isEqualToString:@"weekday"]) {
date.weekday = value; date.weekday = WEEKDAYS[value];
} else } else
if ([key isEqualToString:@"weekdayOrdinal"]) { if ([key isEqualToString:@"weekdayOrdinal"]) {
date.weekdayOrdinal = value; date.weekdayOrdinal = value;
...@@ -829,4 +828,20 @@ ...@@ -829,4 +828,20 @@
return 0; return 0;
} }
/**
* Instance if a calendar where the monday is the first day of the week.
*
* @return [ NSCalendar* ]
*/
- (NSCalendar*) calendarWithMondayAsFirstDay
{
NSCalendar* cal = [[NSCalendar alloc]
initWithCalendarIdentifier:NSCalendarIdentifierISO8601];
cal.firstWeekday = 2;
cal.minimumDaysInFirstWeek = 1;
return cal;
}
@end @end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment