#2921 - get_calendar_event_first_date converting wrong timezone since end of DST
| Identifier | #2921 |
|---|---|
| Issue type | Minor issue (breaks specific functionality) |
| Title | get_calendar_event_first_date converting wrong timezone since end of DST |
| Status | Completed |
| Handling member | Chris Graham |
| Addon | calendar |
| Description | Ever since the daylight savings time end, get_calendar_event_first_date is not correctly converting times. The times are still being converted from UTC-4 to UTC, instead of UTC-5 to UTC like it should. |
| Steps to reproduce | $radioevents = $GLOBALS['SITE_DB']->query_select('calendar_events', array('*'), array('e_type' => 9), '');
foreach ($radioevents as $radioevent) { $thedate = get_calendar_event_first_date('UTC', false, $radioevent['e_start_year'], $radioevent['e_start_month'], $radioevent['e_start_day'], $radioevent['e_start_monthly_spec_type'], $radioevent['e_start_hour'], $radioevent['e_start_minute'], $radioevent['e_end_year'], $radioevent['e_end_month'], $radioevent['e_end_day'], $radioevent['e_end_monthly_spec_type'], $radioevent['e_end_hour'], $radioevent['e_end_minute'], $radioevent['e_recurrence'], $radioevent['e_recurrences'], false); } |
| Funded? | No |
The system will post a comment when this issue is modified (e.g., status changes). To be notified of this, click "Enable comment notifications".


Comments
I entered a Chicago-zoned event (hour=9) with timezone conversion on, and observed it save into the database with UTC-5 (hour=14) for a 1st Nov date and UTC-6 (hour=15) for a 30th Nov date.
In both cases it edited okay and displayed as 9am.
I suspect you may have added to the DB using manual code rather than UI, and UTC+- timezones rather than the named timezones. Those would not do any DST handling.
1) Does it show the wrong time when viewing the event now, but showed the right time before?
2) Can you link me to a specific event with the time you expect in NY time, and the time you expect in UTC time.
The script on my server is lovinity.org/check_user.php if you wish to take a look. I don't think I'm doing anything wrong... the function just seems to be returning the wrong timestamps.
That $timezone parameter is the timezone of the event, not the timezone of the viewing user. The timezone of the event is needed so DST shifts can be calculated - events are stored in the DB in UTC but are fixed in the time zone for the e_timezone value of that event - so the UTC time actually varies as you enter/exit DST. If it doesn't know the correct timezone of the event it can't shift the UTC correctly accordingly.
The API is not designed to be able to show arbitrary timezoned output, but it can be fudged by changing the TIMEZONE_MEMBER_CACHE global as follows...
Code:
$GLOBALS['TIMEZONE_MEMBER_CACHE'][get_member()] = 'UTC';
foreach ($radioevents as $radioevent)
{
$thedate = get_calendar_event_first_date($radioevent['e_timezone'], true, $radioevent['e_start_year'], $radioevent['e_start_month'], $radioevent['e_start_day'], $radioevent['e_start_monthly_spec_type'], $radioevent['e_start_hour'], $radioevent['e_start_minute'], $radioevent['e_end_year'], $radioevent['e_end_month'], $radioevent['e_end_day'], $radioevent['e_end_monthly_spec_type'], $radioevent['e_end_hour'], $radioevent['e_end_minute'], $radioevent['e_recurrence'], $radioevent['e_recurrences'], false);
var_dump($thedate[0]);
}
unset($GLOBALS['TIMEZONE_MEMBER_CACHE']);
Note also that I set the 2nd get_calendar_event_first_date parameter to true to force it to display into UTC (the fudged timezone of the viewing user) rather than the event's own timezone.