Move [iCalEntityObject+SOGo dateFromString:]

.. to CardElement+SOGo so it's also accessible from a NGVCard.
pull/206/head
Francis Lachapelle 2016-04-05 21:57:09 -04:00
parent 66c429740f
commit af4aae2019
4 changed files with 47 additions and 35 deletions

View File

@ -56,8 +56,6 @@ extern NSNumber *iCalDistantFutureNumber;
- (int) priorityNumber;
- (NSDictionary *) createdBy;
- (NSCalendarDate *) dateFromString: (NSString *) dateString
inContext: (WOContext *) context;
- (void) adjustDate: (NSCalendarDate **) date
withTimeString: (NSString *) timeString
inContext: (WOContext *) context;

View File

@ -173,36 +173,6 @@ NSNumber *iCalDistantFutureNumber = nil;
return data;
}
// From [UIxDatePicker takeValuesFromRequest:inContext:]
- (NSCalendarDate *) dateFromString: (NSString *) dateString
inContext: (WOContext *) context
{
NSInteger dateTZOffset, userTZOffset;
NSTimeZone *systemTZ, *userTZ;
SOGoUserDefaults *ud;
NSCalendarDate *date;
date = [NSCalendarDate dateWithString: dateString
calendarFormat: @"%Y-%m-%d"];
if (!date)
[self warnWithFormat: @"Could not parse dateString: '%@'", dateString];
// We must adjust the date timezone because "dateWithString:..." uses the
// system timezone, which can be different from the user's. */
ud = [[context activeUser] userDefaults];
systemTZ = [date timeZone];
dateTZOffset = [systemTZ secondsFromGMTForDate: date];
userTZ = [ud timeZone];
userTZOffset = [userTZ secondsFromGMTForDate: date];
if (dateTZOffset != userTZOffset)
date = [date dateByAddingYears: 0 months: 0 days: 0
hours: 0 minutes: 0
seconds: (dateTZOffset - userTZOffset)];
[date setTimeZone: userTZ];
return date;
}
// From [UIxTimeDatePicker takeValuesFromRequest:inContext:]
- (void) adjustDate: (NSCalendarDate **) date
withTimeString: (NSString *) timeString

View File

@ -1,6 +1,6 @@
/* CardElement+SOGo.h - this file is part of SOGo
*
* Copyright (C) 2014 Inverse inc.
* Copyright (C) 2014-2016 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
@ -23,8 +23,13 @@
#import <NGCards/CardElement.h>
@class NSCalendarDate;
@class WOContext;
@interface CardElement (SOGoExtensions)
- (NSCalendarDate *) dateFromString: (NSString *) dateString
inContext: (WOContext *) context;
- (NSString *) jsonRepresentation;
@end

View File

@ -1,6 +1,6 @@
/* CardElement+SOGo.m - this file is part of SOGo
*
* Copyright (C) 2014 Inverse inc.
* Copyright (C) 2014-2016 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
@ -18,15 +18,54 @@
* Boston, MA 02111-1307, USA.
*/
#import <Foundation/NSCalendarDate.h>
#import <Foundation/NSString.h>
#import <Foundation/NSTimeZone.h>
#import <Foundation/NSValue.h>
#import <NGExtensions/NSObject+Logs.h>
#import <NGObjWeb/WOContext+SoObjects.h>
#import "SOGoUser.h"
#import "SOGoUserDefaults.h"
#import "NSDictionary+Utilities.h"
#import "CardElement+SOGo.h"
@implementation CardElement (SOGoExtensions)
/**
* From [UIxDatePicker takeValuesFromRequest:inContext:]
*/
- (NSCalendarDate *) dateFromString: (NSString *) dateString
inContext: (WOContext *) context
{
NSInteger dateTZOffset, userTZOffset;
NSTimeZone *systemTZ, *userTZ;
SOGoUserDefaults *ud;
NSCalendarDate *date;
date = [NSCalendarDate dateWithString: dateString
calendarFormat: @"%Y-%m-%d"];
if (!date)
[self warnWithFormat: @"Could not parse dateString: '%@'", dateString];
// We must adjust the date timezone because "dateWithString:..." uses the
// system timezone, which can be different from the user's. */
ud = [[context activeUser] userDefaults];
systemTZ = [date timeZone];
dateTZOffset = [systemTZ secondsFromGMTForDate: date];
userTZ = [ud timeZone];
userTZOffset = [userTZ secondsFromGMTForDate: date];
if (dateTZOffset != userTZOffset)
date = [date dateByAddingYears: 0 months: 0 days: 0
hours: 0 minutes: 0
seconds: (dateTZOffset - userTZOffset)];
[date setTimeZone: userTZ];
return date;
}
/**
* Return the JSON representation of the element as a dictionary with two keys:
* - type: the type of the card element, if it exists;