Fix AM/PM parsing to recognize 12 AM as midnight not noon; require time zone if specified in format

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@31084 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Doug Simons 2010-08-06 16:20:19 +00:00
parent f380800ca6
commit 00b4589f91
2 changed files with 43 additions and 19 deletions

View file

@ -1,3 +1,9 @@
2010-08-06 Doug Simons <doug.simons@testplant.com>
* Source/NSCalendarDate.m: Fix to AM/PM parsing to recognize
12 AM as midnight, not noon. When format calls for a time zone,
return nil if no time zone is given (the same as Cocoa).
2010-07-31 Quentin Mathe <quentin.mathe@gmail.com>
* Tools/AGSParser.h:

View file

@ -682,6 +682,7 @@ static inline int getDigits(const char *from, char *to, int limit, BOOL *error)
int sec = 0;
NSTimeZone *tz = nil;
BOOL ampm = NO;
BOOL isPM = NO;
BOOL twelveHrClock = NO;
int julianWeeks = -1, weekStartsMonday = 0, dayOfWeek = -1;
const char *source;
@ -1184,11 +1185,16 @@ static inline int getDigits(const char *from, char *to, int limit, BOOL *error)
* The time addition is handled below because this
* indicator only modifies the time on a 12hour clock.
*/
if ([[amPMNames objectAtIndex: 1] isEqual:
currAMPM] == YES)
{
ampm = YES;
}
if ([[amPMNames objectAtIndex: 0] isEqual:currAMPM])
{
ampm = YES;
isPM = NO;
}
else if ([[amPMNames objectAtIndex: 1] isEqual:currAMPM])
{
ampm = YES;
isPM = YES;
}
}
break;
@ -1294,16 +1300,24 @@ static inline int getDigits(const char *from, char *to, int limit, BOOL *error)
/* Abbreviations aren't one-to-one with time zone names
so just look for the zone named after the abbreviation,
then look up the abbreviation as a last resort */
tz = [NSTimeZone timeZoneWithName: z];
if (tz == nil)
{
tz = [NSTimeZone timeZoneWithAbbreviation: z];
if (tz == nil)
if ([z length] > 0)
{
tz = [NSTimeZone timeZoneWithName: z];
if (tz == nil)
{
error = YES;
NSDebugMLog(@"Time zone '%@' not found", z);
tz = [NSTimeZone timeZoneWithAbbreviation: z];
if (tz == nil)
{
error = YES;
NSDebugMLog(@"Time zone '%@' not found", z);
}
}
}
}
else
{
error = YES;
NSDebugMLog(@"Time zone not given");
}
}
break;
@ -1328,12 +1342,16 @@ static inline int getDigits(const char *from, char *to, int limit, BOOL *error)
}
if (twelveHrClock == YES)
{
if (ampm == YES && hour != 12)
{
hour += 12;
}
}
{
if (ampm == YES && isPM == YES && hour != 12)
{
hour += 12;
}
else if (ampm == YES && isPM == NO && hour == 12)
{
hour = 0; // 12 AM
}
}
if (julianWeeks != -1)
{