mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-22 16:33:29 +00:00
fix am/pm issues and incorrect test
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@32605 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
21371b2c5e
commit
8bea71efa9
2 changed files with 28 additions and 12 deletions
|
@ -495,7 +495,6 @@ GSPrivateTimeNow(void)
|
|||
*/
|
||||
- (id) initWithString: (NSString *)description
|
||||
{
|
||||
// +++ What is the locale?
|
||||
return [self initWithString: description
|
||||
calendarFormat: cformat
|
||||
locale: nil];
|
||||
|
@ -509,7 +508,6 @@ GSPrivateTimeNow(void)
|
|||
- (id) initWithString: (NSString *)description
|
||||
calendarFormat: (NSString *)format
|
||||
{
|
||||
// ++ What is the locale?
|
||||
return [self initWithString: description
|
||||
calendarFormat: format
|
||||
locale: nil];
|
||||
|
@ -1107,7 +1105,8 @@ static inline int getDigits(const char *from, char *to, int limit, BOOL *error)
|
|||
|
||||
case 'd': // fall through
|
||||
case 'e':
|
||||
sourceIdx += getDigits(&source[sourceIdx], tmpStr, 2, &error);
|
||||
sourceIdx
|
||||
+= getDigits(&source[sourceIdx], tmpStr, 2, &error);
|
||||
day = atoi(tmpStr);
|
||||
had |= hadD;
|
||||
if (error == NO && day < 1)
|
||||
|
@ -1118,7 +1117,8 @@ static inline int getDigits(const char *from, char *to, int limit, BOOL *error)
|
|||
break;
|
||||
|
||||
case 'F':
|
||||
sourceIdx += getDigits(&source[sourceIdx], tmpStr, 3, &error);
|
||||
sourceIdx
|
||||
+= getDigits(&source[sourceIdx], tmpStr, 3, &error);
|
||||
milliseconds = atoi(tmpStr);
|
||||
break;
|
||||
|
||||
|
@ -1134,19 +1134,22 @@ static inline int getDigits(const char *from, char *to, int limit, BOOL *error)
|
|||
case 'I': // fall through
|
||||
twelveHrClock = YES;
|
||||
case 'H':
|
||||
sourceIdx += getDigits(&source[sourceIdx], tmpStr, 2, &error);
|
||||
sourceIdx
|
||||
+= getDigits(&source[sourceIdx], tmpStr, 2, &error);
|
||||
hour = atoi(tmpStr);
|
||||
had |= hadh;
|
||||
break;
|
||||
|
||||
case 'j':
|
||||
sourceIdx += getDigits(&source[sourceIdx], tmpStr, 3, &error);
|
||||
sourceIdx
|
||||
+= getDigits(&source[sourceIdx], tmpStr, 3, &error);
|
||||
day = atoi(tmpStr);
|
||||
had |= hadD;
|
||||
break;
|
||||
|
||||
case 'm':
|
||||
sourceIdx += getDigits(&source[sourceIdx], tmpStr, 2, &error);
|
||||
sourceIdx
|
||||
+= getDigits(&source[sourceIdx], tmpStr, 2, &error);
|
||||
month = atoi(tmpStr);
|
||||
had |= hadM;
|
||||
if (error == NO && month < 1)
|
||||
|
@ -1157,7 +1160,8 @@ static inline int getDigits(const char *from, char *to, int limit, BOOL *error)
|
|||
break;
|
||||
|
||||
case 'M':
|
||||
sourceIdx += getDigits(&source[sourceIdx], tmpStr, 2, &error);
|
||||
sourceIdx
|
||||
+= getDigits(&source[sourceIdx], tmpStr, 2, &error);
|
||||
min = atoi(tmpStr);
|
||||
had |= hadm;
|
||||
break;
|
||||
|
@ -1186,12 +1190,14 @@ 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: 0] isEqual:currAMPM])
|
||||
if ([currAMPM caseInsensitiveCompare:
|
||||
[amPMNames objectAtIndex: 0]] == NSOrderedSame)
|
||||
{
|
||||
ampm = YES;
|
||||
isPM = NO;
|
||||
}
|
||||
else if ([[amPMNames objectAtIndex: 1] isEqual:currAMPM])
|
||||
else if ([currAMPM caseInsensitiveCompare:
|
||||
[amPMNames objectAtIndex: 1]] == NSOrderedSame)
|
||||
{
|
||||
ampm = YES;
|
||||
isPM = YES;
|
||||
|
|
|
@ -1,12 +1,20 @@
|
|||
#import "Testing.h"
|
||||
#import <Foundation/NSCalendarDate.h>
|
||||
#import <Foundation/NSAutoreleasePool.h>
|
||||
#import <Foundation/NSDictionary.h>
|
||||
#import <Foundation/NSString.h>
|
||||
#import <Foundation/NSUserDefaults.h>
|
||||
int main()
|
||||
{
|
||||
NSAutoreleasePool *arp = [NSAutoreleasePool new];
|
||||
NSTimeInterval time1, time2, time3, time4, time5, time6, time7, time8, time9;
|
||||
NSCalendarDate *date1;
|
||||
NSMutableDictionary *m;
|
||||
|
||||
m = [[[[NSUserDefaults standardUserDefaults] dictionaryRepresentation]
|
||||
mutableCopy] autorelease];
|
||||
[m setObject: [NSArray arrayWithObjects: @"am", @"pm", nil]
|
||||
forKey: NSAMPMDesignation];
|
||||
|
||||
time1 = [[NSCalendarDate dateWithString: @"Nov 20 02 01:54:22"
|
||||
calendarFormat: @"%b %d %y %H:%M:%S"]
|
||||
|
@ -41,11 +49,13 @@ int main()
|
|||
"+dateWithString:calendarFormat: works if no time zone is specified");
|
||||
|
||||
date1 = [NSCalendarDate dateWithString: @"Nov 29 06 12:00am"
|
||||
calendarFormat: @"%b %d %y %H:%M%p"];
|
||||
calendarFormat: @"%b %d %y %H:%M%p"
|
||||
locale: m];
|
||||
PASS(date1 != nil && [date1 hourOfDay] == 0, "12:00am is midnight");
|
||||
|
||||
date1 = [NSCalendarDate dateWithString: @"Nov 29 06 12:00pm"
|
||||
calendarFormat: @"%b %d %y %H:%M%p"];
|
||||
calendarFormat: @"%b %d %y %H:%M%p"
|
||||
locale: m];
|
||||
PASS(date1 != nil && [date1 hourOfDay] == 12, "12:00pm is noon");
|
||||
|
||||
date1 = [NSCalendarDate dateWithString: @"Nov 29 06 01:25:38"
|
||||
|
|
Loading…
Reference in a new issue