Repository navigation
Description
What is the problem this feature will solve?
Python in trying to move away from datetime that have not explicitly set a timezone, raising warning for, e.g., datetime.utcnow() which caused problems for our tests for python 3.12 (see #14784 and the discussion in #15298). This may mean that output from time.to_datetime() by default produces output that cannot easily be calculated with.
Describe the desired outcome
To at least communicate that our scale="utc" times have timezone="utc", i.e., make TimeDatetime as informative as possible. For scale="utc", it could set timezone="utc" (if no explicit timezone is given by calling to_datetime(timezone), for other scales it still only makes sense to use timezone=None.
EDIT: in principle, we could also store any timezone the user has given on Time, but this would seem to add a lot of complexity for little benefit for anything astronomers actually need Time for.
Additional context
The actual change would be rather minimal. From #15298 (comment), it would require changes at
astropy/astropy/time/formats.py
Lines 1126 to 1130 in bde1b85
| if timezone is not None: | |
| if self._scale != "utc": | |
| raise ScaleValueError( | |
| f"scale is {self._scale}, must be 'utc' when timezone is supplied." | |
| ) |
Essentially, one would change those lines to,
if self._scale == "utc":
if timezone is None:
timezone = timezone.utc
else:
if timezone is not None:
raise ScaleValueError(
f"scale is {self._scale}, must be 'utc' when timezone is supplied."
)
Activity
mhvk commentedon Sep 13, 2023
Closing in favour of #15306