1- # ==========================================================================
2- #
3- # Duration
4- #
5- # ==========================================================================
6-
7-
81"""Duration module."""
92
10- # ==========================================================================
11- # Place all imports after here.
12- #
133import operator
14- #
15- # Place all imports before here.
16- # ==========================================================================
174
185
19- # ==========================================================================
206class Duration (object ):
217 """Class Duration in development.
228 """
239 allowed = ["ET" , "UTC" ]
2410
25- # ----------------------------------------------------------------------
2611 def __init__ (self , frame , seconds ):
2712 """Create a new Duration object.
2813
@@ -41,31 +26,25 @@ def __init__(self, frame, seconds):
4126 self ._frame = frame
4227 self ._seconds = seconds
4328
44- # ----------------------------------------------------------------------
4529 def frame (self ):
4630 """Return the frame the duration is in."""
4731 return self ._frame
4832
49- # ----------------------------------------------------------------------
5033 def __abs__ (self ):
5134 """Return the absolute value of the duration."""
5235 return Duration (self ._frame , abs (self ._seconds ))
5336
54- # ----------------------------------------------------------------------
5537 def __neg__ (self ):
5638 """Return the negative value of this Duration."""
5739 return Duration (self ._frame , - self ._seconds )
5840
59- # ----------------------------------------------------------------------
6041 def seconds (self ):
6142 """Return the number of seconds in the Duration."""
6243 return self ._seconds
6344
64- # ----------------------------------------------------------------------
6545 def __bool__ (self ):
6646 return self ._seconds != 0
6747
68- # ----------------------------------------------------------------------
6948 def __eq__ (self , rhs ):
7049 return self ._cmp (rhs , operator .eq )
7150
@@ -97,7 +76,6 @@ def _cmp(self, rhs, op):
9776 self .checkSameFrame (rhs , "compare" )
9877 return op (self ._seconds , rhs ._seconds )
9978
100- # ----------------------------------------------------------------------
10179 def __add__ (self , rhs ):
10280 """Add two Durations.
10381
@@ -119,7 +97,6 @@ def __add__(self, rhs):
11997 self .checkSameFrame (rhs , "add" )
12098 return Duration (self ._frame , self ._seconds + rhs ._seconds )
12199
122- # ----------------------------------------------------------------------
123100 def __sub__ (self , rhs ):
124101 """Subtract two Durations.
125102
@@ -135,7 +112,6 @@ def __sub__(self, rhs):
135112 self .checkSameFrame (rhs , "sub" )
136113 return Duration (self ._frame , self ._seconds - rhs ._seconds )
137114
138- # ----------------------------------------------------------------------
139115 def __mul__ (self , rhs ):
140116 """Scale a UnitDbl by a value.
141117
@@ -147,7 +123,6 @@ def __mul__(self, rhs):
147123 """
148124 return Duration (self ._frame , self ._seconds * float (rhs ))
149125
150- # ----------------------------------------------------------------------
151126 def __rmul__ (self , lhs ):
152127 """Scale a Duration by a value.
153128
@@ -159,7 +134,6 @@ def __rmul__(self, lhs):
159134 """
160135 return Duration (self ._frame , self ._seconds * float (lhs ))
161136
162- # ----------------------------------------------------------------------
163137 def __div__ (self , rhs ):
164138 """Divide a Duration by a value.
165139
@@ -171,7 +145,6 @@ def __div__(self, rhs):
171145 """
172146 return Duration (self ._frame , self ._seconds / rhs )
173147
174- # ----------------------------------------------------------------------
175148 def __rdiv__ (self , rhs ):
176149 """Divide a Duration by a value.
177150
@@ -183,17 +156,14 @@ def __rdiv__(self, rhs):
183156 """
184157 return Duration (self ._frame , rhs / self ._seconds )
185158
186- # ----------------------------------------------------------------------
187159 def __str__ (self ):
188160 """Print the Duration."""
189161 return "%g %s" % (self ._seconds , self ._frame )
190162
191- # ----------------------------------------------------------------------
192163 def __repr__ (self ):
193164 """Print the Duration."""
194165 return "Duration('%s', %g)" % (self ._frame , self ._seconds )
195166
196- # ----------------------------------------------------------------------
197167 def checkSameFrame (self , rhs , func ):
198168 """Check to see if frames are the same.
199169
@@ -210,5 +180,3 @@ def checkSameFrame(self, rhs, func):
210180 "LHS: %s\n " \
211181 "RHS: %s" % (func , self ._frame , rhs ._frame )
212182 raise ValueError (msg )
213-
214- # ==========================================================================
0 commit comments