Skip to content

UTC issues with Epoch.rise_set() and Epoch.utc2local() #14

@sta-c0000

Description

@sta-c0000

Hi,
Just started looking at pymeeus, and it looks great, but perhaps I'm misunderstanding:

The documentation states that "Epoch internally stores time as Terrestrial Time (TT), not UTC.", "When a UTC time is provided, the parameter utc=True must be given. […] it is converted to (and stored as) Terrestrial Time (TT). If utc is not provided, it is supposed that the input data is already in TT scale."

Yet the Epoch.rise_set()'s documentation notes: "The results are given in UTC time.", and the example provided calls get_full_date() without the utc=True parameter.
Perhaps jrise and jsett should be set with the utc=True param and the example changed for consistency?

Also, it appears that Epoch.utc2local() currently can't work if the difference between current local time and current UTC time cross the 24 hour boundary (e.g. 23:00 and 3:00) because it's doing (localhour - utchour).
Also utc2local() does not work for dates other than today, where the current timezone offset may change (DST).

BTW, instead of using utc2local, I'm doing something like this:

from datetime import *
# from zoneinfo import ZoneInfo # optional for Python 3.9+

from pymeeus.Angle import Angle
from pymeeus.Epoch import Epoch
from pymeeus.Sun import Sun

def epoch_datetime(e):
    edt = e.get_full_date(utc=True) # ! not when rise_set? !
    s = edt[5]
    return datetime(*edt[:5], int(s), int(s%1 * 10E5), tzinfo=timezone.utc)

longitude, latitude, altitude = Angle(45.423646), Angle(-75.698592), 90
e = Epoch(2021,7,1)
dtrise, dtset = map(epoch_datetime, e.rise_set(longitude, latitude, altitude))
dtls = dtset.astimezone() # UTC to local timezone
# dtls = dtset.astimezone(ZoneInfo('EST5EDT')) # Specific timezone, Python 3.9+
print(f'Sunset = UTC: {dtset}, Local: {dtls}')
dtwinter = epoch_datetime(Sun.get_equinox_solstice(2021, 'winter'))
dtlw = dtwinter.astimezone() # UTC to local timezone
# dtlw = dtwinter.astimezone(ZoneInfo('EST5EDT')) # Specific timezone, Python 3.9+
print(f'Winter = UTC: {dtwinter}, Local: {dtlw}')

Output:

Sunset = UTC: 2021-07-02 00:57:11.147205+00:00, Local: 2021-07-01 20:57:11.147205-04:00
Winter = UTC: 2021-12-21 15:59:17.402847+00:00, Local: 2021-12-21 10:59:17.402847-05:00

Notice sunset local time is EDT (-4) and winter local time is EST (-5) as expected.
(Sunset appears incorrect here due to TT vs UTC confusion.)

Thank you!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions