From a76b069ccced322521345f1827873d5acfd261b8 Mon Sep 17 00:00:00 2001 From: Don Cross Date: Sun, 23 Jun 2019 17:50:13 -0400 Subject: [PATCH] Python: added astro_time_t.Utc(). Added more testing. --- generate/template/astronomy.py | 3 +++ generate/test.py | 5 +++++ source/python/astronomy.py | 3 +++ 3 files changed, 11 insertions(+) diff --git a/generate/template/astronomy.py b/generate/template/astronomy.py index 1cf42939..e5b73f68 100644 --- a/generate/template/astronomy.py +++ b/generate/template/astronomy.py @@ -168,6 +168,9 @@ class astro_time_t: n = _EPOCH + datetime.timedelta(milliseconds=millis) return '{:04d}-{:02d}-{:02d}T{:02d}:{:02d}:{:02d}.{:03d}Z'.format(n.year, n.month, n.day, n.hour, n.minute, n.second, math.floor(n.microsecond / 1000)) + def Utc(self): + return _EPOCH + datetime.timedelta(days=self.ut) + _EPOCH = datetime.datetime(2000, 1, 1, 12) def CurrentTime(): diff --git a/generate/test.py b/generate/test.py index 4bb90c1a..6d0ba263 100644 --- a/generate/test.py +++ b/generate/test.py @@ -16,6 +16,10 @@ def Test_AstroTime(): if abs(diff) > 1.0e-12: print('Test_AstroTime: excessive TT error {}'.format(diff)) sys.exit(1) + s = str(time.Utc()) + if s != '2018-12-02 18:30:12.543000': + print('Test_AstroTime: Utc() returned incorrect string "{}"'.format(s)) + sys.exit(1) time = astronomy.MakeTime(2018, 12, 31, 23, 59, 59.9994) s = str(time) if s != '2018-12-31T23:59:59.999Z': @@ -26,6 +30,7 @@ def Test_AstroTime(): if s != '2019-01-01T00:00:00.000Z': print('Test_AstroTime: expected 2019-01-01T00:00:00.000Z but found {}'.format(s)) sys.exit(1) + print('Current time =', astronomy.CurrentTime()) if len(sys.argv) == 2: if sys.argv[1] == 'time': diff --git a/source/python/astronomy.py b/source/python/astronomy.py index 69538da9..5b840e9a 100644 --- a/source/python/astronomy.py +++ b/source/python/astronomy.py @@ -259,6 +259,9 @@ class astro_time_t: n = _EPOCH + datetime.timedelta(milliseconds=millis) return '{:04d}-{:02d}-{:02d}T{:02d}:{:02d}:{:02d}.{:03d}Z'.format(n.year, n.month, n.day, n.hour, n.minute, n.second, math.floor(n.microsecond / 1000)) + def Utc(self): + return _EPOCH + datetime.timedelta(days=self.ut) + _EPOCH = datetime.datetime(2000, 1, 1, 12) def CurrentTime():