Permalink
Browse files

Force __toString to enforce casting consistancy for timestamps when u…

…sing atsumi_DateTime. Add new timestamp or null option
  • Loading branch information...
1 parent fe8e847 commit 4b09493d04214894afa4d30712664000c05282ec @jonnixs committed May 17, 2012
Showing with 13 additions and 2 deletions.
  1. +13 −2 classes/database/adapter/postgresql/caster_PostgreSql.php
@@ -41,6 +41,7 @@ class caster_PostgreSql extends caster_Abstract {
's' => 'text',
'S' => 'textOrNull',
't' => 'timestampWithTimezone',
+ 'T' => 'timestampWithTimezoneOrNull',
'v' => 'fullTextVector',
'x' => 'binary',
'z' => 'interval',
@@ -197,7 +198,17 @@ static function binary($in) {
* @return string Casted string
*/
static function timestampWithTimezone($in) {
- return sf("'%s'::TIMESTAMP WITH TIME ZONE", pg_escape_string(gmdate('Y-m-d H:i:s+00', $in)));
+ return sf("'%s'::TIMESTAMP WITH TIME ZONE", pg_escape_string(gmdate('Y-m-d H:i:s+00', (string)$in)));
+ }
+
+ /**
+ * Casts a variable into a PostgreSQL timestamp with timezone or NULL
+ * @param int $in Int to be casted
+ * @return string Casted string
+ */
+ static function timestampWithTimezoneOrNull($in) {
+ if (is_null($in)) return 'NULL';
+ return sf("'%s'::TIMESTAMP WITH TIME ZONE", pg_escape_string(gmdate('Y-m-d H:i:s+00', (string)$in)));
}
/**
@@ -251,4 +262,4 @@ static function fullTextVector($in) {
/* DEPRECATED METHODS */
}
-?>
+?>

0 comments on commit 4b09493

Please sign in to comment.