Monotone-Parent: f44990050ab038029a3fa83c4918912da401bd4b
Monotone-Revision: 5626a85621c5f1c132d788ea29e164c8fc44cfdf Monotone-Author: wsourdeau@inverse.ca Monotone-Date: 2012-04-23T21:17:54maint-2.0.2
parent
067513959a
commit
b8930b7bd0
|
@ -1,3 +1,10 @@
|
|||
2012-04-23 Wolfgang Sourdeau <wsourdeau@inverse.ca>
|
||||
|
||||
* iCalMonthlyRecurrenceCalculator.m (NGMonthDaySet_clear): make
|
||||
use of memset, which is expected to be faster.
|
||||
(-recurrenceRangesWithinCalendarDateRange:): added handling of
|
||||
"BYSETPOS" for "BYDAY" sets.
|
||||
|
||||
2012-04-20 Wolfgang Sourdeau <wsourdeau@inverse.ca>
|
||||
|
||||
* iCalTrigger.m (-nextAlarmDate): new method including most of
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
02111-1307, USA.
|
||||
*/
|
||||
|
||||
#import <Foundation/NSString.h>
|
||||
#import <NGExtensions/NSCalendarDate+misc.h>
|
||||
|
||||
#import "iCalRecurrenceCalculator.h"
|
||||
|
@ -34,7 +35,6 @@
|
|||
#import "NSCalendarDate+ICal.h"
|
||||
|
||||
#import <string.h>
|
||||
#import <math.h>
|
||||
|
||||
@interface iCalRecurrenceCalculator (PrivateAPI)
|
||||
|
||||
|
@ -49,14 +49,11 @@
|
|||
typedef BOOL NGMonthSet[12];
|
||||
typedef BOOL NGMonthDaySet[32]; // 0 is unused
|
||||
|
||||
static void
|
||||
static inline void
|
||||
NGMonthDaySet_clear (NGMonthDaySet *daySet)
|
||||
|
||||
{
|
||||
register unsigned i;
|
||||
|
||||
for (i = 0; i <= 31; i++)
|
||||
(*daySet)[i] = NO;
|
||||
memset (daySet, 0, sizeof (NGMonthDaySet));
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -201,7 +198,7 @@ static inline unsigned iCalDoWForNSDoW (int dow)
|
|||
YES, YES, YES, YES, YES, YES,
|
||||
YES, YES, YES, YES, YES, YES
|
||||
};
|
||||
NSArray *byMonth, *byMonthDay; // array of ints (-31..-1 and 1..31)
|
||||
NSArray *byMonth, *byMonthDay, *bySetPos; // array of ints (-31..-1 and 1..31)
|
||||
NGMonthDaySet byPositiveMonthDaySet, byNegativeMonthDaySet;
|
||||
iCalByDayMask *byDayMask;
|
||||
|
||||
|
@ -216,6 +213,7 @@ static inline unsigned iCalDoWForNSDoW (int dow)
|
|||
byMonth = [rrule byMonth];
|
||||
byMonthDay = [rrule byMonthDay];
|
||||
byDayMask = [rrule byDayMask];
|
||||
bySetPos = [rrule bySetPos];
|
||||
diff = 0;
|
||||
|
||||
if (![rrule isInfinite])
|
||||
|
@ -239,7 +237,7 @@ static inline unsigned iCalDoWForNSDoW (int dow)
|
|||
if ([until compare: rStart] == NSOrderedAscending)
|
||||
// Range starts after last occurrence
|
||||
return nil;
|
||||
if ([until compare: rEnd] == NSOrderedDescending)
|
||||
if ([until compare: rEnd] == NSOrderedAscending)
|
||||
// Range ends after last occurence; adjust end date
|
||||
rEnd = until;
|
||||
}
|
||||
|
@ -333,6 +331,48 @@ static inline unsigned iCalDoWForNSDoW (int dow)
|
|||
}
|
||||
|
||||
if (byDayMask)
|
||||
{
|
||||
if (!didByFill)
|
||||
NGMonthDaySet_clear (&monthDays);
|
||||
|
||||
if (bySetPos)
|
||||
{
|
||||
NSUInteger monthDay;
|
||||
NSInteger currentPos;
|
||||
iCalWeekDay currentWeekDay;
|
||||
|
||||
currentWeekDay = [[cursor firstDayOfMonth] dayOfWeek];
|
||||
currentPos = 1;
|
||||
for (monthDay = 0; monthDay <= numDaysInMonth; monthDay++)
|
||||
{
|
||||
if ([byDayMask occursOnDay: currentWeekDay])
|
||||
{
|
||||
if ([bySetPos containsObject:
|
||||
[NSString stringWithFormat: @"%d", currentPos]])
|
||||
monthDays[monthDay+1] = YES;
|
||||
currentPos++;
|
||||
}
|
||||
currentWeekDay = (currentWeekDay + 1) % 7;
|
||||
}
|
||||
|
||||
currentWeekDay = [[cursor lastDayOfMonth] dayOfWeek];
|
||||
currentPos = -1;
|
||||
for (monthDay = numDaysInMonth; monthDay > 0; monthDay--)
|
||||
{
|
||||
if ([byDayMask occursOnDay: currentWeekDay])
|
||||
{
|
||||
if ([bySetPos containsObject:
|
||||
[NSString stringWithFormat: @"%d", currentPos]])
|
||||
monthDays[monthDay] = YES;
|
||||
currentPos--;
|
||||
}
|
||||
if (currentWeekDay > 0)
|
||||
currentWeekDay--;
|
||||
else
|
||||
currentWeekDay = 6;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
unsigned int firstDoWInMonth, currentWeekDay;
|
||||
unsigned int weekDaysCount[7], currentWeekDaysCount[7];
|
||||
|
@ -340,17 +380,13 @@ static inline unsigned iCalDoWForNSDoW (int dow)
|
|||
|
||||
firstDoWInMonth = [[cursor firstDayOfMonth] dayOfWeek];
|
||||
|
||||
if (!didByFill)
|
||||
NGMonthDaySet_clear (&monthDays);
|
||||
|
||||
// Fill weekDaysCount to handle negative positions
|
||||
currentWeekDay = firstDoWInMonth;
|
||||
memset(weekDaysCount, 0, 7 * sizeof(unsigned int));
|
||||
for (i = 1; i <= numDaysInMonth; i++)
|
||||
{
|
||||
weekDaysCount[currentWeekDay]++;
|
||||
currentWeekDay++;
|
||||
currentWeekDay = fmod (currentWeekDay, 7);
|
||||
currentWeekDay = (currentWeekDay + 1) % 7;
|
||||
}
|
||||
|
||||
currentWeekDay = firstDoWInMonth;
|
||||
|
@ -367,8 +403,8 @@ static inline unsigned iCalDoWForNSDoW (int dow)
|
|||
withWeekNumber: negativeOrder]));
|
||||
}
|
||||
currentWeekDaysCount[currentWeekDay]++;
|
||||
currentWeekDay++;
|
||||
currentWeekDay = fmod (currentWeekDay, 7);
|
||||
currentWeekDay = (currentWeekDay + 1) % 7;
|
||||
}
|
||||
}
|
||||
didByFill = YES;
|
||||
}
|
||||
|
|
|
@ -92,6 +92,8 @@ extern NSString *iCalWeekDayString[];
|
|||
- (NSArray *) byMonth;
|
||||
- (BOOL) hasByMask;
|
||||
|
||||
- (NSArray *) bySetPos;
|
||||
|
||||
/* count and untilDate are mutually exclusive */
|
||||
|
||||
- (void) setRepeatCount: (int) _repeatCount;
|
||||
|
|
|
@ -183,6 +183,7 @@
|
|||
*/
|
||||
|
||||
#import <Foundation/NSArray.h>
|
||||
#import <Foundation/NSDictionary.h>
|
||||
#import <Foundation/NSEnumerator.h>
|
||||
#import <Foundation/NSException.h>
|
||||
#import <NGExtensions/NSString+Ext.h>
|
||||
|
@ -583,6 +584,19 @@ NSString *iCalWeekDayString[] = { @"SU", @"MO", @"TU", @"WE", @"TH", @"FR",
|
|||
}
|
||||
}
|
||||
|
||||
- (NSArray *) bySetPos
|
||||
{
|
||||
NSArray *lists, *bySetPos;
|
||||
|
||||
lists = [self valuesForKey: @"bysetpos"];
|
||||
if ([lists count] > 0)
|
||||
bySetPos = [lists objectAtIndex: 0];
|
||||
else
|
||||
bySetPos = nil;
|
||||
|
||||
return bySetPos;
|
||||
}
|
||||
|
||||
// - (iCalWeekDay) weekDayForiCalRepre: (NSString *) _weekDay
|
||||
// {
|
||||
// iCalWeekDay day;
|
||||
|
|
|
@ -169,6 +169,23 @@
|
|||
@"19980129T090000Z",
|
||||
@"19980226T090000Z",
|
||||
nil],
|
||||
// Second friday of the month, until Feb 26 1998
|
||||
[NSArray arrayWithObjects: @"19980101T090000Z",
|
||||
@"FREQ=MONTHLY;BYDAY=FR;BYSETPOS=2;UNTIL=19980428T090000Z",
|
||||
@"19980101T090000Z",
|
||||
@"19980109T090000Z",
|
||||
@"19980213T090000Z",
|
||||
@"19980313T090000Z",
|
||||
@"19980410fT090000Z",
|
||||
nil],
|
||||
// Last friday of the month, until Feb 26 1998
|
||||
[NSArray arrayWithObjects: @"19980101T090000Z",
|
||||
@"FREQ=MONTHLY;BYDAY=MO,WE;BYSETPOS=-2;UNTIL=19980331T090000Z",
|
||||
@"19980101T090000Z",
|
||||
@"19980126T090000Z",
|
||||
@"19980223T090000Z",
|
||||
@"19980325T090000Z",
|
||||
nil],
|
||||
nil];
|
||||
|
||||
NSString *dateFormat = @"%a %Y-%m-%d %H:%M";
|
||||
|
|
Loading…
Reference in New Issue