# How to check if date is summer time

**URL:** <https://discourse.julialang.org/t/how-to-check-if-date-is-summer-time/75950>\
**Category:** General Usage\
**Tags:** question, dates, time\
**Created:** [February 7, 2022, 1:35pm UTC](https://discourse.julialang.org/t/how-to-check-if-date-is-summer-time/75950 "2022-02-07T13:35:22Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Impressium](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/impressium/32/19575_2.png) [@Impressium](https://discourse.julialang.org/u/Impressium)\
**Post date:** [February 7, 2022, 1:35pm UTC](https://discourse.julialang.org/t/how-to-check-if-date-is-summer-time/75950/1 "2022-02-07T13:35:22Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [February 7, 2022, 2:03pm UTC](https://discourse.julialang.org/t/how-to-check-if-date-is-summer-time/75950/2 "2022-02-07T14:03:12Z")

</div>

Maybe you could base something on

[https://juliatime.github.io/TimeZones.jl/stable/api-public/#TimeZones.next\_transition\_instant](https://juliatime.github.io/TimeZones.jl/stable/api-public/#TimeZones.next_transition_instant)

```julia
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.

```

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [February 7, 2022, 8:50pm UTC](https://discourse.julialang.org/t/how-to-check-if-date-is-summer-time/75950/3 "2022-02-07T20:50:42Z")

</div>

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:

```julia
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

```

---

<div class="post-metadata">

**Author:** ![Impressium](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/impressium/32/19575_2.png) [@Impressium](https://discourse.julialang.org/u/Impressium)\
**Post date:** [February 15, 2022, 3:39pm UTC](https://discourse.julialang.org/t/how-to-check-if-date-is-summer-time/75950/4 "2022-02-15T15:39:22Z")

</div>

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

```julia
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

```

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [February 15, 2022, 3:44pm UTC](https://discourse.julialang.org/t/how-to-check-if-date-is-summer-time/75950/5 "2022-02-15T15:44:31Z")

</div>

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