Author: rfm
Date: Wed Jun 17 10:00:14 2015
New Revision: 38650
URL: http://svn.gna.org/viewcvs/gnustep?rev=38650&view=rev
Log:
Improve distant past/future handling
Modified:
libs/sqlclient/trunk/Postgres.m
libs/sqlclient/trunk/testPostgres.m
Modified: libs/sqlclient/trunk/Postgres.m
URL:
http://svn.gna.org/viewcvs/gnustep/libs/sqlclient/trunk/Postgres.m?rev=38650&r1=38649&r2=38650&view=diff
==============================================================================
--- libs/sqlclient/trunk/Postgres.m (original)
+++ libs/sqlclient/trunk/Postgres.m Wed Jun 17 10:00:14 2015
@@ -100,7 +100,7 @@
newDateFromBuffer(const char *b, int l)
{
NSCalendarDate *d;
- NSTimeZone *zone;
+ NSTimeZone *zone;
int milliseconds = 0;
int timezone = 0;
int day;
@@ -212,40 +212,59 @@
timezone = -timezone;
}
}
+
+ if (timezone % 60 == 0)
+ {
+ zone = zones[23 + timezone / 60];
+ }
+ else
+ {
+ zone = [NSTimeZone timeZoneForSecondsFromGMT: timezone * 60];
+ }
+
+ d = [NSCalendarDate alloc];
if (year <= 1)
{
- return [[NSDate distantPast] retain];
+ static NSTimeInterval p = 0.0;
+
+ if (0.0 == p)
+ {
+ p = [[NSDate distantPast] timeIntervalSinceReferenceDate];
+ }
+ d = [d initWithTimeIntervalSinceReferenceDate: p];
+ [d setTimeZone: zone];
}
else if (year > 4000)
{
- return [[NSDate distantFuture] retain];
- }
- if (timezone % 60 == 0)
- {
- zone = zones[23 + timezone / 60];
+ static NSTimeInterval f = 0.0;
+
+ if (0.0 == f)
+ {
+ f = [[NSDate distantFuture] timeIntervalSinceReferenceDate];
+ }
+ d = [d initWithTimeIntervalSinceReferenceDate: f];
+ [d setTimeZone: zone];
}
else
{
- 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)
- {
- NSTimeInterval ti;
-
- ti = milliseconds;
- ti /= 1000.0;
- ti += [d timeIntervalSinceReferenceDate];
- d = [d initWithTimeIntervalSinceReferenceDate: ti];
- [d setTimeZone: zone];
+ 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;
Modified: libs/sqlclient/trunk/testPostgres.m
URL:
http://svn.gna.org/viewcvs/gnustep/libs/sqlclient/trunk/testPostgres.m?rev=38650&r1=38649&r2=38650&view=diff
==============================================================================
--- libs/sqlclient/trunk/testPostgres.m (original)
+++ libs/sqlclient/trunk/testPostgres.m Wed Jun 17 10:00:14 2015
@@ -73,7 +73,7 @@
name: @"test"
max: 2
min: 1] autorelease];
-#if 1
+#if 0
{
NSAutoreleasePool *p;
SQLClient *c0;
@@ -486,9 +486,11 @@
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);
}
_______________________________________________
Gnustep-cvs mailing list
[email protected]
https://mail.gna.org/listinfo/gnustep-cvs