From 4bcb2cc0596b5d5a2704868024ff1f8cc9f7a028 Mon Sep 17 00:00:00 2001 From: Cris Date: Wed, 29 Apr 2020 13:16:32 +0200 Subject: [PATCH] Fixed: Active Ampeln now matching correctly time conditions Before missing braces between AND/OR operands delivered wrong results. This is fixed now. --- application/models/content/Ampel_model.php | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/application/models/content/Ampel_model.php b/application/models/content/Ampel_model.php index e75ea7c80..5cdf4ea69 100644 --- a/application/models/content/Ampel_model.php +++ b/application/models/content/Ampel_model.php @@ -45,11 +45,19 @@ class Ampel_model extends DB_Model $query .= ' dauerampel = ? AND'; } - $query .= '( - (NOW()<(deadline+(COALESCE(verfallszeit,0) || \' days\')::interval)::date) - OR (verfallszeit IS NULL) - AND (NOW()>(deadline-(COALESCE(vorlaufzeit,0) || \' days\')::interval)::date) - OR (vorlaufzeit IS NULL AND NOW() < deadline))'; + $query .= ' ( + /* now < ( deadline + verfallszeit ) */ + NOW() < (deadline + (COALESCE(verfallszeit, 0) || \' days\')::interval)::date + /* oder keine verfallszeit */ + OR verfallszeit IS NULL + ) + AND + ( + /* now > ( deadline - vorlaufzeit ) */ + NOW() > (deadline - (COALESCE(vorlaufzeit, 0) || \' days\')::interval)::date + /* oder keine vorlaufzeit (ab sofort) */ + OR vorlaufzeit IS NULL + )'; $query .= ' ORDER BY deadline DESC';