AndrewWPhillips / HexEdit

Binary file editor for Windows
MIT License
173 stars 62 forks source link

21st century date strings are wrongly converted to 20th century #3

Closed AndrewWPhillips closed 8 years ago

AndrewWPhillips commented 8 years ago

Steps to reproduce

  1. Ensure Windows short date format has a two digit year. Eg: In Control Panel/Region and Language/Formats/Short Date use: dd/MM/yy
  2. Open Calculator in HexEdit and clear it. Ensure that decimal mode is in use.
  3. Enter "now()" into the calculator & click = button to see a date like DATE("16/07/16 08:00:00")
  4. Cut this result to the clipboard (Ctrl+A then Ctrl+X).
  5. Enter "test=" into the calculator and paste the previous result (Ctrl+V) & click = button
  6. Enter "test + 36525" into the calculator to add about 100 years to test. Note: date/time variables are stored as floating point in whole days Note 2: If you are not in decimal mode (eg hex) 36525 will not be treated as a decimal integer
  7. The result shown is 16/07/2016 showing that the test variable stores the date 16/07/1916.
AndrewWPhillips commented 8 years ago

The problem is that parsing a date string with a 2 digit year using time_get::get_date produces a date in the range 1900-1999. This may be a bug in the MS CRT (I am using VC++ 2010) - I was under the impression that it should return values in the range 1970-2069 for a 2 digit year.

However, to avoid this problem I have changed the code to always create a 4 digit year irrespective of the Windows short date format. To do this (not easy) we get the Windows short date format (eg mm/dd/yy) and convert it (eg mm/dd/yyyy) before calling Windows system call "GetDataFormat" - see the new function FormatDate in misc.cpp. If the Windows short date format already has a 4 digit year (eg dd/mm/yyyy) the the old code (strftime) is used.

This fix appears in build number (Git checkin) 1347. (To see the build number hold down shift while opening the About box in HexEdit.)