Skip to content

Commit

Permalink
Merge pull request #40 from sot/short-circuit-for-time-object
Browse files Browse the repository at this point in the history
Short circuit convert_time_format for a CxoTime object
  • Loading branch information
taldcroft authored Nov 13, 2023
2 parents 7bd474d + 47d1e30 commit 7511e59
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
5 changes: 5 additions & 0 deletions cxotime/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ def convert_time_format(val, fmt_out, *, fmt_in=None):
val_out : str
Time string in output format
"""
# If this is already a CxoTime object then return the attribute without all the
# conversion machinery.
if isinstance(val, CxoTime):
return getattr(val, fmt_out)

jd1, jd2 = None, None
if fmt_in is None:
# Get the format. For some formats the jd1/jd2 values are generated as a
Expand Down
6 changes: 6 additions & 0 deletions cxotime/tests/test_cxotime.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,3 +447,9 @@ def test_convert_functions(fmt_val, val_type, fmt_out):
out3 = func(val)
assert type(out) is type(out3)
assert np.all(out == out3)


def test_convert_time_format_obj():
"""Explicit test of convert_time_format for CxoTime object"""
tm = CxoTime(100.0)
assert tm.date == convert_time_format(tm, "date")

0 comments on commit 7511e59

Please sign in to comment.