Skip to content

Commit

Permalink
(fix) fixed recurring events with timezones for EAS (fixes #3822)
Browse files Browse the repository at this point in the history
  • Loading branch information
extrafu committed Oct 3, 2016
1 parent 340c110 commit 665367f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 15 deletions.
25 changes: 18 additions & 7 deletions ActiveSync/iCalRecurrenceRule+ActiveSync.m
Expand Up @@ -37,11 +37,25 @@
#import <NGCards/iCalEvent.h>
#import <NGCards/iCalByDayMask.h>

#import <NGCards/iCalDateTime.h>
#import <NGCards/iCalTimeZone.h>

#import "NSCalendarDate+ActiveSync.h"
#import "NSDate+ActiveSync.h"

@implementation iCalRecurrenceRule (ActiveSync)

- (NSCalendarDate *) _adjustedStartDate
{
iCalTimeZone *timeZone;

timeZone = [(iCalDateTime *)[[self parent] firstChildWithTag: @"dtstart"] timeZone];
if (timeZone)
return [timeZone computedDateForDate: [[self parent] startDate]];
else
return [[self parent] startDate];
}

- (NSString *) activeSyncRepresentationInContext: (WOContext *) context
{
NSMutableString *s;
Expand Down Expand Up @@ -90,7 +104,7 @@ - (NSString *) activeSyncRepresentationInContext: (WOContext *) context
{
// No byDayMask, we take the event's start date to compute the DayOfWeek
// 0 == Sunday, 6 == Saturday
v = (1 << [[[self parent] startDate] dayOfWeek]);
v = (1 << [[self _adjustedStartDate] dayOfWeek]);
}

[s appendFormat: @"<Recurrence_DayOfWeek xmlns=\"Calendar:\">%d</Recurrence_DayOfWeek>", v];
Expand Down Expand Up @@ -139,8 +153,7 @@ - (NSString *) activeSyncRepresentationInContext: (WOContext *) context
{
// Simple reccurrence rule of type "Monthly"
type = 2;
[s appendFormat: @"<Recurrence_DayOfMonth xmlns=\"Calendar:\">%d</Recurrence_DayOfMonth>",
(int)[[[self parent] startDate] dayOfMonth]];
[s appendFormat: @"<Recurrence_DayOfMonth xmlns=\"Calendar:\">%d</Recurrence_DayOfMonth>", [[self _adjustedStartDate] dayOfMonth]];
}
}
else if ([self frequency] == iCalRecurrenceFrequenceYearly)
Expand Down Expand Up @@ -178,10 +191,8 @@ - (NSString *) activeSyncRepresentationInContext: (WOContext *) context
else
{
type = 5;
[s appendFormat: @"<Recurrence_DayOfMonth xmlns=\"Calendar:\">%d</Recurrence_DayOfMonth>",
(int)[[[self parent] startDate] dayOfMonth]];
[s appendFormat: @"<Recurrence_MonthOfYear xmlns=\"Calendar:\">%d</Recurrence_MonthOfYear>",
(int)[[[self parent] startDate] monthOfYear]];
[s appendFormat: @"<Recurrence_DayOfMonth xmlns=\"Calendar:\">%d</Recurrence_DayOfMonth>", [[self _adjustedStartDate] dayOfMonth]];
[s appendFormat: @"<Recurrence_MonthOfYear xmlns=\"Calendar:\">%d</Recurrence_MonthOfYear>", [[self _adjustedStartDate] monthOfYear]];

}
}
Expand Down
20 changes: 12 additions & 8 deletions ActiveSync/iCalTimeZone+ActiveSync.m
Expand Up @@ -128,7 +128,7 @@ - (NSString *) activeSyncRepresentationInContext: (WOContext *) context
//uint16_t wStandardYear;
struct SYSTEMTIME stStandardDate;
//uint16_t wDaylightYear;
struct SYSTEMTIME stDaylightDate;
struct SYSTEMTIME stDaylightDate = {0,0,0,0,0,0,0,0};

char standardName[64], daylightName[64];

Expand All @@ -144,13 +144,17 @@ - (NSString *) activeSyncRepresentationInContext: (WOContext *) context

period = [self _mostRecentPeriodWithName: @"DAYLIGHT"];
if (!period)
stStandardDate.wMonth = 0;

lDaylightBias = (uint32_t) -([period secondsOffsetFromGMT] / 60) - lBias;
[period _fillTZDate: &stDaylightDate];
//wStandardYear = stStandardDate.wYear;
//wDaylightYear = stDaylightDate.wYear;

{
stStandardDate.wMonth = 0;
lDaylightBias = 0;
}
else
{
lDaylightBias = (uint32_t) -([period secondsOffsetFromGMT] / 60) - lBias;
[period _fillTZDate: &stDaylightDate];
//wStandardYear = stStandardDate.wYear;
//wDaylightYear = stDaylightDate.wYear;
}

// We build the timezone
[bytes appendBytes: &lBias length: 4];
Expand Down

0 comments on commit 665367f

Please sign in to comment.