Skip to content

DateTime.FromTimeT() generates invalid dates #1910

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

Closed
StokesMIDE opened this issue Jan 28, 2021 · 9 comments · Fixed by #1912
Closed

DateTime.FromTimeT() generates invalid dates #1910

StokesMIDE opened this issue Jan 28, 2021 · 9 comments · Fixed by #1912

Comments

@StokesMIDE
Copy link

Operating system: Windows 10 (build 10.0.18363)
wxPython version & source: 4.1.1 from PyPI
Python version & source: Stock 3.7.4 and stock 3.9.1

Description of the problem:
DateTime.FromTimeT() is failing in Python 3.7.4 and 3.9.1. The results are slightly different, although that may simply be the reporting; it looks like the same root problem.

In 3.7.4, the method executes, but generates bad values (equivalent Python datetime used to show expected behavior):

>>> import datetime, wx
>>> datetime.datetime.fromtimestamp(1611851055)
datetime.datetime(2021, 1, 28, 11, 24, 15)
>>> wx.DateTime.FromTimeT(1611851055)
<wx.DateTime: "Fri Dec 16 17:16:15 59183">

In 3.9.1, the same call to wx.DateTime.FromTimeT() produces a series of wxPython Debug Alert dialogs before the Python interpreter shuts down:
FromTimeT-1
FromTimeT-2
FromTimeT-3

In 3.7.4, the wx,DateTime.FromTimeT() results are the same whether a wx.App is running or not. In 3.9.1, the debug alerts only show up if a wx.App has not been instantiated; without it, the interpreter simply shuts down.

I can't verify it at the moment, but I believe DateTime.FromTimeT() was working in wxPython 4.0.7; I skipped 4.1.0.

@swt2c
Copy link
Collaborator

swt2c commented Jan 29, 2021

This might be a Windows-specific problem. I don't see any problems on Linux.

I wonder if this is related to the Locale issues on Windows with 4.1.x?

@swt2c
Copy link
Collaborator

swt2c commented Jan 29, 2021

Scratch that about the Locale issues - don't think it's related.

Still could be Windows specific though. Are you using 32-bit or 64-bit Python on Windows?

@StokesMIDE
Copy link
Author

This may well be Windows-specific; I could not reproduce it on MacOS.

I'm using the 64b Python: Python 3.9.1 (tags/v3.9.1:1e5d33e, Dec 7 2020, 17:08:21) [MSC v.1927 64 bit (AMD64)] on win32.

@RobinD42
Copy link
Member

RobinD42 commented Jan 29, 2021

It looks like there may be something going on with converting to the C time_t type. The same thing is happening with the Set(time_t) method. I'm taking a closer look now.

@StokesMIDE
Copy link
Author

StokesMIDE commented Jan 29, 2021

FWIW, it seems to act like the start of the epoch is wrong. The dates are far future, but seem consistent with the value entered.

>>> wx.DateTime.FromTimeT(0)
<wx.DateTime: "Mon Dec  2 05:12:16 55185">
>>> wx.DateTime.FromTimeT(1)
<wx.DateTime: "Mon Dec  2 05:12:17 55185">

@RobinD42
Copy link
Member

I had an incorrect typedef, so on Windows where long is a 32-bit value half of the time_t bits were being dropped. Fix is on the way.

@VolkerSiep
Copy link

I have a similar observation. The following code

from datetime import datetime
import wx   

tick = 1664478821  # 29.9.2022 21:13:41
print(datetime.fromtimestamp(tick))
print(wx.DateTime().FromTimeT(tick))

generates

2022-09-29 21:13:41
Sat Feb 22 01:42:13 79873

Packages:
python 3.10.6 h9a09f29_0_cpython conda-forge
wxpython 4.1.1 py310h494077a_7 conda-forge

I'm on a Windows 10 PC with miniconda installation.

@Jalkhov
Copy link

Jalkhov commented Jan 26, 2023

Something new about this? I am having similar problem with following code:

import wx

dt = wx.DateTime(29, 1, 2023)

Got this alert

imagen

I am on Windows 10

@swt2c
Copy link
Collaborator

swt2c commented Jan 26, 2023

@Jalkhov, the month parameter actually an enumeration, not 1-12 for Jan-Dec. So, 1 is actually February. February 29 doesn't exist in 2023.

>>> import wx
>>> wx.DateTime.Month.Feb
1
>>> 

It is a bit strange, I know.

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

Successfully merging a pull request may close this issue.

5 participants