1

Situation

It appears to me that my timezone is configured correctly because with

[nix-shell:~]$ date +"%T %Z"
19:49:07 CET

I get what I expect.

But with lua's lgi library I am appearently using Daylight Saving Time,whereas the normal lua functions honour the system settings:

[nix-shell:~]$ lua
Lua 5.2.4  Copyright (C) 1994-2015 Lua.org, PUC-Rio
> for k,v in pairs(os.date("*t")) do print(k,v) end
isdst   false
sec 31
min 51
month   11
day 12
hour    19
yday    317
wday    5
year    2020
> glib=require"lgi".GLib
> return glib.DateTime.new_now(glib.TimeZone.new()):format("%F %T %Z")
2020-11-12 20:51:52 CEST

Question

Where and how can I make lgi honour my systems timezone/DST settings?

Background

lgi is used by awesome WM for the clock widget, so I want it to be correct.

Lucas
  • 685
  • 4
  • 19

2 Answers2

1

.new_local() calls .new() with the correct TZ env variable inside.

https://developer.gnome.org/glib/stable/glib-GTimeZone.html#g-time-zone-new

return glib.DateTime.new_now(glib.TimeZone.new_local()):format("%F %T %Z")

just make sure your TZ environment var is set properly.

https://www.cyberciti.biz/faq/linux-unix-set-tz-environment-variable


you'd think AwesomeWM would figure timezones out automatically, but who knows... OS.date is reporting that you're off DST properly, so would this do it?

if os.date('*t').isdst then
    wibox.widget.textclock( timezone='CEST' )
else
    wibox.widget.textclock( timezone='CET' )
end
Doyousketch2
  • 2,060
  • 1
  • 11
  • 11
  • The TZ variable is not relevant according to the docs you link. And my region is also correctly detected because /etc/localtime is the same as /etc/zoneinfo/Europe/Berlin (the docs you link also say NULL/nil as time zone argument is ok. My problem is that lgi assumes DST when it should not. – Lucas Nov 12 '20 at 21:25
  • It literally says: `g_time_zone_new_local() calls this function with the value of the TZ environment variable.` – Doyousketch2 Nov 12 '20 at 22:04
  • Yea but I am using code by awesome that does not use g_time_zone_new_local but g_time_zone_new directly and additionally my TZ env var is unset so it results in the same (null as argument to g_time_zone_new). – Lucas Nov 12 '20 at 22:28
  • PS: If I do set `TZ=Europe/Berlin` in the env before starting lua, I still get CEST as timezone instead of CET as I think I should. – Lucas Nov 12 '20 at 22:33
  • With `%z` instead of `%Z` I get `+0200` instead of `CEST` (but `date +%z` gives me the correct `+0100`). If I specify `"UTC"` to `glib.TimeZone.new` it correctly prints the time in UTC but if I give it `"CET"` it still prints CEST! – Lucas Nov 12 '20 at 23:21
  • https://en.wikipedia.org/wiki/Daylight_saving_time#IANA_time_zone_database shows it written as `TZ=':America/New_York'` I'd try writing it like that, might also need to log out or reboot so it has effect. – Doyousketch2 Nov 12 '20 at 23:28
0

In my particular case my distribution did make a "mistake" when updating the zoneinfo file:

The problem was that the tzdata package did change the file format but the application (in my case aswesome WM) did not support the new format.

The solution was from the distribution was to install the new data files in the old format.

Lucas
  • 685
  • 4
  • 19