Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sunset returned as yesterday #30

Open
buelowp opened this issue Mar 19, 2024 · 10 comments
Open

Sunset returned as yesterday #30

buelowp opened this issue Mar 19, 2024 · 10 comments

Comments

@buelowp
Copy link

buelowp commented Mar 19, 2024

I think this may be the same as #29 but testing it, I couldn't exactly get the same reproduction. At issue is when I use this library on my Pi, I'm getting a sunset value from the day before, but sunrise is correct.

This little snippet reproduces the issue for me.

import time
from datetime import datetime
from suntime import Sun, SunTimeException
from dateutil import tz

latitude = 42.01
longitude = -87.98
sun = Sun(latitude, longitude)

def main():
    while True:
        now = datetime.now(tz.gettz('US/Central'))
        ss = sun.get_sunset_time(at_date=now, time_zone=tz.gettz('US/Central'))
        sr = sun.get_sunrise_time(at_date=now, time_zone=tz.gettz('US/Central'))
        print("Now: {}, sr: {}, ss: {}".format(now, sr, ss))

        time.sleep(1)


if __name__ == '__main__':
    main()

which gives me the following results

Now: 2024-03-19 07:55:42.667241-05:00, sr: 2024-03-19 06:55:48-05:00, ss: 2024-03-18 19:03:36-05:00
Now: 2024-03-19 07:55:43.670629-05:00, sr: 2024-03-19 06:55:48-05:00, ss: 2024-03-18 19:03:36-05:00
Now: 2024-03-19 07:55:44.673976-05:00, sr: 2024-03-19 06:55:48-05:00, ss: 2024-03-18 19:03:36-05:00
Now: 2024-03-19 07:55:45.677398-05:00, sr: 2024-03-19 06:55:48-05:00, ss: 2024-03-18 19:03:36-05:00
Now: 2024-03-19 07:55:46.680704-05:00, sr: 2024-03-19 06:55:48-05:00, ss: 2024-03-18 19:03:36-05:00
Now: 2024-03-19 07:55:47.684021-05:00, sr: 2024-03-19 06:55:48-05:00, ss: 2024-03-18 19:03:36-05:00
Now: 2024-03-19 07:55:48.687425-05:00, sr: 2024-03-19 06:55:48-05:00, ss: 2024-03-18 19:03:36-05:00
Now: 2024-03-19 07:55:49.690767-05:00, sr: 2024-03-19 06:55:48-05:00, ss: 2024-03-18 19:03:36-05:00
Now: 2024-03-19 07:55:50.694099-05:00, sr: 2024-03-19 06:55:48-05:00, ss: 2024-03-18 19:03:36-05:00
Now: 2024-03-19 07:55:51.697491-05:00, sr: 2024-03-19 06:55:48-05:00, ss: 2024-03-18 19:03:36-05:00

The values returned are correct, but notice that sunset is yesterday, which doesn't make a lot of sense. This behavior is the same whether I use at_date or not.

Name: suntime
Version: 1.3.2
Summary: Simple sunset and sunrise time calculation python library
Home-page: https://github.com/SatAgro/suntime
Author: Krzysztof Stopa
Author-email: None
License: LGPLv3
Location: /home/pi/.local/lib/python3.9/site-packages
Requires: python-dateutil
Required-by: 
@thennen
Copy link

thennen commented Mar 20, 2024

I also ran into this problem...

@CozyBlanket
Copy link

I've run into the same issue too. I think the problem might be in suntime.py with get_sun_timedelta function as the returning timedelta(hours=UT) variable is negative.

@varaki
Copy link

varaki commented Mar 22, 2024

I have the same problem too since a couple of days ago, but it's consistent ever since 😐

@gablank
Copy link

gablank commented Mar 23, 2024

This issue seems to have been introduced by e9b1fa4.

The bug seems to only happen for days 1 through 80 of the year (i.e. 2024-01-01 through 2024-03-19 are fine this year).

Update: Removing this conditional (run the code for both sunrise and sunset) seems to fix the issue. Not sure if it impacts anything else, but the conditional wasn't there before.

@fluxion-t
Copy link

Same issue here.

@thomarse-ef
Copy link

I have the same issue

@Erotemic
Copy link

Erotemic commented Aug 3, 2024

Also hitting this. It would be nice to have a fix. As it currently stands my estimation of the amount of sunlight at given points looks very wrong:

images_timeofday_distribution

@joe-mccarthy
Copy link

I've just run into this issue.

@TomGudman
Copy link

In the mean time you can use version 1.2.5 (1.3.0 and 1.3.1 are borked and 1.3.2 is one day in the past):

 pip3 install suntime==1.2.5

@TomGudman
Copy link

I have just noted that, despite using 1.2.5, now my sunrise date is the following day but the time is right. So, for my basic chicken coop needs I have done this ugly hack: combining the current date with the sunrise/sunset times. Don't use that if you have NASA needs ;-)

    # UTC+10
    tz_name = 'Australia/Brisbane'
    tz = zoneinfo.ZoneInfo(tz_name)
    # Fix for buggy(?) suntime library (sunrise is right time but date is the next day):
    # was:                   2024-09-20 05:41:00+10:00 --> 2024-09-19 17:43:00+10:00
    # with this fix becomes: 2024-09-19 05:41:00       --> 2024-09-19 17:43:00
    sunrise = datetime.combine(datetime.now(), today_sr.astimezone(tz).time())
    sunset  = datetime.combine(datetime.now(), today_ss.astimezone(tz).time())

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants