diff options
author | Aleksander Machniak <alec@alec.pl> | 2013-06-05 18:54:26 +0200 |
---|---|---|
committer | Aleksander Machniak <alec@alec.pl> | 2013-06-05 18:54:26 +0200 |
commit | aa44ce6e9703ab15bb5270251358fb756a347f17 (patch) | |
tree | 3f45a36c511f3a9f8cee44ca739e5c9d50bce76a /program/lib/Roundcube/rcube_db_pgsql.php | |
parent | 14226fc845521fd9c7100a056db9aaac0a7352da (diff) |
Add optional argument to now() for simple interval calculations on SQL-side
Diffstat (limited to 'program/lib/Roundcube/rcube_db_pgsql.php')
-rw-r--r-- | program/lib/Roundcube/rcube_db_pgsql.php | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/program/lib/Roundcube/rcube_db_pgsql.php b/program/lib/Roundcube/rcube_db_pgsql.php index 90adf4bad..984dd57a1 100644 --- a/program/lib/Roundcube/rcube_db_pgsql.php +++ b/program/lib/Roundcube/rcube_db_pgsql.php @@ -75,9 +75,6 @@ class rcube_db_pgsql extends rcube_db /** * Return SQL statement to convert a field value into a unix timestamp * - * This method is deprecated and should not be used anymore due to limitations - * of timestamp functions in Mysql (year 2038 problem) - * * @param string $field Field name * * @return string SQL statement to use in query @@ -89,6 +86,24 @@ class rcube_db_pgsql extends rcube_db } /** + * Return SQL function for current time and date + * + * @param int $interval Optional interval (in seconds) to add/subtract + * + * @return string SQL function to use in query + */ + public function now($interval = 0) + { + if ($interval) { + $add = ' ' . ($interval > 0 ? '+' : '-') . " interval '"; + $add .= $interval > 0 ? intval($interval) : intval($interval) * -1; + $add .= " seconds'"; + } + + return "now()" . $add; + } + + /** * Return SQL statement for case insensitive LIKE * * @param string $column Field name |