extends Node var latest_sensor_timestamp: float = 0 var sys_time_at_sensor_time: float = 0 func on_time_data_received(timestamp_list: Array): latest_sensor_timestamp = 3600.*timestamp_list[0] + 60.*timestamp_list[1] + timestamp_list[2] + timestamp_list[3] sys_time_at_sensor_time = utc_timestamp_24h() func get_current_sensor_time(): var sys_time = utc_timestamp_24h() var sys_time_diff = calc_time_diff_24h(sys_time_at_sensor_time, sys_time) var sensor_time = latest_sensor_timestamp + sys_time_diff if sensor_time >= 86400: return sensor_time - 86400 return sensor_time func calc_time_diff_24h(timestamp_1, timestamp_2): if timestamp_2 < 3600 and timestamp_1 > 82800: return (timestamp_2 + 86400) - timestamp_1 return timestamp_2 - timestamp_1 func is_timestamp_newer_24h(old_timestamp: float, new_timestamp: float) -> bool: if old_timestamp > 82800. and new_timestamp < 3600: # earlier than 23 hours return true return old_timestamp < new_timestamp func utc_timestamp_24h(): var time_dict = Time.get_time_dict_from_system(true) var unix_time = Time.get_unix_time_from_system() return time_dict["hour"] * 3600 + time_dict["minute"] * 60 + time_dict["second"] + (unix_time - int(unix_time))