Skip to content

Commit

Permalink
Make solar_date() timezone aware. (#1521)
Browse files Browse the repository at this point in the history
  • Loading branch information
SpacemanPaul authored Dec 12, 2023
1 parent 7c738fd commit b872aff
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion datacube/api/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ def solar_day(dataset: Dataset, longitude: Optional[float] = None) -> np.datetim
:param longitude: If supplied correct timestamp for this longitude,
rather than mid-point of the Dataset's footprint
"""
utc = dataset.center_time
utc = dataset.center_time.astimezone(datetime.timezone.utc)

if longitude is None:
_lon = _ds_mid_longitude(dataset)
Expand Down
1 change: 1 addition & 0 deletions docs/about/whats_new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ What's New
v1.8.next
=========
- Add dataset cli tool ``find-duplicates`` to identify duplicate indexed datasets (:pull:`1517`)
- Make solar_day() timezone aware (:pull:`1521`)

v1.8.17 (8th November 2023)
===========================
Expand Down
7 changes: 7 additions & 0 deletions tests/api/test_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,13 @@ def test_solar_day():

assert 'Cannot compute solar_day: dataset is missing spatial info' in str(e.value)

# Test with Non-UTC timestamp in index.
ds = _s(center_time=parse_time('1997-05-22 22:07:44.2270250-7:00'),
metadata=_s(lon=Range(begin=-136.615,
end=-134.325)))
assert solar_day(ds) == np.datetime64('1997-05-22', 'D')
assert solar_day(ds, longitude=0) == np.datetime64('1997-05-23', 'D')


def test_solar_offset():
from datacube.utils.geometry import point
Expand Down

0 comments on commit b872aff

Please sign in to comment.