Kosmorro / lib

Kosmorrolib, a library to calculate ephemerides.
https://kosmorro.space/lib
GNU Affero General Public License v3.0
7 stars 6 forks source link

rise_time and set_time are sometimes None with some timezones #47

Closed SpeedCode210 closed 2 years ago

SpeedCode210 commented 2 years ago

I have searched for an opened issue and didn't find my bug

Version of Kosmorrolib

1.0

Version of Python

3.10

Operating system

Linux

Bug description

When trying to get ephemerids from Kosmorrolib, sometimes it returns None rise_time and set_times

Reproducer

import kosmorrolib
import datetime

print("Timezone UTC :")
print(kosmorrolib.get_ephemerides(kosmorrolib.Position(36.6794, 4.8555), datetime.date(2022, 7, 7), timezone=0)[5])
print("Timezone UTC+1 :")
print(kosmorrolib.get_ephemerides(kosmorrolib.Position(36.6794, 4.8555), datetime.date(2022, 7, 7), timezone=1)[5])

Expected result

Timezone UTC :
<AsterEphemerides rise_time=2022-07-07 22:59:00 culmination_time=2022-07-07 05:11:00 set_time=2022-07-07 11:20:00 aster=<Object type=PLANET name=JUPITER />>
Timezone UTC+1 :
<AsterEphemerides rise_time=2022-07-07 23:59:00 culmination_time=2022-07-07 06:11:00 set_time=2022-07-07 12:20:00 aster=<Object type=PLANET name=JUPITER />>

Actual result

Timezone UTC :
<AsterEphemerides rise_time=2022-07-07 22:59:00 culmination_time=2022-07-07 05:11:00 set_time=2022-07-07 11:20:00 aster=<Object type=PLANET name=JUPITER />>
Timezone UTC+1 :
<AsterEphemerides rise_time=None culmination_time=2022-07-07 06:11:00 set_time=None aster=<Object type=PLANET name=JUPITER />>
Deuchnord commented 2 years ago

This is due to the way the ephemerides are computed:

  1. the rise, culmination and set times are computed on UTC timezone;
  2. the found times are then converted to the requested timezone
  3. if once converted to the requested timezone, one or several hours are found outside of the requested date, they are removed.

At first, it seemed logical to me, but it's actually not. I think the best way to fix this might be to take the requested timezone in account at the computation time.