From b04b66fd797b4333792554dcad9fee135e8da0a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Enrique=20J=2E=20Hern=C3=A1ndez=20Blasco?= Date: Tue, 26 May 2015 21:42:57 +0200 Subject: [PATCH] Use UTC offset to encode NSCalendarDate in BSON Using name abbreviation in Objective-C is discouraged as it stated in the following link: https://developer.apple.com/library/prerelease/ios/documentation/Cocoa/Reference/Foundation/Classes/NSTimeZone_Class/index.html#//apple_ref/occ/clm/NSTimeZone/timeZoneWithAbbreviation: Indeed, the GNUStep library is generating the name abbreviation using the system tzdata information but parsing this data using GNUStep resources making changes like this: http://mm.icann.org/pipermail/tz-announce/2014-August/000023.html Not working until GNUStep reaches these tzdata changes. Using the UTC offset we are losing the position in planet Earth but it could be considered valid looking at other bson implementations. --- SoObjects/SOGo/BSONCodec.m | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/SoObjects/SOGo/BSONCodec.m b/SoObjects/SOGo/BSONCodec.m index 99eee87c4..ce4c01e24 100644 --- a/SoObjects/SOGo/BSONCodec.m +++ b/SoObjects/SOGo/BSONCodec.m @@ -1,10 +1,12 @@ -// -// BSONCodec.m -// BSON Codec for Objective-C. -// -// Created by Martin Kou on 8/17/10. -// MIT License, see LICENSE file for details. -// +/* + * BSONCodec.m + * BSON Codec for Objective-C. + * + * Created by Martin Kou on 8/17/10. + * MIT License, see LICENSE file for details. + * + * Adapted by Ludovic Marcotte and Enrique J. Hernández +*/ #import "BSONCodec.h" #import @@ -570,7 +572,7 @@ static NSDictionary *BSONTypes() { NSString *v; - v = [self descriptionWithCalendarFormat: @"%Y-%m-%d %H:%M:%S %Z" + v = [self descriptionWithCalendarFormat: @"%Y-%m-%d %H:%M:%S %z" locale: nil]; return [v BSONEncode]; @@ -599,7 +601,22 @@ static NSDictionary *BSONTypes() key = [NSString stringWithFormat: @"%s", timezone]; - if (!(tz = [timezoneCache objectForKey: key])) + /* We may have the zone using the UTC offset + or abbreviation (deprecated) */ + if (timezone && strlen(timezone) > 0 && (timezone[0] == '+' || timezone[0] == '-')) + { + NSCalendarDate *tzDate; + + tzDate = [[NSCalendarDate alloc] initWithString: key + calendarFormat: @"%z" + locale: nil]; + [tzDate autorelease]; + if (tzDate) + tz = [tzDate timeZone]; + else + tz = nil; + } + else if (!(tz = [timezoneCache objectForKey: key])) { tz = [NSTimeZone timeZoneWithAbbreviation: key];