From: helge Date: Thu, 21 Feb 2008 21:30:12 +0000 (+0000) Subject: fixed OGo bug #779 (last day was missing in print overviews) X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e8a5b40e1db8900d567e12ae47bf581bd00642c4;p=sope fixed OGo bug #779 (last day was missing in print overviews) git-svn-id: http://svn.opengroupware.org/SOPE/trunk@1606 e4a50df8-12e2-0310-a44c-efbce7f8a7e3 --- diff --git a/sope-appserver/WEExtensions/ChangeLog b/sope-appserver/WEExtensions/ChangeLog index 56763d45..d07c0194 100644 --- a/sope-appserver/WEExtensions/ChangeLog +++ b/sope-appserver/WEExtensions/ChangeLog @@ -1,3 +1,8 @@ +2008-02-21 Helge Hess + + * WEMonthOverview.m: fixed bug, last day of appointments got lost ... + (OGo bug #779) (v4.7.94) + 2007-03-17 Marcus Mueller * *.m: ported all elements to honour the new diff --git a/sope-appserver/WEExtensions/Version b/sope-appserver/WEExtensions/Version index 2e14700b..5df9973c 100644 --- a/sope-appserver/WEExtensions/Version +++ b/sope-appserver/WEExtensions/Version @@ -1,6 +1,6 @@ # version file -SUBMINOR_VERSION:=93 +SUBMINOR_VERSION:=94 # v4.7.93 requires libNGObjWeb v4.7.5 # v4.5.76 requires libNGObjWeb v4.5.176 diff --git a/sope-appserver/WEExtensions/WEMonthOverview.m b/sope-appserver/WEExtensions/WEMonthOverview.m index df5159f9..1ece952c 100644 --- a/sope-appserver/WEExtensions/WEMonthOverview.m +++ b/sope-appserver/WEExtensions/WEMonthOverview.m @@ -1,5 +1,6 @@ /* - Copyright (C) 2000-2005 SKYRIX Software AG + Copyright (C) 2000-2008 SKYRIX Software AG + Copyright (C) 2008 Helge Hess This file is part of SOPE. @@ -49,9 +50,12 @@ WOAssociation *labelColor; WOAssociation *contentColor; - + @private - NSMutableArray *matrix[MatrixSize]; + /* Note: the matrix does NOT start at the 1st of a month! (the first row + * contains dates from the previous month, unless the 1st is Monday) + */ + NSMutableArray *matrix[MatrixSize]; /* 42 mutable arrays (for each day) */ struct { int firstDisplayedDay; // first day to be displayed Sun 0 .. Sat 6 @@ -411,7 +415,7 @@ _takeValuesInCell(WEMonthOverview *self, WORequest *request, tz = [self->timeZone valueInComponent:comp]; monthStart = [NSCalendarDate dateWithYear:y month:m day:1 hour:0 minute:0 - second:0 timeZone:tz]; + second:0 timeZone:tz]; d = [monthStart dateByAddingYears:0 months:0 days:i]; @@ -420,11 +424,11 @@ _takeValuesInCell(WEMonthOverview *self, WORequest *request, d = [monthStart dateByAddingYears:0 months:0 days:i]; } - firstDisplayedDay = (self->firstDay) + firstDisplayedDay = (self->firstDay != nil) ? ([self->firstDay intValueInComponent:comp] % 7) : 1; // Monday - firstIdx = (([monthStart dayOfWeek]-firstDisplayedDay)+7) % 7; + firstIdx = (([monthStart dayOfWeek] - firstDisplayedDay) + 7) % 7; self->matrixInfo.weeks = ceil((float)(firstIdx + i) / 7); self->matrixInfo.firstDisplayedDay = firstDisplayedDay; @@ -432,45 +436,78 @@ _takeValuesInCell(WEMonthOverview *self, WORequest *request, // keep the timezone in the date self->matrixInfo.start = [[monthStart dateByAddingYears:0 months:0 days:-firstIdx] retain]; + +#if HEAVY_DEBUG + NSLog(@"MONTH START: %@", monthStart); + NSLog(@"MATRIX START: %@", self->matrixInfo.start); +#endif } + + /* + * The 'matrix start' is the day the grid starts. Eg if we are displaying + * Feb 2008, Feb 1st does not start on Monday. The matrix looks like: + * + * Week Mon Tue Wed Thu Fri Sat Sun + * 5 28 29 30 31 1 2 3 [starts in January] + * 6 4 5 6 7 8 9 10 + * 7 11 12 13 14 15 16 17 + * 8 18 19 20 21 22 23 24 + * 9 25 26 27 28 29 1 2 [goes into march] + * + * Hence the matrix start will be 2008-01-28 00:00 [TZ]. + */ for (i = 0, cnt = [array count]; i < cnt; i++) { id app; NSCalendarDate *sd, *ed; - NSTimeInterval diff; + NSTimeInterval diff; // seconds since matrixInfo.start (1. 00:00) int idx, idx2; - - app = [array objectAtIndex:i]; + NSNumber *iNum; + + app = [array objectAtIndex:i]; // appointment sd = [app valueForKey:startKey]; // startDate ed = [app valueForKey:endKey]; // endDate - + if (sd == nil && ed == nil) continue; - + + /* startdate */ diff = [sd timeIntervalSinceDate:self->matrixInfo.start]; + idx = floor(diff / SecondsPerDay); /* eg 0 */ +#if HEAVY_DEBUG + NSLog(@" DTSTART: %i (offset=%.3fs)", idx, diff); +#endif - idx = floor(diff / SecondsPerDay); - - if (0 <= idx && idx < MatrixSize) { + if (idx >= 0 && idx < MatrixSize) { if (self->matrix[idx] == nil) self->matrix[idx] = [[NSMutableArray alloc] initWithCapacity:4]; [self->matrix[idx] addObject:[NSNumber numberWithInt:i]]; } idx = (idx < 0) ? 0 : idx + 1; - + + /* enddate */ diff = [ed timeIntervalSinceDate:self->matrixInfo.start]; idx2 = floor(diff / SecondsPerDay); - idx2 = (idx2 > MatrixSize) ? MatrixSize : idx2; +#if HEAVY_DEBUG + NSLog(@" DTEND: %i (offset=%.3fs)", idx2, diff); +#endif + idx2 = (idx2 > MatrixSize) ? MatrixSize : idx2; /* limit length */ - while (idx < idx2) { + /* Add event to all columns covered. we store the indices! */ + iNum = [[NSNumber alloc] initWithInt:i]; + for (; idx <= idx2; idx++) { /* inclusive! */ +#if HEAVY_DEBUG + NSLog(@" ADD %i TO: %i", i, idx); +#endif if (self->matrix[idx] == nil) self->matrix[idx] = [[NSMutableArray alloc] initWithCapacity:4]; - - [self->matrix[idx] addObject:[NSNumber numberWithInt:i]]; - idx++; + + [self->matrix[idx] addObject:iNum]; } + [iNum release]; iNum = nil; } - + + /* fill up remaining slots with empty arrays */ for (i = 0; i < MatrixSize; i++) { if (self->matrix[i] == nil) self->matrix[i] = [[NSArray alloc] init];