From f68b9c43958df9ec2657eea7fe6e8c9db70c4726 Mon Sep 17 00:00:00 2001 From: "Adam.Dybbroe" Date: Fri, 19 Jul 2024 16:13:28 +0200 Subject: [PATCH] Improve readability Signed-off-by: Adam.Dybbroe --- pyorbital/orbital.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/pyorbital/orbital.py b/pyorbital/orbital.py index e6fd99c..f08c638 100644 --- a/pyorbital/orbital.py +++ b/pyorbital/orbital.py @@ -927,13 +927,12 @@ def _get_tz_unaware_utctime(utc_time): The input *utc_time* is either a timezone unaware object assumed to be in UTC, or a timezone aware datetime object in UTC. """ - if not hasattr(utc_time, 'tzinfo') or utc_time.tzinfo is None: - return utc_time + if isinstance(utc_time, datetime): + if utc_time.tzinfo and utc_time.tzinfo != pytz.utc: + raise AttributeError("UTC time expected! Parsing a timezone aware datetime object requires it to be UTC!") + return utc_time.replace(tzinfo=None) - if utc_time.tzinfo != pytz.utc: - raise AttributeError("UTC time expected! Parsing a timezone aware datetime object requires it to be UTC!") - - return utc_time.replace(tzinfo=None) + return utc_time def kep2xyz(kep):