Beispiel #1
0
def getRoot( n, k ):
    if isinstance( n, RPNMeasurement ):
        if not isInteger( k ):
            raise ValueError( 'cannot take a fractional root of a measurement' )

        newUnits = RPNUnits( n.getUnits( ) )

        for unit, exponent in newUnits.items( ):
            if fmod( exponent, k ) != 0:
                if k == 2:
                    name = 'square'
                elif k == 3:
                    name = 'cube'
                else:
                    name = getOrdinalName( k )

                raise ValueError( 'cannot take the ' + name + ' root of this measurement: ', n.getUnits( ) ) #print measurement RPNMeasurement.getValue( ) )

            newUnits[ unit ] /= k

        value = root( n.getValue( ), k )

        return RPNMeasurement( value, newUnits )

    return root( n, k )
Beispiel #2
0
def getBahaiCalendarDateName( n ):
    if not isinstance( n, RPNDateTime ):
        raise ValueError( 'time type required for this operator' )

    date = bahai.from_gregorian( n.year, n.month, n.day )

    result = bahaiDays[ n.weekday( ) ] + ', ' + bahaiMonths[ date[ 1 ] - 1 ] + \
           ' ' + str( date[ 2 ] ) + ', '

    print( date )

    if date[ 0 ] >= 1:
        result += 'Year ' + bahaiYears[ date[ 0 ] % 19 - 1 ] + ' of the ' + \
                  getOrdinalName( ( date[ 0 ] / 19 ) + 1 ) + ' Vahid of the ' + \
                  getOrdinalName( ( date[ 0 ] / 361 ) + 1 ) + ' Kull-i-Shay\'' + \
                  ' (Year ' + str( date[ 0 ] ) + ')'
    else:
        result += str( date[ 0 ] )

    return result