rmyorston / busybox-w32

WIN32 native port of BusyBox.
https://frippery.org/busybox
Other
697 stars 126 forks source link

Timezones are wrong #454

Open ale5000-git opened 2 months ago

ale5000-git commented 2 months ago

Bash online:

$ TZ='UTC' date
Thu Sep 19 03:18:14 AM UTC 2024
$ TZ='Europe/Rome' date
Thu Sep 19 05:18:14 AM CEST 2024
$ TZ='CET' date
Thu Sep 19 05:18:14 AM CEST 2024

BusyBox for Windows:

$ TZ='UTC' date
Thu Sep 19 03:18:14 UTC 2024
$ TZ='Europe/Rome' date
Thu Sep 19 04:18:14 ope 2024
$ TZ='CET' date
Thu Sep 19 03:18:14 CET 2024

There are 2 errors: the hour and the timezone string. Is it possible to fix them?

rmyorston commented 2 months ago

Yeah, Microsoft's timezone handling is a bit rubbish. It's almost as if they hadn't read POSIX properly ;-)

What sort of works is specifying the time zone in full, with offset and DST name:

~ $ date -u
Thu Sep 19 07:43:02 UTC 2024
~ $ TZ=CET-1CEST date
Thu Sep 19 09:43:04 CES 2024
~ $
ale5000-git commented 2 months ago

@rmyorston Is it possible to implement a custom code for some cases?

My idea is: if the TZ match this regexp [A-Za-z]{3,}[+-][0-9]* then use custom code and skip the windows API. Looking at bash online the letters only have a minimum limit of 3 chars but they have no maximum limit so long strings are allowed. Even a string of over 4000 chars can be displayed correctly. If the number is higher of 24 it is changed to 24. If the number is missing it is changed to 0. -1 sum 1. +1 subtract 1.

Examples:

$ TZ='AfgdfhTHTHtHhh+1' date
Thu Sep 19 04:03:37 PM AfgdfhTHTHtHhh 2024
$ TZ='ABC-' date
Thu Sep 19 05:03:37 PM ABC 2024
$ TZ='CET-1' date
Thu Sep 19 06:03:37 PM CET 2024
$ TZ='CEST-2' date
Thu Sep 19 07:03:37 PM CEST 2024