regebro / tzlocal

A Python module that tries to figure out what your local timezone is
MIT License
185 stars 58 forks source link

Please allow timezone in the form CET-1 #132

Closed mowgli closed 1 year ago

mowgli commented 2 years ago

My timezone (CET-1) is not able to express as Continent/City. It would be only true in the time between End of October and End of March.

There is no timezone that supports them anytime.

Even more, if I set Etc/CET it does use DST even if not expressed.

regebro commented 2 years ago

Where are you located?

CET has DST, yes. CET-1 would be the same as British time, so Europe/London should work in that case.

mowgli commented 2 years ago

Well, CET-1 in TZ environment means that CET is just a label and -1 means that you have to subtract 1 hour to get UTC.

And no, CET has NO DTS. The DST for that is CEST. CET is always one hour more than UTC, always.

I don't use Summertime for years now for health reasons. I am one of the ~10% who have massive troubles with summertime!

regebro commented 1 year ago

We all have problems with summertime, but in your case you want GMT/UTC and using that as a timezone name works just fine. I don't know why you would need to express it as CET-1, but that's not a time zone recognized in the zoneinfo database, so there isn't anything I can do to help with that.

And CET does have daylight saving.

>>> import zoneinfo
>>> import datetime
>>> zoneinfo.ZoneInfo("CET").utcoffset(datetime.datetime(2022, 1, 1))
datetime.timedelta(seconds=3600)
>>> zoneinfo.ZoneInfo("CET").utcoffset(datetime.datetime(2022, 6, 1))
datetime.timedelta(seconds=7200)

So CET-1, if it worked, would could you daylight savings time.

mowgli commented 1 year ago

Am Sa den 25. Feb 2023 um 14:26 schrieb Lennart Regebro:

We all have problems with summertime, and in your case you are on GMT/UTC. I don't know why you would need to express it as CET-1, but that's not a time zone recognized in the zoneinfo database, so there isn't anything I can do to help with that.

Well, CET-1 is a well defined content of the environment variable TZ.

POSIX[0] define this variable to hold either an defined timezone name from /usr/share/zoneinfo or a name and a offset as I used it. And more over, the name content (Europe/Berlin) is only a new addition.

I am in CET timezone (UTC + 1h) And with this setting, that does not change sommer and winter.

So, yes, tzlocal is doing it wrong!

Regards Klaus

[0] https://www.gnu.org/software/libc/manual/html_node/TZ-Variable.html -- Klaus Ethgen http://www.ethgen.ch/ pub 4096R/4E20AF1C 2011-05-16 Klaus Ethgen @.***> Fingerprint: 85D4 CA42 952C 949B 1753 62B3 79D0 B06F 4E20 AF1C

regebro commented 1 year ago

The purpose of tzlocal is to figure out the timezone, primarily the zoneinfo name, used in the configuration of your computer. You are defining your own timezone that does not exist in the zoneinfo database. That means tzlocal fails.

I guess it's possible to parse the POSIX definition and create tzinfo objects from that. If someone wants to contribute that functionality I would accept that. However, as I have never seen, nor can I imagine, any use case where this would be necessary or desireable, I'm not going to implement it myself.

Also, notably, the attempt of finding the timezone name would still fail, as the ZoneInfo objects would not support this.

Since the timezone you are configuring is the exact same one as UTC, you can simply solve this by using UTC, making this a non-issue.

mowgli commented 1 year ago

Am Sa den 25. Feb 2023 um 18:09 schrieb Lennart Regebro:

The purpose of tzlocal is to figure out the timezone, primarily the zoneinfo name, used in the configuration of your computer. You are defining your own timezone that does not exist in the zoneinfo database. That means tzlocal fails.

Well, that is the main purpose of TZ.

Since the timezone you are configuring is the exact same one as UTC, you can simply solve this by using UTC, making this a non-issue.

No, it isn't UTC. It is UTC plus one hour. It is CET whole of the year and not CEST in some months.

Regards Klaus -- Klaus Ethgen http://www.ethgen.ch/ pub 4096R/4E20AF1C 2011-05-16 Klaus Ethgen @.***> Fingerprint: 85D4 CA42 952C 949B 1753 62B3 79D0 B06F 4E20 AF1C

regebro commented 1 year ago

In ZoneInfo parlance that's Etc/GMT+1.