Skip to content

Commit a4b8041

Browse files
committed
added support for passing a Time object into Time initializer
1 parent 9356d40 commit a4b8041

1 file changed

Lines changed: 18 additions & 2 deletions

File tree

‎astropy/time/core.py‎

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,9 @@ class Time(object):
6464
6565
Parameters
6666
----------
67-
val : sequence, str, or number
68-
Value(s) to initialize the time or times
67+
val : sequence, str, number, or `~astropy.time.Time` object
68+
Value(s) to initialize the time or times. If a `Time` object,
69+
a simple copy will be made (or a deep copy if `copy` is True).
6970
val2 : sequence, str, or number; optional
7071
Value(s) to initialize the time or times
7172
format : str, optional
@@ -95,6 +96,21 @@ class Time(object):
9596
def __init__(self, val, val2=None, format=None, scale=None,
9697
precision=None, in_subfmt=None, out_subfmt=None,
9798
lat=0.0, lon=0.0, copy=False):
99+
100+
# if the first input is a Time object, copy the attributes and don't do
101+
# any of the parsing. Copy the values if possible when `copy` is True
102+
if isinstance(val, self.__class__):
103+
if copy:
104+
for attrname, attrvalue in val.__dict__.iteritems():
105+
if hasattr(attrvalue, 'copy'):
106+
setattr(self, attrname, attrvalue.copy())
107+
else:
108+
setattr(self, attrname, attrvalue)
109+
else:
110+
for attrname, attrvalue in val.__dict__.iteritems():
111+
setattr(self, attrname, attrvalue)
112+
return
113+
98114
self.lat = lat
99115
self.lon = lon
100116
if precision is not None:

0 commit comments

Comments
 (0)