From aa44ce6e9703ab15bb5270251358fb756a347f17 Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Wed, 5 Jun 2013 18:54:26 +0200 Subject: Add optional argument to now() for simple interval calculations on SQL-side --- program/lib/Roundcube/rcube_db.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'program/lib/Roundcube/rcube_db.php') diff --git a/program/lib/Roundcube/rcube_db.php b/program/lib/Roundcube/rcube_db.php index 69793b91a..086fd66cb 100644 --- a/program/lib/Roundcube/rcube_db.php +++ b/program/lib/Roundcube/rcube_db.php @@ -711,11 +711,19 @@ class 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() + public function now($interval = 0) { - return "now()"; + if ($interval) { + $add = ' ' . ($interval > 0 ? '+' : '-') . ' INTERVAL '; + $add .= $interval > 0 ? intval($interval) : intval($interval) * -1; + $add .= ' SECONDS'; + } + + return "now()" . $add; } /** -- cgit v1.2.3