mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-30 08:21:25 +00:00
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:
parent
09666b5d16
commit
cb757f4794
3 changed files with 28 additions and 3 deletions
|
@ -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
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue