def convertToCDS(pyTime, timeFormat): """returns a CDS binary data unit representation of time""" days = int(pyTime) // UTIL.TIME.SECONDS_OF_DAY secsOfDay = pyTime - (days * UTIL.TIME.SECONDS_OF_DAY) milsOfDay = secsOfDay * 1000.0 mils = int(milsOfDay) milsFine = milsOfDay - mils if timeFormat == TIME_FORMAT_CDS1: mils = int(round(secsOfDay * 1000.0)) timeDU = BinaryUnit("\0" * CDS1_TIME_BYTE_SIZE, CDS1_TIME_BYTE_SIZE, CDS1_TIME_ATTRIBUTES) elif timeFormat == TIME_FORMAT_CDS2: mics = int(round(secsOfDay * 1000000.0)) mils = mics // 1000 mics %= 1000 timeDU = BinaryUnit("\0" * CDS2_TIME_BYTE_SIZE, CDS2_TIME_BYTE_SIZE, CDS2_TIME_ATTRIBUTES) timeDU.mics = mics elif timeFormat == TIME_FORMAT_CDS3: pics = int(round(secsOfDay * 1000000000000.0)) mils = pics // 1000000000 pics %= 1000000000 timeDU = BinaryUnit("\0" * CDS3_TIME_BYTE_SIZE, CDS3_TIME_BYTE_SIZE, CDS3_TIME_ATTRIBUTES) timeDU.pics = pics else: return None timeDU.days = days timeDU.mils = mils return timeDU
def convertToCDS(pyTime, hasMicro): """returns a CDS binary data unit representation of time""" # split seconds and micros secs = int(pyTime) mics = int(round((pyTime - secs) * 1000000)) # convert into CDS components days = secs / SECONDS_OF_DAY secs %= SECONDS_OF_DAY mils = (secs * 1000) + (mics / 1000) if hasMicro: mics %= 1000 timeDU = BinaryUnit("\0" * CDS2_TIME_BYTE_SIZE, CDS2_TIME_BYTE_SIZE, CDS2_TIME_ATTRIBUTES) timeDU.mics = mics else: timeDU = BinaryUnit("\0" * CDS1_TIME_BYTE_SIZE, CDS1_TIME_BYTE_SIZE, CDS1_TIME_ATTRIBUTES) timeDU.days = days timeDU.mils = mils return timeDU
def convertToCDS(pyTime, timeFormat): """returns a CDS binary data unit representation of time""" # split seconds and micros secs = int(pyTime) mics = int(round((pyTime - secs) * 1000000)) # convert into CDS components days = secs / UTIL.TIME.SECONDS_OF_DAY secs %= UTIL.TIME.SECONDS_OF_DAY mils = (secs * 1000) + (mics / 1000) if timeFormat == TIME_FORMAT_CDS1: timeDU = BinaryUnit("\0" * CDS1_TIME_BYTE_SIZE, CDS1_TIME_BYTE_SIZE, CDS1_TIME_ATTRIBUTES) elif timeFormat == TIME_FORMAT_CDS2: mics %= 1000 timeDU = BinaryUnit("\0" * CDS2_TIME_BYTE_SIZE, CDS2_TIME_BYTE_SIZE, CDS2_TIME_ATTRIBUTES) timeDU.mics = mics else: return None timeDU.days = days timeDU.mils = mils return timeDU