How to check if date is summer time

Hi all,

Didn’t find anything online and here on discourse. So here is my my question.

How would I check if a date is summer or winter time?

Cheers

Maybe you could base something on

https://juliatime.github.io/TimeZones.jl/stable/api-public/#TimeZones.next_transition_instant

TimeZones.next_transition_instant — Function.

next_transition_instant(zdt::ZonedDateTime) -> Union{ZonedDateTime, Nothing}
next_transition_instant(tz::TimeZone=localzone()) -> Union{ZonedDateTime, Nothing}

Determine the next instant at which a time zone transition occurs (typically due to daylight-savings time). If no there exists no future transition then nothing will be returned.
2 Likes

In many countries in Europe, Daylight Saving Time (DST) starts on the last Sunday in March and ends on the last Sunday in October. Using Dates and these rules one could implement:

using Dates
             
function isEuroDST(d::Date)
    d1 = tolast(Date(Year(d),Month(3)),  7, of=Month)    # last Sunday of March
    d2 = tolast(Date(Year(d),Month(10)), 7, of=Month)    # last Sunday of October
    return (d1 <= d < d2)
end

isEuroDST(Date("2022-03-26"))   # false
isEuroDST(Date("2023-03-26"))   # true
1 Like

I wrote that. It seems to work. What are your thoughts on adding this to the ZonedDateTime pkg?

using Dates
using TimeZones
const NY_TIMEZONE = tz"America/New_York"

function is_summer_time(date = now(UTC))::Bool
    year_start = ZonedDateTime(
        year(date),
        1,
        1, 
        NY_TIMEZONE
    )
    
    summer_time_start = TimeZones.next_transition_instant(year_start)
    summer_time_end = TimeZones.next_transition_instant(summer_time_start + Day(1))
    
    if date isa DateTime || date isa Date
        date = ZonedDateTime(date, NY_TIMEZONE)
    end

    summer_time_start <= date < summer_time_end
end
1 Like

No idea, never used that package myself, but why not open an issue/file a PR there and see what they think?