Closed Rayman256 closed 1 year ago
Should be possible after they take a look at my example of working timezone code at https://github.com/martinet101/ElevenClock/issues/1018#issuecomment-1330063502 and https://github.com/martinet101/ElevenClock/issues/989#issuecomment-1330150676
(actually, most up-to-date info is below)
@martinet101, to make timezone selection easier on those that want to use them, you'll probably want to use/integrate a, or make your own, map timezone picker like https://github.com/jannikmi/timezonefinder (and functionally would kinda feel like this https://kevinnovak.github.io/Time-Zone-Picker/)
And as for how to include it as formatting in the time date formatter,
I'd suggest doing it in the same way that linux uses temporary changes to environment variables... e.g. you can specify the change in timezone by putting the changed environment variable at the start of a command (e.g. TZ=America/Los_Angeles date +"%I:%M %p %Z (%z)"
would produce 11:19 PM PST (-0800)
So, likewise, for the formatter, you could use something like the following:
TZ=TIMEZONE_HERE [rest of the formatting here]
(timezone can NEVER have spaces, at least on linux)TZ=America/Los_Angeles %I:%M %p %Z (%z)
11:19 PM PST (-0800)
Also, did more research, and found that there's more official python packages that can be used before having to resort to third parties, which means the following packages can be avoided: pytz
(no need to install or import), dateutil
(no need to install or import, unless you're using it for other things besides timezones), win_tz
(this stagnate file is useless when tzlocal
could be installed and auto updated on each new build):
# Python Official, included with 3.9+, zoneinfo is Python's own official timezone database for datetime and etc.
import datetime, zoneinfo
# Python Official, needs to be installed; tzdata is for devices lacking IANA timezones (populates zoneinfo on Windows)
import tzdata # $ pip install tzdata
# third-party, but only used for the soul purpose of "translating" the Windows local timezone to IANA local timezone
import tzlocal # $ pip install tzlocal
LOCAL_TIMEZONE = tzlocal.get_localzone_name()
dateTimeFormat = "%I:%M %p %Z (%z)"
# timezones
# NOW = None
# NOW_TZ = Uses system local timezone string
local = zoneinfo.ZoneInfo(LOCAL_TIMEZONE) # avoid `tzlocal.get_localzone()` (creates a pytz shim, waste of resources)
utc = datetime.timezone.utc
portland = zoneinfo.ZoneInfo('America/Los_Angeles')
egypt = zoneinfo.ZoneInfo('Africa/Cairo')
amazonas = zoneinfo.ZoneInfo('America/Manaus')
armenia = zoneinfo.ZoneInfo('Asia/Tbilisi')
# not timezone aware
now = datetime.datetime.now() # by default timezone data isn't included in datetime
# is timezone aware (lets `%z` and `%Z` work)
nowTZ = datetime.datetime.now().astimezone()
nowLocal = now.astimezone(local)
nowUTC = now.astimezone(utc)
nowPortland = now.astimezone(portland)
nowEgypt = now.astimezone(egypt)
nowAmazonas = now.astimezone(amazonas)
nowArmenia = now.astimezone(armenia)
# now use strftime to format times
time = now.strftime(dateTimeFormat)
timeTZ = nowTZ.strftime(dateTimeFormat)
timeLocal = nowLocal.strftime(dateTimeFormat)
timeUTC = nowUTC.strftime(dateTimeFormat)
timePortland = nowPortland.strftime(dateTimeFormat)
timeEgypt = nowEgypt.strftime(dateTimeFormat)
timeAmazonas = nowAmazonas.strftime(dateTimeFormat)
timeArmenia = nowArmenia.strftime(dateTimeFormat)
print("Results formated as ====>",dateTimeFormat)
print("")
print("Now -------------------->",time)
print("Now (with OS timezone) ->",timeTZ)
print("")
print("<= Forcing use of IANA =>")
print("Local timezone --------->",timeLocal)
print("In UTC ----------------->",timeUTC)
print("Portland, Oregon ------->",timePortland)
print("Egypt, Africa ---------->",timeEgypt)
print("Amazonias, Brazil ------>",timeAmazonas)
print("Armenia, Asia ---------->",timeArmenia)
This shows the results properly working, with the original implementations as the top two.
Results formated as ====> %I:%M %p %Z (%z)
Now --------------------> 03:13 AM ()
Now (with OS timezone) -> 03:13 AM Pacific Standard Time (-0800)
<= Forcing use of IANA =>
Local timezone ---------> 03:13 AM PST (-0800)
In UTC -----------------> 11:13 AM UTC (+0000)
Portland, Oregon -------> 03:13 AM PST (-0800)
Egypt, Africa ----------> 01:13 PM EET (+0200)
Amazonias, Brazil ------> 07:13 AM -04 (-0400)
Armenia, Asia ----------> 03:13 PM +04 (+0400)
And, this would prevent the need to worry about using any other timezone types other than what's listed from
print(zoneinfo.available_timezones())
Which results in the following list of available timezones
I'll take a look at this.
I guess there shoud be no issue while implementing this feature, but I had issues with timezones before
Due to the technical diffculty and the need of a complete rewrite of the base code, this feature will not be worked on
Yeah... I would have added it myself, the timezone capabilities at least (not necessarily the tooltip portion noted here)... but I guess you noticed the same thing that I did, in that your code is a bit all over the place regarding the time control/formatting.
However, does this mean that a rewrite is being thought about and/or in the works @marticliment ?
To be honest, the whole code is a mess, and it needs a serious rewrite.
It will come, but maybe not soon, since my free time is currently quite limited, and I also have other projects I maintain.
Windows seems to be limited to setting up and showing 2 additional time zones, e.g., when hovering over the clock. It would be useful if you could find a way to hold and show more, i.e., so that the tool tip would be expanded to show 3, 4 or more additional time zones