From 107a07223bc8e523626f3e7dfb7598e77b112d06 Mon Sep 17 00:00:00 2001 From: Don Cross Date: Tue, 5 May 2020 21:40:55 -0400 Subject: [PATCH] Python: added repr() support for astronomy.Time class. Now when a Time object is evaluated and represented in the Python interpreter, it results in a string of the form: astronomy.Time(ut) where ut is the numeric representation of the ut field. This mimics the exact way such a Time value could be constructed. That is, eval(repr(t)) results in a time value equal to t. --- generate/template/astronomy.py | 3 +++ source/python/astronomy.py | 3 +++ 2 files changed, 6 insertions(+) diff --git a/generate/template/astronomy.py b/generate/template/astronomy.py index 9414833a..a00308cc 100644 --- a/generate/template/astronomy.py +++ b/generate/template/astronomy.py @@ -462,6 +462,9 @@ class Time: """ return Time(self.ut + days) + def __repr__(self): + return 'astronomy.Time(' + repr(self.ut) + ')' + def __str__(self): millis = round(self.ut * 86400000.0) n = _EPOCH + datetime.timedelta(milliseconds=millis) diff --git a/source/python/astronomy.py b/source/python/astronomy.py index 8e3fb585..4009c040 100644 --- a/source/python/astronomy.py +++ b/source/python/astronomy.py @@ -553,6 +553,9 @@ class Time: """ return Time(self.ut + days) + def __repr__(self): + return 'astronomy.Time(' + repr(self.ut) + ')' + def __str__(self): millis = round(self.ut * 86400000.0) n = _EPOCH + datetime.timedelta(milliseconds=millis)