Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Daylight saving time causes timestamp display error when viewing data present time of DST not active when data is from date when DST active #1111

Open
mark-lunar opened this issue Dec 5, 2024 · 0 comments

Comments

@mark-lunar
Copy link

Python version

('python=3.11.9 (tags/v3.11.9:de54cf5, Apr 2 2024, 10:12:12) [MSC v.1938 64 '
'bit (AMD64)]')
'os=Windows-10-10.0.22631-SP0'
'numpy=1.26.4'
'asammdf=8.0.1'

Code

MDF version

4.10

Code snippet

    from zoneinfo import ZoneInfo
    
    # Define time zones
    pacific = ZoneInfo("America/Los_Angeles")
    utc = ZoneInfo("UTC")
    
    # Localize to Pacific Time (DST-aware)
    first_timestamp =(group_df['Time'].iloc[0]).to_pydatetime()
    utc_timestamp = first_timestamp.replace(tzinfo=utc)
    
    # Convert to UTC
    localized_timestamp = utc_timestamp.astimezone(pacific)
    mdf.start_time = localized_timestamp #group_df['Time'].iloc[0]
    print(f"Setting MDF start time to local timezone: {mdf.start_time}")

    # Save MF4 file

    mdf.save(mf4_path, compression=2, overwrite=True)
    print(f"File saved: {mf4_path}")
    mdf.close()

Traceback

No error thrown, but GUI visualization is incorrect

Description

Data was collected from 9/23/2024 when daylight saving time was active
The present date is 12/5/2024 when daylight saving time is over

When using the above code to assign the mdf.start_time to the file prior to saving the file under these conditions, the date is saved and mf4 file is opened in the Asammdf GUI 8.0.1. When reviewing the timestamp for a single signal on the graph, the first timestamp of the signal is shown under the variable legend window and also able to be read directly from the graph. In this isntance, the legend timestamp shows 2024-09-23 16:41:37.817182-07:00. This is the correct timestamp for the time the data was collected with the correct offset to GMT. The x-axis of the graph shows the first signal offset by 1 hour from the legend timestamp where the x-axis is showing 2024-09-23 15:41:37.81718264-08:00 which is not the correct time.

DST ended on November 3, 2024

If I use the following command mdf.start_time = datetime.datetime(2024, 11, 4, 14, 47, 5, 667648) to arbitrarily set the mdf.start_time to a date after DST ended, I show that the GUI plot will properly show a matching timestamp between the legend and x-axis if the date is set after DST ends with no 1 hour offset.

If I use the following command mdf.start_time = datetime.datetime(2024, 11, 2, 14, 47, 5, 667648) to arbitrarily set the mdf.start_time to a date before DST ending, this confirms the legend timestamp and the x-axis timestamp are different by 1 hour.

The data appears to be properly stored in the mdf file. The GUI is ignoring DST and showing the x-axis relative to GMT without adjustment for daylight saving time. I am not sure if this is intended. I can see an instance where plotting data from October to December would include the DST ending, but not sure how the data would be represented in the plot.

Image showing the 1 hour offset between legend and x-axis timestamps when having a start time prior to DST ending and current date of plot generation after DST ended.

Screenshot 2024-12-05 131128

The same data is plotted again, but after running the following command for the start_time. This shows a perfect match between legend and x-axis start time
mdf.start_time = (datetime.datetime(2024, 12, 2, 14, 47, 5, 667648)).astimezone(pacific)

Screenshot 2024-12-05 133439

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant