Skip to content

How to build TZDateTime in ambiguous moments (DST transition) #223

@brinux

Description

@brinux

This is just a question...

TZDateTime allows to set date-time and location to identify a specific moment in time, but there are ambiguous situations.
For example in Europe/Rome, on October 27th 2024 at 3:00am (CEST) time went back to 2:00am (CET), changing Zone (disabling DST).
Because of this, 2:30am is a valid time for both the new and the old Zone (CET/CEST).
tz.TZDateTime() allows me to set the location, which is enough 99.9% of the times, but not in this case...

// If I try to set the provided time...
final overlap = tz.TZDateTime(tz.getLocation("Europe/Rome"), 2024, 10, 27, 2, 30, 0);
// I get it in the most recent Zone (CET, no DST), after the time transition.
// If I want to get the previous one (CEST, DST), I have to manually remove the Save time (which is not straightforward to compute), applying DST.
final before = overlap.add(Duration(hours: -1));

Is there a way to create TZDateTime providing date, time, timezone and zone?
Is there a better/alternative way to handle this situation?

Thanks in advance!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions