aboutsummaryrefslogtreecommitdiffstats
path: root/Frameworks/PostgresKit/Source/FLXPostgresTypeDateTimeHandler.m
diff options
context:
space:
mode:
authorstuconnolly <stuart02@gmail.com>2012-09-08 10:45:57 +0000
committerstuconnolly <stuart02@gmail.com>2012-09-08 10:45:57 +0000
commitf7df6d3700bac8181e2258a9df28a32153124c46 (patch)
treedf91350bbb69e167148d16a76f584ccccbd88a66 /Frameworks/PostgresKit/Source/FLXPostgresTypeDateTimeHandler.m
parent66f9f09721647b635e4095c865653b8008c9552e (diff)
downloadsequelpro-f7df6d3700bac8181e2258a9df28a32153124c46.tar.gz
sequelpro-f7df6d3700bac8181e2258a9df28a32153124c46.tar.bz2
sequelpro-f7df6d3700bac8181e2258a9df28a32153124c46.zip
Add native timezone type support.
Diffstat (limited to 'Frameworks/PostgresKit/Source/FLXPostgresTypeDateTimeHandler.m')
-rw-r--r--Frameworks/PostgresKit/Source/FLXPostgresTypeDateTimeHandler.m48
1 files changed, 31 insertions, 17 deletions
diff --git a/Frameworks/PostgresKit/Source/FLXPostgresTypeDateTimeHandler.m b/Frameworks/PostgresKit/Source/FLXPostgresTypeDateTimeHandler.m
index 1494478c..c60c1eb9 100644
--- a/Frameworks/PostgresKit/Source/FLXPostgresTypeDateTimeHandler.m
+++ b/Frameworks/PostgresKit/Source/FLXPostgresTypeDateTimeHandler.m
@@ -25,6 +25,7 @@
#import "FLXPostgresConnectionParameters.h"
#import "FLXPostgresConnection.h"
#import "FLXPostgresConnectionTypeHandling.h"
+#import "FLXTimeTZ.h"
static FLXPostgresOid FLXPostgresTypeDateTimeTypes[] =
{
@@ -40,8 +41,8 @@ static FLXPostgresOid FLXPostgresTypeDateTimeTypes[] =
@interface FLXPostgresTypeDateTimeHandler ()
- (NSDate *)_dateFromResult:(const PGresult *)result atRow:(NSUInteger)row column:(NSUInteger)column;
-- (NSDate *)_timeFromResult:(const PGresult *)result atRow:(NSUInteger)row column:(NSUInteger)column;
-- (NSDate *)_timestmpFromResult:(const PGresult *)result atRow:(NSUInteger)row column:(NSUInteger)column;
+- (id)_timeFromResult:(const PGresult *)result atRow:(NSUInteger)row column:(NSUInteger)column type:(FLXPostgresOid)type;
+- (id)_timestmpFromResult:(const PGresult *)result atRow:(NSUInteger)row column:(NSUInteger)column type:(FLXPostgresOid)type;
- (NSDate *)_dateFromComponents:(NSDateComponents *)components;
@@ -78,10 +79,10 @@ static FLXPostgresOid FLXPostgresTypeDateTimeTypes[] =
case FLXPostgresOidTime:
case FLXPostgresOidTimeTZ:
case FLXPostgresOidAbsTime:
- return [self _timeFromResult:result atRow:row column:column];
+ return [self _timeFromResult:result atRow:row column:column type:type];
case FLXPostgresOidTimestamp:
case FLXPostgresOidTimestampTZ:
- return [self _timestmpFromResult:result atRow:row column:column];
+ return [self _timestmpFromResult:result atRow:row column:column type:type];
default:
return nil;
}
@@ -115,21 +116,24 @@ static FLXPostgresOid FLXPostgresTypeDateTimeTypes[] =
}
/**
- * Returns an NSDate created from a time value.
+ * Returns a native object created from a time value.
*
* @note The date part should be ignored as it's set to a default value.
*
* @param result The result to extract the value from.
* @param row The row to extract the value from.
* @param column The column to extract the value from.
+ * @type type The type to be converted from (handles times and times with a time zone).
*
- * @return The NSDate representation.
+ * @return The object representation.
*/
-- (NSDate *)_timeFromResult:(const PGresult *)result atRow:(NSUInteger)row column:(NSUInteger)column
+- (id)_timeFromResult:(const PGresult *)result atRow:(NSUInteger)row column:(NSUInteger)column type:(FLXPostgresOid)type
{
PGtime time;
- PQgetf(result, row, "%time", column, &time);
+ BOOL hasTimeZone = type == FLXPostgresOidTimeTZ;
+
+ PQgetf(result, row, hasTimeZone ? "%timetz" : "%time", column, &time);
NSDateComponents *components = [[NSDateComponents alloc] init];
@@ -142,29 +146,39 @@ static FLXPostgresOid FLXPostgresTypeDateTimeTypes[] =
[components setMinute:time.min];
[components setSecond:time.sec];
- // TODO: handle timezone
-
- return [self _dateFromComponents:components];
+ NSDate *date = [self _dateFromComponents:components];
+
+ return hasTimeZone ? [FLXTimeTZ timeWithDate:date timeZoneGMTOffset:time.gmtoff] : date;
}
/**
- * Returns an NSDate created from a timestamp value.
+ * Returns a native object created from a timestamp value.
*
* @param result The result to extract the value from.
* @param row The row to extract the value from.
* @param column The column to extract the value from.
+ * @type type The type to be converted from (handles timestamps and timestamps with a time zone).
*
- * @return The NSDate representation.
+ * @return The object representation.
*/
-- (NSDate *)_timestmpFromResult:(const PGresult *)result atRow:(NSUInteger)row column:(NSUInteger)column
+- (id)_timestmpFromResult:(const PGresult *)result atRow:(NSUInteger)row column:(NSUInteger)column type:(FLXPostgresOid)type
{
PGtimestamp timestamp;
- PQgetf(result, row, "%timestamp", column, &timestamp);
+ BOOL hasTimeZone = type == FLXPostgresOidTimestampTZ;
+
+ PQgetf(result, row, hasTimeZone ? "%timstamptz" : "%timestamp", column, &timestamp);
+
+ FLXTimeTZ *timestampTZ = nil;
+ NSDate *date = [NSDate dateWithTimeIntervalSince1970:timestamp.epoch];
- // TODO: handle timezone
+ if (hasTimeZone) {
+ timestampTZ = [FLXTimeTZ timeWithDate:date timeZoneGMTOffset:timestamp.time.gmtoff];
+
+ [timestampTZ setHasDate:YES];
+ }
- return [NSDate dateWithTimeIntervalSince1970:timestamp.epoch];
+ return hasTimeZone ? timestampTZ : date;
}
/**