Running a website with the timezone set to CET (GMT + 2), Date module @ 6.x-2.9

When saving exceptions for a repeating event, the event series is generated with the correct exceptions, but on the node view page the exception dates get shifted with 1 day back. I.e. Jul-6-2012 becomes Jul-5-2012.

Demo:
- the week view of the calendar: http://kampfkunstzuerich.ch/calendar/2012-W28?mini=calendar%2F2012-07
- the event's view: http://kampfkunstzuerich.ch/content/jugendliche-erwachsene-0 (says that the entry repeats on every Mon, Tue, Wed, Fri, except Jul 05 2012 and Jul 31 2012)

I'd like to keep the timezone setting to be able to handle daylight saving times, so any suggestions on how this could be fixed would be much appreciated.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

karoly’s picture

Version: 7.x-1.2 » 6.x-1.2

Sry, submitted to wrong version. Should be 6x-1.2.

karoly’s picture

In case this would help anyone else, logging my solution to this, which fixes the timezone for the exception dates:

In date_repeat_form.inc @line 177, instead of
$EXCEPT = $exceptions[$i]['datetime'];
Insert
$except_date = date_make_date($exceptions[$i]['datetime'], $exceptions[$i]['tz']);
date_timezone_set($except_date, timezone_open($timezone));
$EXCEPT = date_format($except_date, DATE_FORMAT_DATETIME);

And in date_repeat.module @line 246 instead of the for loop insert this:
foreach ($exceptions as $exception) {
$exception = date_ical_date($exception, 'UTC');
date_timezone_set($exception, date_default_timezone());
$values[] = date_format_date($exception, 'custom', $format);
}

Note, if you also use additional dates, you need to repeat this exercise for those fileds. Would be nice if someone would fix it in the main module.

karoly’s picture

Project: Date Repeat Instance » Date
Version: 6.x-1.2 » 6.x-2.9
karoly’s picture

Title: Event exception dates are not saved with the correct time zone » Event exception dates are not shown with the correct time zone
gpk’s picture

Title: Event exception dates are not shown with the correct time zone » Exceptions to repeat rule are one day off on node view/edit (exceptions are not saved with the correct time zone)

I've just noticed this following a recent upgrade to 6.x-2.9.

This looks almost identical to #1266536: Exceptions to repeat rule save as wrong date which was raised against 7.x, but may be very slightly different - as the original report states above, the event series is created with the correct exceptions but on viewing the node the exceptions are listed one day earlier and the same happens when editing the node (so if you edit an existing node which has the correct event series and exceptions, and then save the node without making any changes, the exceptions will get mucked up).

Am changing the title to reflect both the symptom and the postulated cause at #2.

Sorry, unableto test the fix at #2 just now as my test instance is out of date.

gpk’s picture

Component: Code » Date Repeat API

We should probably also check if the behavior is the same with 6.x-2.x-dev.

gpk’s picture

Still haven't managed to test 6.x-2.x-dev, though I can't see any changes since 2.9 that would have fixed this. I wonder if the problem was introduced here:
http://drupalcode.org/project/date.git/commit/0fb90e34814e5163e7229741a3...
which sets the time of exceptions and additions to midnight instead of 23:59 as previously. Since the bug appears (#2) to be a DST or more general TZ handling problem, this would make sense as midnight could get saved as e.g. 11pm on the previous day, for dates during the DST period, if the +0100 DST conversion not applied (I'm in the UK so I only have at most 1 hour of deviation from UTC to think about!)

So I suspect this problem will appear to go away for me, for a few months, when the clocks go back at the end of October (or, more correctly, for additions/exceptions that are not in the DST period).

I also wonder if the bug has been there for ages, but maybe I would have had to save a node 23 times or more to hit it (with the time being decremented by 1 hour on each save...).

needle’s picture

@gpk: I agree with you - I too reckon that's exactly the commit that introduces the "shift-to-the-day-before error" for the exception dates. My timezone is also UK, and because of the commit, the exceptions get parsed to 23:00 of the previous day in UTC. Line 431 of date_repeat_calc.inc then strips off just the Y-m-d part and, bang, I get the wrong days excluded from the sequence.

I assume the line:
$exception['datetime'] .= ' 23:59:59';
was changed to:
$exception['datetime'] .= ' 00:00:00';
because others (behind UTC) were getting "shift-to-the-day-after errors".

Presumably, it should actually be:
$exception['datetime'] .= ' 12:00:00';
since all timezones are within 12 hours of UTC.

Edit: I seem to be wrong about this. But I can verify that the problem exists... will check further.

indigoxela’s picture

I can confirm the off by one day problem in date(_repeat) 6.x-2.9 for date exceptions and can confirm that the changes in comment #2 did the trick.

Standard timezone of the webpage: "Europe/Berlin",
Timezone setting of the field: "Timezone of the webpage"

gpk’s picture

Just to confirm a suspicion I had in #7, that for me this problem goes away for additions/exceptions after 27 October 2012, i.e. outside of the DST period. I'm in London by the way with the following date settings:

Default time zone: Europe/London
Field type: Datetime
Field time zone handling: No time zone conversion

TeeganB’s picture

I am getting this issue at the moment. The exception dates go back a day each time I save the node or add another exception date. Has anyone come up with a fix for this yet? I don't feel comfortable editing the module itself.

Thanks,

gpk’s picture

Yes now we are back in DST this is biting us again. I was planning to turn #2 into a patch but have not got round to it yet.

jonathanhuot’s picture

Status: Active » Needs review
FileSize
1.18 KB
1.28 KB

Patch for 6.x-2.9 are attached. Please review them and commit them if working anywhere.

I've tested exclusions and additions with a timezone offset from Europe/Paris (GMT+2).

Status: Needs review » Needs work

The last submitted patch, date_repeat.module.patch, failed testing.

benoitF’s picture

First test seems ok here (also in France, UTC+2).
I can edit an existing event without exceptions drifting 1 day before.

Thanks.

jonathanhuot’s picture

Status: Needs work » Needs review

Someone can help to make patch working with Drupal system ?

gpk’s picture

To make a patch: http://drupal.org/node/707484

Actually we didn't read that page but just watched http://vimeo.com/41366717 and used the instructions at http://drupal.org/project/date/git-instructions.

This patch is the same as #13 but in the right format.

Fingers crossed!

gpk’s picture

Version: 6.x-2.9 » 6.x-2.x-dev

Actually the patch at #17 is against 6.x-2.x-dev but in practical terms I doubt that makes any difference.

Status: Needs review » Needs work

The last submitted patch, date_exceptions_additions-1619916-17.patch, failed testing.

gpk’s picture

Status: Needs work » Needs review
gpk’s picture

Version: 6.x-2.x-dev » 6.x-2.9

Hmmm, Date 6.x-2.x branch fails tests. Maybe try with 6.x-2.9 after all...???

eFeS’s picture

Just want to confirm the bug and the solution (#2) also.
Patch from #17 clearly applied to 6.x-2.9. Thanks!

bnorbi’s picture

Version: 6.x-2.9 » 6.x-2.10
Issue summary: View changes

6.x-2.10 also have this bug.
Patch #17 solve it.

DamienMcKenna’s picture

Status: Needs review » Closed (won't fix)

Unfortunately the D6 version of this module is no longer supported, but we appreciate the time you put into this. If this problem is relevant for D7 too, please reopen the issue. Thanks.