Skip to content

Commit

Permalink
fix: amend UTC datetime.astimezone() across repository in @observerly…
Browse files Browse the repository at this point in the history
…/celerity.

fix: amend UTC datetime.astimezone() across repository in @observerly/celerity.
  • Loading branch information
michealroberts committed Apr 24, 2024
1 parent c637ad0 commit db6d275
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 17 deletions.
8 changes: 2 additions & 6 deletions src/celerity/equinox.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ def get_spring_equinox(year: int) -> datetime:
)

# Convert the Julian date to a datetime UTC object:
return datetime.utcfromtimestamp((JD - 2440587.5) * 86400).astimezone(
tz=timezone.utc
)
return datetime.fromtimestamp((JD - 2440587.5) * 86400).astimezone(tz=timezone.utc)


# **************************************************************************************
Expand All @@ -49,9 +47,7 @@ def get_autumn_equinox(year: int) -> datetime:
)

# Convert the Julian date to a datetime UTC object:
return datetime.utcfromtimestamp((JD - 2440587.5) * 86400).astimezone(
tz=timezone.utc
)
return datetime.fromtimestamp((JD - 2440587.5) * 86400).astimezone(tz=timezone.utc)


# **************************************************************************************
8 changes: 2 additions & 6 deletions src/celerity/solstice.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ def get_summer_solstice(year: int) -> datetime:
JD = 1721233.2486 + 365.2417284 * year - 0.053018 * pow(T, 2) + 0.009332 * pow(T, 3)

# Convert the Julian date to a datetime UTC object:
return datetime.utcfromtimestamp((JD - 2440587.5) * 86400).astimezone(
tz=timezone.utc
)
return datetime.fromtimestamp((JD - 2440587.5) * 86400).astimezone(tz=timezone.utc)


# **************************************************************************************
Expand All @@ -47,9 +45,7 @@ def get_winter_solstice(year: int) -> datetime:
)

# Convert the Julian date to a datetime UTC object:
return datetime.utcfromtimestamp((JD - 2440587.5) * 86400).astimezone(
tz=timezone.utc
)
return datetime.fromtimestamp((JD - 2440587.5) * 86400).astimezone(tz=timezone.utc)


# **************************************************************************************
7 changes: 2 additions & 5 deletions src/celerity/temporal.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,8 @@ def get_greenwhich_sidereal_time(date: datetime) -> float:
if T_0 < 0:
T_0 += 24

# Ensure that the date is in UTC
d = date.astimezone(tz=timezone.utc)

# Convert the UTC time to a decimal fraction of hours:
UTC = d.microsecond / 1e-6 + d.second / 60 + d.minute / 60 + d.hour
UTC = date.microsecond / 1e-6 + date.second / 60 + date.minute / 60 + date.hour

A = UTC * 1.002737909

Expand All @@ -101,7 +98,7 @@ def get_local_sidereal_time(date: datetime, longitude: float) -> float:
:param longitude: The longitude of the observer.
:return: The Local Sidereal Time (LST) of the given date normalised to UTC.
"""
GST = get_greenwhich_sidereal_time(date.astimezone(tz=timezone.utc))
GST = get_greenwhich_sidereal_time(date)

d = (GST + longitude / 15.0) / 24.0

Expand Down
19 changes: 19 additions & 0 deletions tests/test_sun.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from datetime import datetime, timezone

from src.celerity.common import EquatorialCoordinate, GeographicCoordinate
from src.celerity.coordinates import convert_equatorial_to_horizontal
from src.celerity.sun import (
get_angular_diameter,
get_distance,
Expand Down Expand Up @@ -65,6 +66,24 @@ def test_get_equatorial_coordinate():
assert eq["ra"] == 318.5617376411268
assert eq["dec"] == -16.008394691469505

hz = convert_equatorial_to_horizontal(date, observer, eq)

assert hz["alt"] == -69.40209879395105
assert hz["az"] == 82.77542830157664

# Add one hour to the date:
date = datetime(2015, 2, 5, 13, 0, 0, 0, tzinfo=timezone.utc)

eq = get_equatorial_coordinate(date)

assert eq["ra"] == 318.60368091333004
assert eq["dec"] == -15.995795336804742

hz = convert_equatorial_to_horizontal(date, observer, eq)

assert hz["alt"] == -55.32225076978145
assert hz["az"] == 89.64913544932578


def test_get_angular_diameter():
date = datetime(2015, 2, 15, 0, 0, 0, 0, tzinfo=timezone.utc)
Expand Down

0 comments on commit db6d275

Please sign in to comment.