def find_time(start_date, new_time): start_datetime = DateTime.convert_date(start_date, result_format='datetime') time = to_time(new_time) result = start_datetime.replace(hour=time.hour, minute=time.minute, second=time.second, microsecond=time.microsecond) if time < start_datetime.time(): result += datetime.timedelta(days=1) return result
def get_bmc_date_time(): r""" Get date/time info from BMC and return as a dictionary. Example of dictionary data returned by this keyword. time_dict: [local_time]: Fri 2017-11-03 152756 UTC [local_time_seconds]: 1509740876 [universal_time]: Fri 2017-11-03 152756 UTC [universal_time_seconds]: 1509740876 [rtc_time]: Fri 2016-05-20 163403 [rtc_time_seconds]: 1463780043 [time_zone]: n/a (UTC, +0000) [network_time_on]: yes [ntp_synchronized]: no [rtc_in_local_tz]: no """ out_buf, stderr, rc = bsu.bmc_execute_command('timedatectl') # Example of output returned by call to timedatectl: # Local time: Fri 2017-11-03 15:27:56 UTC # Universal time: Fri 2017-11-03 15:27:56 UTC # RTC time: Fri 2016-05-20 16:34:03 # Time zone: n/a (UTC, +0000) # Network time on: yes # NTP synchronized: no # RTC in local TZ: no # Convert the out_buf to a dictionary. initial_time_dict = vf.key_value_outbuf_to_dict(out_buf) # For each "_time" entry in the dictionary, we will create a corresponding # "_time_seconds" entry. We create a new dictionary so that the entries # are kept in a nice order for printing. try: result_time_dict = collections.OrderedDict() except AttributeError: result_time_dict = DotDict() for key, value in initial_time_dict.items(): result_time_dict[key] = value if not key.endswith("_time"): continue result_time_dict[key + '_seconds'] = \ int(DateTime.convert_date(value, result_format='epoch')) return result_time_dict
def convert_output(value): if isinstance(value, str): return try_to_convert(value) if isinstance(value, dict): return { convert_output(k): convert_output(v) for k, v in value.items() } try: i = (convert_output(v) for v in value) except TypeError: pass else: return list(i) if isinstance(value, datetime.datetime): return DateTime.convert_date(value, result_format='timestamp') if isinstance(value, datetime.timedelta): return DateTime.convert_time(value, result_format='timer') return try_to_convert(value)
def convert_history_output(result): return [(DateTime.convert_date(date, result_format='timestamp'), int(value)) for date, value in result]
def convert_history_input(args): return [(DateTime.convert_date(args[i], result_format='timestamp'), args[i + 1]) for i in range(0, len(args), 2)]
def __convert_date(self, date): return DateTime.convert_date(date, result_format='datetime')