Skip to content

[Bug]: num2date behaves inconsistently with time zone within a container #30136

Closed as not planned
@oloapinivad

Description

@oloapinivad

Bug summary

I have a very curious problem with num2date which I am not able to understand where it comes from. It seems that when running a code snippet (which is working as expected in a conda environment) within a container on a specific machine with time zone EET, num2date introduces a 2-hour offset from UTC associated to the time zone. The weird fact is that the time seems to be the same for both machines, so I do not understand where such extra two hours is applied. it is interesting also since the date2num works fine...

Unfortunately this is partially reproducible since this is happening within a singularity container that I cannot share easily. I am wondering if such potential issues with time zones are known to show up inside containers.

It might be a feature that I am not aware but I cannot understand how to control this.

Code for reproduction

from datetime import datetime, timezone
import matplotlib.dates as mdates
import time
print("Time:", time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))
print("System timezone according to time module:", time.tzname)

original = datetime(1989, 1, 1, tzinfo=timezone.utc)
num = mdates.date2num(original)
converted = mdates.num2date(num, tz=timezone.utc)

print("Epoch:", mdates.get_epoch())
print("Original datetime:     ", original)
print("Converted to num:      ", num)
print("Back to datetime:      ", converted)

Actual outcome

On the container

Time: 2025-06-03 19:30:19
System timezone according to time module: ('EET', 'EEST')
Epoch: 1970-01-01T00:00:00
Original datetime:      1989-01-01 00:00:00+00:00
Converted to num:       6940.0
Back to datetime:       1988-12-31 22:00:00+00:00

Expected outcome

On the conda envrionment:

Time: 2025-06-03 19:30:23
System timezone according to time module: ('EET', 'EEST')
Epoch: 1970-01-01T00:00:00
Original datetime:      1989-01-01 00:00:00+00:00
Converted to num:       6940.0
Back to datetime:       1989-01-01 00:00:00+00:00

Additional information

Running matplotlib 3.10.3

Operating system

unix

Matplotlib Version

matplotlib 3.10.3

Matplotlib Backend

agg

Python version

3.12

Jupyter version

No response

Installation

conda

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions