in reply to Determining Daylight Savings Time

No, that is fundamentally impossible.

Suppose I give you the date '27 October 2002, 2:30', and the timezone is CET. Is that in daylight savings time or not? The answer is that *both* are possible. There will be a 27 October 2002, 2:30 in DST, followed one hour later by a 27 October 2002, 2:30 not in DST.

Of course it's possible that given a date (and time), and the timezone to calculate which date/times have to be DST, which ones cannot be DST, which ones can be both (typically just one hour/year), and which date/time combinations are impossible (typically one hour/year as well). After all, that's what your computer does too when displaying time ;-) But the rules differ from timezone to timezone.

Note that in your particular example, with TZ = MST7MDT, it's easy, as then the timezone name itself indicates daylight savings time is active.

I don't understand your steps to determine DST though. With step 1, you convert the date to epoch seconds - but you already need to know the timezone and whether it's DST or not for that. And why are you in step 3 fiddling with the epoch?

Finally, did you study Time::Local and see how that tackles the problem?

Abigail

Replies are listed 'Best First'.
Re^2: Determining Daylight Savings Time
by Anonymous Monk on Apr 11, 2020 at 02:00 UTC

    Late reply, but:

    This is absolutely impossible without knowing local rules. Because there can be different rules within a single timezone. Example: while Arizona in its entirety belong to the Mountain time zone, most (but not all) of it does NOT observe Daylight Savings Time. Other states in this same timezone do. There are a number of other similar situations in the world.

    Your best bet is to query some service for example geonames. Then you can have accurate data.