def add( self, time ): if not isinstance( time, RPNMeasurement ): ValueError( 'RPNMeasurement expected' ) if 'years' in g.unitOperators[ time.getUnitString( ) ].categories: years = convertUnits( time, 'year' ).getValue( ) return self.replace( year = self.year + years ) elif 'months' in g.unitOperators[ time.getUnitString( ) ].categories: months = convertUnits( time, 'month' ).getValue( ) return self.incrementMonths( months ) else: days = int( floor( convertUnits( time, 'day' ).getValue( ) ) ) seconds = int( fmod( floor( convertUnits( time, 'second' ).getValue( ) ), 86400 ) ) microseconds = int( fmod( floor( convertUnits( time, 'microsecond' ).getValue( ) ), 1000000 ) ) try: return self + datetime.timedelta( days = days, seconds = seconds, microseconds = microseconds ) except OverflowError: print( 'rpn: value is out of range to be converted into a time' ) return nan
def convertToYDHMS( n ): return convertUnits( n, [ RPNMeasurement( 1, { 'year' : 1 } ), RPNMeasurement( 1, { 'day' : 1 } ), RPNMeasurement( 1, { 'hour' : 1 } ), RPNMeasurement( 1, { 'minute' : 1 } ), RPNMeasurement( 1, { 'second' : 1 } ) ] )