When adding a fixed date condition to a rule, re-saving the condition adds or subtracts the difference between the local time and GMT each time.

My timezone in Regional settings is set to "America/Toronto", which is currently GMT -0500.

  1. Create a condition for site:current-date, operator is greater than, data value 2012-12-28 06:00:00.
  2. Edit the condition. The form's data value is displayed as 2012-12-28 11:00:00, which is 5 hours ahead of the previously saved value.
  3. Save the condition.

Repeating these steps causes the data value to drift by +5 hours (or the difference from GMT) each time. It looks like this behaviour comes from RulesDataUIDate::inputForm(), which runs the saved timestamp through gmdate() each time the form is displayed.

Related: #1289566: Rules interface instructs to use GMT, but evaluation is against local time

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

star-szr’s picture

Title: Value of fixed date comparison condition drifts when re-saved » Value of fixed date data value drifts when re-saved

Re-titling because I don't think this bug affects only conditions, it looks like it would affect the schedule functionality as well.

star-szr’s picture

Title: Value of fixed date data value drifts when re-saved » Fixed date values drift when re-saved
Component: Rules Core » User Interface

Clearer title and technically this is a Rules UI bug.

BrightBold’s picture

Title: Fixed date values drift when re-saved » Fixed date values drift by GMT offset when re-saved
Issue summary: View changes

I can confirm this is still a problem in the latest dev.

weiseng’s picture

Display the datetime using system default timezone instead of gmdate() to avoid confusion.

related issue: https://www.drupal.org/node/1289566

weiseng’s picture

Status: Active » Needs review
Luxian’s picture

Status: Needs review » Needs work

Thanks @weiseng for the patch. It made my life easier today.

As for review, my only complain is regarding the field description text:

+++ b/ui/ui.data.inc
@@ -354,20 +354,20 @@ class RulesDataUIBoolean extends RulesDataUI implements RulesDataDirectInputForm
+    $form[$name]['#description'] = t('The date in system\'s default timezone. You may enter a fixed time (like %format) or any other values in GMT known by the PHP !strtotime function (like "+1 day"). Relative dates like "+1 day" or "now" relate to the evaluation time.',

1. Maybe we can get away by not mentioning the timezone at all because it's confusing. First of all - I'm not sure what "system" means (Drupal or server). And even if it refers to Drupal system, it can be user's timezone and not the default Drupal timezone. The timezone used is set by Drupal according to the value returned by drupal_get_user_timezone() during bootstrap.

2. There is still a 'GMT' mention in that string.

Proposal:

Fixed time (like %format) or any other values known by the PHP !strtotime function (like "+1 day"). Relative dates like "+1 day" or "now" relate to the evaluation time.
TR’s picture

Patch needs to be re-rolled.