From 9e8d991099d2b9e12c594d8d712f6fd0c29b283f Mon Sep 17 00:00:00 2001 From: Francis Lachapelle Date: Wed, 29 Apr 2015 16:42:10 -0400 Subject: [PATCH] Display relative dates in Calendar module --- UI/Scheduler/UIxCalListingActions.h | 5 ++- UI/Scheduler/UIxCalListingActions.m | 50 ++++++++++++++++++++++++----- 2 files changed, 44 insertions(+), 11 deletions(-) diff --git a/UI/Scheduler/UIxCalListingActions.h b/UI/Scheduler/UIxCalListingActions.h index 41c27cecd..f57df5c77 100644 --- a/UI/Scheduler/UIxCalListingActions.h +++ b/UI/Scheduler/UIxCalListingActions.h @@ -1,8 +1,6 @@ /* UIxCalListingActions.h - this file is part of SOGo * - * Copyright (C) 2006-2009 Inverse inc. - * - * Author: Wolfgang Sourdeau + * Copyright (C) 2006-2015 Inverse inc. * * 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 @@ -40,6 +38,7 @@ NSMutableDictionary *componentsData; NSCalendarDate *startDate; NSCalendarDate *endDate; + NSCalendarDate *now; NSString *value; NSString *criteria; NSString *userLogin; diff --git a/UI/Scheduler/UIxCalListingActions.m b/UI/Scheduler/UIxCalListingActions.m index c625dd492..945e4a578 100644 --- a/UI/Scheduler/UIxCalListingActions.m +++ b/UI/Scheduler/UIxCalListingActions.m @@ -24,8 +24,10 @@ #import #import #import +#import /* for locale string constants */ #import +#import #import #import #import @@ -51,6 +53,7 @@ #import #import #import +#import #import #import #import @@ -115,6 +118,7 @@ static NSArray *tasksFields = nil; componentsData = [NSMutableDictionary new]; startDate = nil; endDate = nil; + ASSIGN (now, [NSCalendarDate calendarDate]); ASSIGN (request, newRequest); user = [[self context] activeUser]; ASSIGN (dateFormatter, [user dateFormatterInContext: context]); @@ -526,17 +530,48 @@ static NSArray *tasksFields = nil; { NSCalendarDate *date; NSString *formattedDate; - + NSUInteger delta; + date = [NSCalendarDate dateWithTimeIntervalSince1970: seconds]; // Adjust for daylight saving time? (wrt to startDate) //NSLog(@"***[UIxCalListingActions _formattedDateForSeconds] user timezone is %@", 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 - formattedDate = [dateFormatter formattedDateAndTime: date]; - - return formattedDate; + { + return [dateFormatter shortFormattedDate: date]; + } } /** @@ -1288,7 +1323,7 @@ _computeBlocksPosition (NSArray *blocks) - (NSString *) _getStatusClassForStatusCode: (int) statusCode andEndDateStamp: (unsigned int) endDateStamp { - NSCalendarDate *taskDate, *now; + NSCalendarDate *taskDate; NSString *statusClass; if (statusCode == 1) @@ -1297,7 +1332,6 @@ _computeBlocksPosition (NSArray *blocks) { if (endDateStamp) { - now = [NSCalendarDate calendarDate]; taskDate = [NSCalendarDate dateWithTimeIntervalSince1970: endDateStamp]; [taskDate setTimeZone: userTimeZone]; if ([taskDate earlierDate: now] == taskDate)