Skip to content

On day of time changes, the sunrise is off by 1 if the time is set to midnight #10

@sgabler

Description

@sgabler

I noticed an issue that might be a bug, or at least something that I misunderstood from the examples provided in the README.

Example: We have a location in Berlin, Germany. We now want to calculate the sunrise for the following three days

  • day before winter time change: Oct 30 2021
  • day of winter time change: Oct 31 2021
  • day after winter time change: Nov 1 2021

The way I used the library, the correct sunrise/sunset was calculated for the day before and the day after, but not for the day of the winter time change.

  • Oct 30 2021: 2021-10-30T07:58:41
  • Oct 31 2021: 2021-10-31T08:00:35 (wrong, off by one hour, should be 07:00:35)
  • Nov 01 2021: 2021-11-01T07:02:25

For each case I created a DateTime with Kind Unspecified. So for the example of Oct 31:

var date = new DateTime(2021, 10, 31, 0, 0, 0);
var solarTimes = new SolarTimes(date, 52.50, 13.35);

This calculates the wrong date, because at 00:00 the UTC offset is still 2. At 3:00 the UTC offset changes to 1. The offset is used in internal calculations, which I found out after debugging a while.

So as a workaround/fix, we are now always passing a DateTime set to noon (12:00).

var date = new DateTime(2021, 10, 31, 12, 0, 0);
var solarTimes = new SolarTimes(date, 52.50, 13.35);

Then it works very well.

In my mind that seems like a bug, because even if you are checking the sunrise/sunset of a day before 3:00 AM (e.g. via DateTime.Now), you should be able to get the correct sunrise/sunset for that day.

The above examples are a bit simplified from my real code and I didn't double check them, but the point is that some days have 2 valid UTC offsets, and if the wrong one is accidentally used, then the sunrise is off by 1.

Did I misunderstand something maybe, or might this be a bug?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions