From 02607a453a103d5ce00c6563c50142eaeb790bd0 Mon Sep 17 00:00:00 2001 From: Wilfred Gee Date: Sat, 15 Feb 2020 09:00:30 +1100 Subject: [PATCH 1/4] Forcing datetime to utc --- panoptes/utils/time.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/panoptes/utils/time.py b/panoptes/utils/time.py index 15a089ec8..d6c0b1658 100644 --- a/panoptes/utils/time.py +++ b/panoptes/utils/time.py @@ -1,5 +1,7 @@ import os import time +from pytz import utc + from astropy import units as u from astropy.time import Time @@ -67,7 +69,7 @@ def current_time(flatten=False, datetime=False, pretty=False): if datetime: # Add UTC timezone - _time = _time.to_datetime() + _time = _time.to_datetime(timezone=utc) return _time From 294eaec89ba1a12ee434c357b142f22dfffd977b Mon Sep 17 00:00:00 2001 From: Wilfred Gee Date: Sat, 15 Feb 2020 09:26:06 +1100 Subject: [PATCH 2/4] Test for the utc timezone --- panoptes/utils/tests/test_utils.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/panoptes/utils/tests/test_utils.py b/panoptes/utils/tests/test_utils.py index 8346dde80..ff135d416 100644 --- a/panoptes/utils/tests/test_utils.py +++ b/panoptes/utils/tests/test_utils.py @@ -2,6 +2,7 @@ import pytest import signal import time +from pytz import utc from datetime import datetime as dt from astropy import units as u @@ -86,7 +87,7 @@ def test_pretty_time(): # This will increment one second - see docs t3 = current_time(datetime=True) - assert t3 == dt(2016, 8, 13, 10, 0, 2) + assert t3 == dt(2016, 8, 13, 10, 0, 2, tzinfo=utc) def test_countdown_timer_bad_input(): From 6245917909ca2ab86b1da758c9cd77d0c36713b3 Mon Sep 17 00:00:00 2001 From: Wilfred Tyler Gee Date: Mon, 17 Feb 2020 22:11:24 +1100 Subject: [PATCH 3/4] Use datetime.timezone instead of pytz --- panoptes/utils/tests/test_utils.py | 2 +- panoptes/utils/time.py | 2 +- requirements.txt | 1 - 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/panoptes/utils/tests/test_utils.py b/panoptes/utils/tests/test_utils.py index ff135d416..1d57884b7 100644 --- a/panoptes/utils/tests/test_utils.py +++ b/panoptes/utils/tests/test_utils.py @@ -2,7 +2,7 @@ import pytest import signal import time -from pytz import utc +from datetime.timezone import utc from datetime import datetime as dt from astropy import units as u diff --git a/panoptes/utils/time.py b/panoptes/utils/time.py index d6c0b1658..0748e4816 100644 --- a/panoptes/utils/time.py +++ b/panoptes/utils/time.py @@ -1,6 +1,6 @@ import os import time -from pytz import utc +from datetime.timezone import utc from astropy import units as u from astropy.time import Time diff --git a/requirements.txt b/requirements.txt index 8e3afdc7d..ba93288cb 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,7 +6,6 @@ numpy photutils pyserial python-dateutil -pytz PyYAML pyzmq ruamel.yaml>=0.15 From 35dd8b1f211429bebc35a78c56f4aa72c2a17a87 Mon Sep 17 00:00:00 2001 From: Wilfred Tyler Gee Date: Mon, 17 Feb 2020 22:18:17 +1100 Subject: [PATCH 4/4] Correct import of datetime timezone --- panoptes/utils/tests/test_utils.py | 4 ++-- panoptes/utils/time.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/panoptes/utils/tests/test_utils.py b/panoptes/utils/tests/test_utils.py index 1d57884b7..84c8e2aa0 100644 --- a/panoptes/utils/tests/test_utils.py +++ b/panoptes/utils/tests/test_utils.py @@ -2,7 +2,7 @@ import pytest import signal import time -from datetime.timezone import utc +from datetime import timezone as tz from datetime import datetime as dt from astropy import units as u @@ -87,7 +87,7 @@ def test_pretty_time(): # This will increment one second - see docs t3 = current_time(datetime=True) - assert t3 == dt(2016, 8, 13, 10, 0, 2, tzinfo=utc) + assert t3 == dt(2016, 8, 13, 10, 0, 2, tzinfo=tz.utc) def test_countdown_timer_bad_input(): diff --git a/panoptes/utils/time.py b/panoptes/utils/time.py index 0748e4816..17326c64e 100644 --- a/panoptes/utils/time.py +++ b/panoptes/utils/time.py @@ -1,6 +1,6 @@ import os import time -from datetime.timezone import utc +from datetime import timezone as tz from astropy import units as u from astropy.time import Time @@ -69,7 +69,7 @@ def current_time(flatten=False, datetime=False, pretty=False): if datetime: # Add UTC timezone - _time = _time.to_datetime(timezone=utc) + _time = _time.to_datetime(timezone=tz.utc) return _time