easy +8 pts

Daylight saving check

Calculate if a given local datetime falls on a daylight saving transition day in the US.

Write a function `is_dst_transition_day(date_str)` that takes a string `date_str` in the format `YYYY-MM-DD` and returns `True` if that date is either the second Sunday in March (DST start) or the first Sunday in November (DST end) for the United States, otherwise returns `False`. The DST rules apply to all years from 2007 onward. Assume the input is always a valid date. Do not use external libraries; use only the `datetime` module.

Constraints

Input is a string in `%Y-%m-%d` format. Year is between 2007 and 2099 inclusive. Return a boolean.

Example

>>> is_dst_transition_day('2024-03-10')
True
>>> is_dst_transition_day('2024-11-03')
True
>>> is_dst_transition_day('2024-03-17')
False
>>> is_dst_transition_day('2024-11-10')
False
8 points ~10 min

Recent Submissions

No submissions yet — hit Run Tests to try!

Hints

Parse the string into a date object using `datetime.strptime`.
For a given year, compute the second Sunday of March and the first Sunday of November.
Use `weekday()` to check if a day is Sunday (6).
Python 3
All tests passed!
Test Results
Press Ctrl+Enter or click Run Tests to execute your code.