geomagpy / magpy

MagPy (or GeomagPy) is a Python package for analysing and displaying geomagnetic data.
BSD 3-Clause "New" or "Revised" License
45 stars 27 forks source link

wx.DateTimeFromTimeT(time.mktime(somedate.timetuple())) doesn't work correctly on windows #113

Closed stephanbracke closed 2 years ago

stephanbracke commented 2 years ago

this is linked with issue #112 and #111 If I search on the methods wx.DateTimeFromTimeT and wx.DateTime.FromTimeT I notice that they are used on several places in the gui py classes. From my current testing I saw that these cause problems on windows and the simple solution is to replace them with

This cleaning needs to be done to avoid strange behaviours on windows machines

stephanbracke commented 2 years ago

After investigation I noted that the real problem is also linked with time.mktime on windows. Behind the scenes it will use a C runtime dll and the description can be found here https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/asctime-wasctime?redirectedfrom=MSDN&view=msvc-170 Here you notice that the year parameter = Year (current year minus 1900) and also 0 based months . Anyway because we depend on the C++ library behaviour we need to avoid the use of mktime in the code base in order to have a code that works on windows

stephanbracke commented 2 years ago

Herunder a summary of the places where mktime is used (after I corrected the issues #112 and #111 ) usage_mktime It is most of the time the same thing and can easily be solved with the same approach. You can safely delete the try except code as well. It is concentrated in the files developmentpage.py and dialogclasses.py If you made the currently class method _pydate2wxdate as a global one. You could reuse this method everywhere (normally this code should work correctly, however I didn't test it)

https://github.com/geomagpy/magpy/blob/71c46c9d5debf30681e1896b53d9ddd94650eb09/magpy/gui/dialogclasses.py#L2396-L2403

leonro commented 2 years ago

All references to DateTimeFromTimeT(...mktime...) where replaced using DateTime.fromDMY. Solved with a9352b4d65f00c8be2cb196c4512934e72e9f8c0 and 429e3425fe1ad4b77830a4f5cad2b34172b02418