2525from skyfield .errors import EphemerisRangeError
2626
2727from .model import Position , AsterEphemerides , MoonPhase , Object , ASTERS
28- from .dateutil import translate_to_timezone , normalize_datetime
29- from .core import get_skf_objects , get_timescale , get_iau2000b
28+ from .dateutil import translate_to_utc_offset , normalize_datetime
29+ from .core import (
30+ get_skf_objects ,
31+ get_timescale ,
32+ get_iau2000b ,
33+ deprecated ,
34+ alert_deprecation ,
35+ )
3036from .enum import MoonPhaseType
3137from .exceptions import OutOfRangeDateError
3238
3339RISEN_ANGLE = - 0.8333
3440
3541
3642def _get_skyfield_to_moon_phase (
37- times : [Time ], vals : [int ], now : Time , timezone : int
43+ times : [Time ], vals : [int ], now : Time , utc_offset : Union [ int , float ]
3844) -> Union [MoonPhase , None ]:
3945 tomorrow = get_timescale ().utc (
4046 now .utc_datetime ().year , now .utc_datetime ().month , now .utc_datetime ().day + 1
@@ -58,21 +64,27 @@ def _get_skyfield_to_moon_phase(
5864 MoonPhaseType .FULL_MOON ,
5965 MoonPhaseType .LAST_QUARTER ,
6066 ]:
61- current_phase_time = translate_to_timezone (times [i ].utc_datetime (), timezone )
67+ current_phase_time = translate_to_utc_offset (
68+ times [i ].utc_datetime (), utc_offset
69+ )
6270 else :
6371 current_phase_time = None
6472
6573 # Find the next moon phase
6674 for j in range (i + 1 , len (times )):
6775 if vals [j ] in [0 , 2 , 4 , 6 ]:
68- next_phase_time = translate_to_timezone (times [j ].utc_datetime (), timezone )
76+ next_phase_time = translate_to_utc_offset (
77+ times [j ].utc_datetime (), utc_offset
78+ )
6979 break
7080
7181 return MoonPhase (current_phase , current_phase_time , next_phase_time )
7282
7383
74- def get_moon_phase (for_date : date = date .today (), timezone : int = 0 ) -> MoonPhase :
75- """Calculate and return the moon phase for the given date, adjusted to the given timezone if any.
84+ def get_moon_phase (
85+ for_date : date = date .today (), utc_offset : Union [int , float ] = 0 , ** argv
86+ ) -> MoonPhase :
87+ """Calculate and return the moon phase for the given date, adjusted to the given UTC offset if any.
7688
7789 Get the moon phase for the 27 March, 2021:
7890
@@ -85,7 +97,12 @@ def get_moon_phase(for_date: date = date.today(), timezone: int = 0) -> MoonPhas
8597 >>> get_moon_phase(datetime(2021, 3, 28))
8698 <MoonPhase phase_type=MoonPhaseType.FULL_MOON time=2021-03-28 18:48:10.902298+00:00 next_phase_date=2021-04-04 10:02:27.393689+00:00>
8799
88- Get the moon phase for the 27 March, 2021, in the UTC+2 timezone:
100+ Get the moon phase for the 27 March, 2021, in UTC+2:
101+
102+ >>> get_moon_phase(date(2021, 3, 27), utc_offset=2)
103+ <MoonPhase phase_type=MoonPhaseType.WAXING_GIBBOUS time=None next_phase_date=2021-03-28 20:48:10.902298+02:00>
104+
105+ Note that the `utc_offset` argument was named `timezone` before version 1.1. The old name still works, but will be dropped in the future.
89106
90107 >>> get_moon_phase(date(2021, 3, 27), timezone=2)
91108 <MoonPhase phase_type=MoonPhaseType.WAXING_GIBBOUS time=None next_phase_date=2021-03-28 20:48:10.902298+02:00>
@@ -98,6 +115,13 @@ def get_moon_phase(for_date: date = date.today(), timezone: int = 0) -> MoonPhas
98115 ...
99116 kosmorrolib.exceptions.OutOfRangeDateError: The date must be between 1899-08-09 and 2053-09-26
100117 """
118+
119+ if argv .get ("timezone" ) is not None :
120+ alert_deprecation (
121+ "'timezone' argument of the get_moon_phase() function is deprecated. Use utc_offset instead."
122+ )
123+ utc_offset = argv .get ("timezone" )
124+
101125 earth = get_skf_objects ()["earth" ]
102126 moon = get_skf_objects ()["moon" ]
103127 sun = get_skf_objects ()["sun" ]
@@ -117,11 +141,11 @@ def moon_phase_at(time: Time):
117141
118142 try :
119143 times , phases = find_discrete (start_time , end_time , moon_phase_at )
120- return _get_skyfield_to_moon_phase (times , phases , today , timezone )
144+ return _get_skyfield_to_moon_phase (times , phases , today , utc_offset )
121145
122146 except EphemerisRangeError as error :
123- start = translate_to_timezone (error .start_time .utc_datetime (), timezone )
124- end = translate_to_timezone (error .end_time .utc_datetime (), timezone )
147+ start = translate_to_utc_offset (error .start_time .utc_datetime (), utc_offset )
148+ end = translate_to_utc_offset (error .end_time .utc_datetime (), utc_offset )
125149
126150 start = date (start .year , start .month , start .day ) + timedelta (days = 12 )
127151 end = date (end .year , end .month , end .day ) - timedelta (days = 12 )
@@ -130,9 +154,12 @@ def moon_phase_at(time: Time):
130154
131155
132156def get_ephemerides (
133- position : Position , for_date : date = date .today (), timezone : int = 0
157+ position : Position ,
158+ for_date : date = date .today (),
159+ utc_offset : Union [int , float ] = 0 ,
160+ ** argv
134161) -> [AsterEphemerides ]:
135- """Compute and return the ephemerides for the given position and date, adjusted to the given timezone if any.
162+ """Compute and return the ephemerides for the given position and date, adjusted to the given UTC offset if any.
136163
137164 Compute the ephemerides for July 7th, 2022:
138165
@@ -148,9 +175,9 @@ def get_ephemerides(
148175 <AsterEphemerides rise_time=2022-07-07 22:27:00 culmination_time=2022-07-07 04:25:00 set_time=2022-07-07 10:20:00 aster=<Object type=PLANET name=NEPTUNE />>,
149176 <AsterEphemerides rise_time=2022-07-07 19:46:00 culmination_time=2022-07-07 00:41:00 set_time=2022-07-07 05:33:00 aster=<Object type=PLANET name=PLUTO />>]
150177
151- Timezone can be optionnaly set to adapt the hours to your location:
178+ UTC offset can be optionnaly set to adapt the hours to your location:
152179
153- >>> get_ephemerides(Position(36.6794, 4.8555), date(2022, 7, 7), timezone =2)
180+ >>> get_ephemerides(Position(36.6794, 4.8555), date(2022, 7, 7), utc_offset =2)
154181 [<AsterEphemerides rise_time=2022-07-07 06:29:00 culmination_time=2022-07-07 13:46:00 set_time=2022-07-07 21:02:00 aster=<Object type=STAR name=SUN />>,
155182 <AsterEphemerides rise_time=2022-07-07 14:16:00 culmination_time=2022-07-07 20:06:00 set_time=2022-07-07 01:27:00 aster=<Object type=SATELLITE name=MOON />>,
156183 <AsterEphemerides rise_time=2022-07-07 05:36:00 culmination_time=2022-07-07 12:58:00 set_time=2022-07-07 20:20:00 aster=<Object type=PLANET name=MERCURY />>,
@@ -163,6 +190,20 @@ def get_ephemerides(
163190 <AsterEphemerides rise_time=2022-07-07 21:46:00 culmination_time=2022-07-07 02:41:00 set_time=2022-07-07 07:33:00 aster=<Object type=PLANET name=PLUTO />>]
164191
165192
193+ Note that the `utc_offset` argument was named `timezone` before version 1.1. The old name still works, but will be dropped in the future.
194+
195+ >>> get_ephemerides(Position(36.6794, 4.8555), date(2022, 7, 7), timezone=2)
196+ [<AsterEphemerides rise_time=2022-07-07 06:29:00 culmination_time=2022-07-07 13:46:00 set_time=2022-07-07 21:02:00 aster=<Object type=STAR name=SUN />>,
197+ <AsterEphemerides rise_time=2022-07-07 14:16:00 culmination_time=2022-07-07 20:06:00 set_time=2022-07-07 01:27:00 aster=<Object type=SATELLITE name=MOON />>,
198+ <AsterEphemerides rise_time=2022-07-07 05:36:00 culmination_time=2022-07-07 12:58:00 set_time=2022-07-07 20:20:00 aster=<Object type=PLANET name=MERCURY />>,
199+ <AsterEphemerides rise_time=2022-07-07 04:30:00 culmination_time=2022-07-07 11:44:00 set_time=2022-07-07 18:58:00 aster=<Object type=PLANET name=VENUS />>,
200+ <AsterEphemerides rise_time=2022-07-07 02:05:00 culmination_time=2022-07-07 08:39:00 set_time=2022-07-07 15:14:00 aster=<Object type=PLANET name=MARS />>,
201+ <AsterEphemerides rise_time=2022-07-07 01:02:00 culmination_time=2022-07-07 07:11:00 set_time=2022-07-07 13:20:00 aster=<Object type=PLANET name=JUPITER />>,
202+ <AsterEphemerides rise_time=2022-07-07 23:06:00 culmination_time=2022-07-07 04:29:00 set_time=2022-07-07 09:48:00 aster=<Object type=PLANET name=SATURN />>,
203+ <AsterEphemerides rise_time=2022-07-07 02:47:00 culmination_time=2022-07-07 09:42:00 set_time=2022-07-07 16:38:00 aster=<Object type=PLANET name=URANUS />>,
204+ <AsterEphemerides rise_time=2022-07-07 00:31:00 culmination_time=2022-07-07 06:25:00 set_time=2022-07-07 12:20:00 aster=<Object type=PLANET name=NEPTUNE />>,
205+ <AsterEphemerides rise_time=2022-07-07 21:46:00 culmination_time=2022-07-07 02:41:00 set_time=2022-07-07 07:33:00 aster=<Object type=PLANET name=PLUTO />>]
206+
166207 Objects may not rise or set on the given date (e.g. they rise the previous day or set the next day).
167208 In this case, you will get `None` values on the rise or set time.
168209
@@ -226,10 +267,16 @@ def get_ephemerides(
226267 ...
227268 kosmorrolib.exceptions.OutOfRangeDateError: The date must be between 1899-07-29 and 2053-10-07
228269
229- - The date given in parameter is considered as being given from the point of view of the given timezone .
230- Using a timezone that does not correspond to the place's actual one can impact the returned times.
270+ - The date given in parameter is considered as being given from the point of view of the given UTC offset .
271+ Using a UTC offset that does not correspond to the place's actual one can impact the returned times.
231272 """
232273
274+ if argv .get ("timezone" ) is not None :
275+ alert_deprecation (
276+ "'timezone' argument of the get_ephemerides() function is deprecated. Use utc_offset instead."
277+ )
278+ utc_offset = argv .get ("timezone" )
279+
233280 def get_angle (for_aster : Object ):
234281 def fun (time : Time ) -> float :
235282 return (
@@ -251,15 +298,15 @@ def fun(time: Time) -> bool:
251298 fun .rough_period = 0.5
252299 return fun
253300
254- # The date given in argument is supposed to be given in the given timezone (more natural for a human),
255- # but we need it in UTC. Subtracting the timezone to get it in UTC.
301+ # The date given in argument is supposed to be given in the given UTC offset (more natural for a human),
302+ # but we need it in UTC. Subtracting the offset to get it in UTC.
256303
257304 start_time = get_timescale ().utc (
258- for_date .year , for_date .month , for_date .day , - timezone
305+ for_date .year , for_date .month , for_date .day , - utc_offset
259306 )
260307
261308 end_time = get_timescale ().utc (
262- for_date .year , for_date .month , for_date .day + 1 , - timezone
309+ for_date .year , for_date .month , for_date .day + 1 , - utc_offset
263310 )
264311
265312 ephemerides = []
@@ -276,7 +323,7 @@ def fun(time: Time) -> bool:
276323
277324 for i , time in enumerate (times ):
278325 time_dt = normalize_datetime (
279- translate_to_timezone (time .utc_datetime (), to_tz = timezone )
326+ translate_to_utc_offset (time .utc_datetime (), to_tz = utc_offset )
280327 )
281328
282329 if time_dt is not None and time_dt .day != for_date .day :
@@ -289,18 +336,18 @@ def fun(time: Time) -> bool:
289336
290337 if culmination_time is not None :
291338 culmination_time = normalize_datetime (
292- translate_to_timezone (
339+ translate_to_utc_offset (
293340 culmination_time .utc_datetime (),
294- to_tz = timezone ,
341+ to_tz = utc_offset ,
295342 )
296343 )
297344
298345 ephemerides .append (
299346 AsterEphemerides (rise_time , culmination_time , set_time , aster = aster )
300347 )
301348 except EphemerisRangeError as error :
302- start = translate_to_timezone (error .start_time .utc_datetime (), timezone )
303- end = translate_to_timezone (error .end_time .utc_datetime (), timezone )
349+ start = translate_to_utc_offset (error .start_time .utc_datetime (), utc_offset )
350+ end = translate_to_utc_offset (error .end_time .utc_datetime (), utc_offset )
304351
305352 start = date (start .year , start .month , start .day + 1 )
306353 end = date (end .year , end .month , end .day - 1 )
0 commit comments