Skip to content

Use of timezone in Time.datetime #15311

Closed

Description

@mhvk

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

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

  1. mhvk commented on Sep 13, 2023

    @mhvk
    ContributorAuthor

    Closing in favour of #15306

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions