Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Incorrect time on DST transition date #40

@mnemanov

Description

@mnemanov

When calculating a zman, the code first calculates the time in UTC and then adjusts for the local timezone offset.

If you calculate a zman for a location that is not yet DST while UTC is already in DST or the reverse the zmanim are off by an hour. (e.g. the last day of standard time in Los Angeles, in UTC it is already DST, same goes for first day of DST in Australia)

I added the following code in my project to account for this

        var newTime = utcDateTime.AddMilliseconds(localOffset);
        var utcDst = DateWithLocation.Location.TimeZone.IsDaylightSavingTime(utcDateTime);
        var newDst = DateWithLocation.Location.TimeZone.IsDaylightSavingTime(newTime);
        if (utcDst != newDst)
        {
            newTime = newTime.AddHours(newDst ? 1 : -1);
        }
        return newTime;

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