mirror of
https://github.com/gnustep/libs-sqlclient.git
synced 2025-02-21 19:01:03 +00:00
Improve distant past/future handling
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/sqlclient/trunk@38650 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
670f939dc8
commit
dfdc074674
2 changed files with 47 additions and 26 deletions
65
Postgres.m
65
Postgres.m
|
@ -100,7 +100,7 @@ static NSDate*
|
|||
newDateFromBuffer(const char *b, int l)
|
||||
{
|
||||
NSCalendarDate *d;
|
||||
NSTimeZone *zone;
|
||||
NSTimeZone *zone;
|
||||
int milliseconds = 0;
|
||||
int timezone = 0;
|
||||
int day;
|
||||
|
@ -212,14 +212,7 @@ newDateFromBuffer(const char *b, int l)
|
|||
timezone = -timezone;
|
||||
}
|
||||
}
|
||||
if (year <= 1)
|
||||
{
|
||||
return [[NSDate distantPast] retain];
|
||||
}
|
||||
else if (year > 4000)
|
||||
{
|
||||
return [[NSDate distantFuture] retain];
|
||||
}
|
||||
|
||||
if (timezone % 60 == 0)
|
||||
{
|
||||
zone = zones[23 + timezone / 60];
|
||||
|
@ -229,24 +222,50 @@ newDateFromBuffer(const char *b, int l)
|
|||
zone = [NSTimeZone timeZoneForSecondsFromGMT: timezone * 60];
|
||||
}
|
||||
|
||||
d = [[NSCalendarDate alloc] initWithYear: year
|
||||
month: month
|
||||
day: day
|
||||
hour: hour
|
||||
minute: minute
|
||||
second: second
|
||||
timeZone: zone];
|
||||
|
||||
if (milliseconds > 0)
|
||||
d = [NSCalendarDate alloc];
|
||||
if (year <= 1)
|
||||
{
|
||||
NSTimeInterval ti;
|
||||
static NSTimeInterval p = 0.0;
|
||||
|
||||
ti = milliseconds;
|
||||
ti /= 1000.0;
|
||||
ti += [d timeIntervalSinceReferenceDate];
|
||||
d = [d initWithTimeIntervalSinceReferenceDate: ti];
|
||||
if (0.0 == p)
|
||||
{
|
||||
p = [[NSDate distantPast] timeIntervalSinceReferenceDate];
|
||||
}
|
||||
d = [d initWithTimeIntervalSinceReferenceDate: p];
|
||||
[d setTimeZone: zone];
|
||||
}
|
||||
else if (year > 4000)
|
||||
{
|
||||
static NSTimeInterval f = 0.0;
|
||||
|
||||
if (0.0 == f)
|
||||
{
|
||||
f = [[NSDate distantFuture] timeIntervalSinceReferenceDate];
|
||||
}
|
||||
d = [d initWithTimeIntervalSinceReferenceDate: f];
|
||||
[d setTimeZone: zone];
|
||||
}
|
||||
else
|
||||
{
|
||||
d = [d initWithYear: year
|
||||
month: month
|
||||
day: day
|
||||
hour: hour
|
||||
minute: minute
|
||||
second: second
|
||||
timeZone: zone];
|
||||
|
||||
if (milliseconds > 0)
|
||||
{
|
||||
NSTimeInterval ti;
|
||||
|
||||
ti = milliseconds;
|
||||
ti /= 1000.0;
|
||||
ti += [d timeIntervalSinceReferenceDate];
|
||||
d = [d initWithTimeIntervalSinceReferenceDate: ti];
|
||||
[d setTimeZone: zone];
|
||||
}
|
||||
}
|
||||
[d setCalendarFormat: @"%Y-%m-%d %H:%M:%S %z"];
|
||||
return d;
|
||||
}
|
||||
|
|
|
@ -73,7 +73,7 @@ main()
|
|||
name: @"test"
|
||||
max: 2
|
||||
min: 1] autorelease];
|
||||
#if 1
|
||||
#if 0
|
||||
{
|
||||
NSAutoreleasePool *p;
|
||||
SQLClient *c0;
|
||||
|
@ -486,9 +486,11 @@ main()
|
|||
|
||||
d0 = [r0 objectForKey:@"when1"];
|
||||
d1 = [r0 objectForKey:@"when2"];
|
||||
NSCAssert([d0 isEqual: [NSDate distantPast]],
|
||||
NSCAssert([d0 timeIntervalSinceReferenceDate]
|
||||
== [[NSDate distantPast]timeIntervalSinceReferenceDate],
|
||||
NSInternalInconsistencyException);
|
||||
NSCAssert([d1 isEqual: [NSDate distantFuture]],
|
||||
NSCAssert([d1 timeIntervalSinceReferenceDate]
|
||||
== [[NSDate distantFuture]timeIntervalSinceReferenceDate],
|
||||
NSInternalInconsistencyException);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue