Incorrect Timezone Handling Causing Start and End Date Calculation Errors

Created on 22 September 2023, 9 months ago
Updated 30 October 2023, 8 months ago

Problem/Motivation

I've run into a bug where our start and end dates aren't being calculated correctly due to the use of an incorrect timezone setting

Currently, our dates are stored in UTC, and the "getDateStatus" method employs DrupalDateTime::createFromFormat() to perform these calculations. However, the underlying issue is that DrupalDateTime::createFromFormat() internally calls php's root class DateTime::createFromFormat(), which in turn defaults to using the system timezone – in my case, "Pacific/Auckland."

Set system timezone to something other than UTC

Proposed resolution

Fortunately, the solution is quite straightforward: we can rectify this by specifying the correct timezone as the third parameter when using DrupalDateTime::createFromFormat($format, $time, $timezone = NULL, $settings = []).

πŸ› Bug report
Status

Fixed

Version

1.0

Component

Code

Created by

πŸ‡³πŸ‡ΏNew Zealand garethhallnz

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.69.0 2024