bugfixing

This commit is contained in:
MuslemRahimi 2025-01-02 22:22:01 +01:00
parent d0cf246066
commit ef5945715c

View File

@ -49,27 +49,30 @@ def convert_timestamps(data_list):
for item in data_list: for item in data_list:
try: try:
# First, handle the microseconds by splitting on '.' # Get the timestamp and split on '.'
timestamp = item['timestamp'] timestamp = item['timestamp']
base_time = timestamp.split('.')[0] base_time = timestamp.split('.')[0]
# If there are microseconds, add them back in the correct format # Handle microseconds if present
if '.' in timestamp: if '.' in timestamp:
microseconds = timestamp.split('.')[1].replace('Z', '') microseconds = timestamp.split('.')[1].replace('Z', '')
# Pad with zeros if needed microseconds = microseconds.ljust(6, '0') # Pad with zeros if needed
microseconds = microseconds.ljust(6, '0')
base_time = f"{base_time}.{microseconds}" base_time = f"{base_time}.{microseconds}"
# Replace 'Z' with '+00:00' for UTC # Replace 'Z' with '+00:00' (for UTC)
base_time = base_time.replace('Z', '+00:00') base_time = base_time.replace('Z', '+00:00')
# Parse the timestamp # Parse the timestamp
dt = datetime.fromisoformat(base_time) dt = datetime.fromisoformat(base_time)
# Convert to New York timezone # Ensure the datetime is timezone-aware (assumed to be UTC initially)
if dt.tzinfo is None:
dt = pytz.utc.localize(dt)
# Convert the time to New York timezone (automatically handles DST)
ny_time = dt.astimezone(ny_tz) ny_time = dt.astimezone(ny_tz)
# Format the timestamp # Optionally, format to include date and time
item['timestamp'] = ny_time.strftime('%Y-%m-%d %H:%M:%S') item['timestamp'] = ny_time.strftime('%Y-%m-%d %H:%M:%S')
except ValueError as e: except ValueError as e: