Skip to content

Issue with timezones that have daylight savings time (DST) #3

@JorisH

Description

@JorisH

Detailed description

When modifying a DateTimePlus (for example by adding days), the library is unable to consider DST because it is unaware of the timezone. The offset alone is not enough to identify the timezone and the need to adjust for DST.

Context

As we usually work in Europe/Brussels timezone - which has DST - we always will have this problem when modifying a DateTimePlus from summertime to wintertime and vice versa.

Possible implementation

Add a FormatWithTimezone that does what it says: include the timezone (iso the offset).

Your environment

how to reproduce:

// summertime ends at 27/10/2024 when 03:00 becomes 02:00
$summerTime = DateTimePlus::from("2024-10-27T00:00:00+02:00", FormatWithTimezone::ATOM);
// add 1 day
$winterTime = $summerTime->add(0, 0, 1); 
$winterFormatted = $winterTime->formatPlus("Y-MM-dd'T'HH:mm:ss.SSSZZZZZ'", 'nl_BE', new \DateTimeZone("Europe/Brussels"));

echo $winterFormatted;
// expected: 2024-10-28T00:00:00.000+01:00
// actual: 2024-10-27T23:00:00.000+01:00

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions