fix natural language date parsing with AM/PM; fix to 12-hour time format; skip field widths in date formats

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@29825 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Doug Simons 2010-03-03 19:24:56 +00:00
parent 09666b5d16
commit cb757f4794
3 changed files with 28 additions and 3 deletions

View file

@ -1,3 +1,9 @@
2010-03-03 Doug Simons <dpsimons@testplant.com>
* Source/NSDate.m: Fix natural language date parsing to handle AM/PM.
* Source/NSCalendarDate.m: Fix to %I (12-hour clock) to show midnight
hour as 12, not 00. Skip over field widths while parsing in init.
2010-03-03 Richard Frith-Macdonald <rfm@gnu.org>
* Source/ObjectiveC2/runtime.c: Bugfixes for getting superclass and

View file

@ -874,6 +874,8 @@ static inline int getDigits(const char *from, char *to, int limit, BOOL *error)
{
// Skip '%'
formatIdx++;
while (format[formatIdx] >= '0' && format[formatIdx] <= '9' && formatIdx < formatLen)
formatIdx++; // skip field width
switch (format[formatIdx])
{
@ -2111,7 +2113,7 @@ static void outputValueWithFormat(int v, char *fldfmt, DescriptionInfo *info)
v = info->hd;
if (twelve == YES)
{
if (info->hd == 12)
if (info->hd == 12 || info->hd == 0)
{
v = 12;
}

View file

@ -546,6 +546,7 @@ otherTime(NSDate* other)
dtoIndex = 0;
scanner = [NSScanner scannerWithString: string];
[scanner setCaseSensitive:NO];
[scanner scanUpToCharactersFromSet: digits intoString: 0];
while ([scanner scanCharactersFromSet: digits intoString: &tmp] == YES)
{
@ -561,6 +562,7 @@ otherTime(NSDate* other)
if (tmp && ([tmp characterAtIndex: 0] == (unichar)':'))
{
BOOL done = NO;
BOOL checkForAMPM = NO;
do
{
@ -583,6 +585,7 @@ otherTime(NSDate* other)
m = 0;
s = 0;
hadHour = YES;
checkForAMPM = YES;
}
}
else if (hadMinute == NO)
@ -639,8 +642,7 @@ otherTime(NSDate* other)
{
num = [tmp intValue];
done = NO;
if ([scanner scanUpToCharactersFromSet: digits
intoString: &tmp] == NO)
if ([scanner scanString:@":" intoString: &tmp] == NO)
{
tmp = nil;
}
@ -648,6 +650,21 @@ otherTime(NSDate* other)
}
}
while (done == NO);
if (checkForAMPM)
{
NSArray *ampm = [locale objectForKey: NSAMPMDesignation];
if ([scanner scanString:[ampm objectAtIndex:0] intoString:NULL])
{
if (h == 12) // 12 AM means midnight
h = 0;
}
else if ([scanner scanString:[ampm objectAtIndex:1] intoString:NULL])
{
if (h < 12) // if PM add 12 to any hour less than 12
h += 12;
}
}
}
else
{