Display relative dates in Calendar module

pull/91/head
Francis Lachapelle 2015-04-29 16:42:10 -04:00
parent 1e3cb57567
commit 9e8d991099
2 changed files with 44 additions and 11 deletions

View File

@ -1,8 +1,6 @@
/* UIxCalListingActions.h - this file is part of SOGo /* UIxCalListingActions.h - this file is part of SOGo
* *
* Copyright (C) 2006-2009 Inverse inc. * Copyright (C) 2006-2015 Inverse inc.
*
* Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
* *
* This file is free software; you can redistribute it and/or modify * This file is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -40,6 +38,7 @@
NSMutableDictionary *componentsData; NSMutableDictionary *componentsData;
NSCalendarDate *startDate; NSCalendarDate *startDate;
NSCalendarDate *endDate; NSCalendarDate *endDate;
NSCalendarDate *now;
NSString *value; NSString *value;
NSString *criteria; NSString *criteria;
NSString *userLogin; NSString *userLogin;

View File

@ -24,8 +24,10 @@
#import <Foundation/NSNull.h> #import <Foundation/NSNull.h>
#import <Foundation/NSString.h> #import <Foundation/NSString.h>
#import <Foundation/NSTimeZone.h> #import <Foundation/NSTimeZone.h>
#import <Foundation/NSUserDefaults.h> /* for locale string constants */
#import <Foundation/NSValue.h> #import <Foundation/NSValue.h>
#import <NGObjWeb/WOApplication.h>
#import <NGObjWeb/WOContext.h> #import <NGObjWeb/WOContext.h>
#import <NGObjWeb/WOContext+SoObjects.h> #import <NGObjWeb/WOContext+SoObjects.h>
#import <NGObjWeb/WORequest.h> #import <NGObjWeb/WORequest.h>
@ -51,6 +53,7 @@
#import <SOGo/NSCalendarDate+SOGo.h> #import <SOGo/NSCalendarDate+SOGo.h>
#import <SOGo/NSArray+Utilities.h> #import <SOGo/NSArray+Utilities.h>
#import <SOGo/NSObject+Utilities.h> #import <SOGo/NSObject+Utilities.h>
#import <SOGo/WOResourceManager+SOGo.h>
#import <Appointments/SOGoAppointmentFolder.h> #import <Appointments/SOGoAppointmentFolder.h>
#import <Appointments/SOGoAppointmentFolders.h> #import <Appointments/SOGoAppointmentFolders.h>
#import <Appointments/SOGoAppointmentObject.h> #import <Appointments/SOGoAppointmentObject.h>
@ -115,6 +118,7 @@ static NSArray *tasksFields = nil;
componentsData = [NSMutableDictionary new]; componentsData = [NSMutableDictionary new];
startDate = nil; startDate = nil;
endDate = nil; endDate = nil;
ASSIGN (now, [NSCalendarDate calendarDate]);
ASSIGN (request, newRequest); ASSIGN (request, newRequest);
user = [[self context] activeUser]; user = [[self context] activeUser];
ASSIGN (dateFormatter, [user dateFormatterInContext: context]); ASSIGN (dateFormatter, [user dateFormatterInContext: context]);
@ -526,17 +530,48 @@ static NSArray *tasksFields = nil;
{ {
NSCalendarDate *date; NSCalendarDate *date;
NSString *formattedDate; NSString *formattedDate;
NSUInteger delta;
date = [NSCalendarDate dateWithTimeIntervalSince1970: seconds]; date = [NSCalendarDate dateWithTimeIntervalSince1970: seconds];
// Adjust for daylight saving time? (wrt to startDate) // Adjust for daylight saving time? (wrt to startDate)
//NSLog(@"***[UIxCalListingActions _formattedDateForSeconds] user timezone is %@", userTimeZone); //NSLog(@"***[UIxCalListingActions _formattedDateForSeconds] user timezone is %@", userTimeZone);
[date setTimeZone: userTimeZone]; [date setTimeZone: userTimeZone];
if (forAllDay)
formattedDate = [dateFormatter formattedDate: date]; if ([now dayOfCommonEra] == [date dayOfCommonEra])
{
// Same day
if (forAllDay)
return [self labelForKey: @"Today"];
else
return [dateFormatter formattedTime: date];
}
else if ([now dayOfCommonEra] - [date dayOfCommonEra] == 1)
{
// Yesterday
return [self labelForKey: @"Yesterday"];
}
else if ([date dayOfCommonEra] - [now dayOfCommonEra] == 1)
{
// Tomorrow
return [self labelForKey: @"Tomorrow"];
}
else if (abs(delta = [date dayOfCommonEra] - [now dayOfCommonEra]) < 7)
{
WOResourceManager *resMgr = [[WOApplication application] resourceManager];
NSString *language = [[[context activeUser] userDefaults] language];
NSDictionary *locale = [resMgr localeForLanguageNamed: language];
NSString *dayOfWeek = [[locale objectForKey: NSWeekDayNameArray] objectAtIndex: [date dayOfWeek]];
if (delta < 7)
// Wihtin the next 7 days
return dayOfWeek;
else
// With the past 7 days
return [NSString stringWithFormat: [self labelForKey: @"last %@"], dayOfWeek];
}
else else
formattedDate = [dateFormatter formattedDateAndTime: date]; {
return [dateFormatter shortFormattedDate: date];
return formattedDate; }
} }
/** /**
@ -1288,7 +1323,7 @@ _computeBlocksPosition (NSArray *blocks)
- (NSString *) _getStatusClassForStatusCode: (int) statusCode - (NSString *) _getStatusClassForStatusCode: (int) statusCode
andEndDateStamp: (unsigned int) endDateStamp andEndDateStamp: (unsigned int) endDateStamp
{ {
NSCalendarDate *taskDate, *now; NSCalendarDate *taskDate;
NSString *statusClass; NSString *statusClass;
if (statusCode == 1) if (statusCode == 1)
@ -1297,7 +1332,6 @@ _computeBlocksPosition (NSArray *blocks)
{ {
if (endDateStamp) if (endDateStamp)
{ {
now = [NSCalendarDate calendarDate];
taskDate = [NSCalendarDate dateWithTimeIntervalSince1970: endDateStamp]; taskDate = [NSCalendarDate dateWithTimeIntervalSince1970: endDateStamp];
[taskDate setTimeZone: userTimeZone]; [taskDate setTimeZone: userTimeZone];
if ([taskDate earlierDate: now] == taskDate) if ([taskDate earlierDate: now] == taskDate)