Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Could not get current timezone on WSL (Windows Subsystem for Linux) #102

Closed
qis opened this issue Nov 19, 2016 · 11 comments
Closed

Could not get current timezone on WSL (Windows Subsystem for Linux) #102

qis opened this issue Nov 19, 2016 · 11 comments

Comments

@qis
Copy link
Contributor

qis commented Nov 19, 2016

Windows 10 Bash on Ubuntu on Windows issue.

When the function date::current_zone() is called, tz.cpp throws the runtime error "Could not get current timezone". Here are the problems:

  • The file /etc/localtime is not a symlink.
  • The file /etc/timezone does not exist.
  • The file /etc/sysconfig/clock does not exist.
  • There is no file in /usr/share/zoneinfo that matches /etc/localtime.

Can somebody confirm that this is always the case or do I have a broken system?

qis@core ~ file /etc/localtime
/etc/localtime: timezone data, version 2, 2 gmt time flags, 2 std time flags, no leap seconds, 64 transition times, 2 abbreviation chars
qis@core ~ file /etc/timezone
/etc/timezone: ERROR: cannot open `/etc/timezone' (No such file or directory)
qis@core ~ file /etc/sysconfig/clock
/etc/sysconfig/clock: ERROR: cannot open `/etc/sysconfig/clock' (No such file or directory)
qis@core ~ find /usr/share/zoneinfo/ -type f -exec diff /etc/localtime '{}' ';' | grep -v 'differ$'
# no output
@qis qis changed the title Could not get current timezone on WSL (Windows Subsystem for Linux or Bash on Windows) Could not get current timezone on WSL (Windows Subsystem for Linux) Nov 19, 2016
@HowardHinnant
Copy link
Owner

HowardHinnant commented Nov 19, 2016

Wow, looks like you're on the bleeding edge! I had not even heard of this platform. Thanks for the excellent description of the problem!

You are the first to try to run tz on this platform. Just skimming their docs the only thing I'm picking up is in the release notes (https://msdn.microsoft.com/en-us/commandline/wsl/release_notes) it says:

Add current Windows timezone data and set as default

I find myself wondering if the Windows version of current_zone() needs to be used (that under #ifdef _WIN32). Fixing this may be as easy as finding the write macro to choose the Windows implementation of current_zone() in tz.cpp.

Currently it looks like you're in the driver's seat for getting this ported, and that would be much appreciated!

More clues, but not a clear answer: microsoft/WSL#856

@qis
Copy link
Contributor Author

qis commented Nov 19, 2016

Currently I see only two solutions: replace the file with a symlink or parse it manually. Since this platform is targeted at developers, the first option seems to be the right way to solve the problem and wait for Microsoft to fix it. I've reported it.

rm /etc/localtime
ln -s /usr/share/zoneinfo/Europe/Berlin /etc/localtime

This seems to persist through a reboot but dpkg-reconfigure tzdata will replace the symlink with a real file.

@HowardHinnant
Copy link
Owner

Does /etc/localtime contain text that indicates the name of the current time zone?

@qis
Copy link
Contributor Author

qis commented Nov 19, 2016

I don't think so. This is what zdump can print out:

qis@core ~ zdump /etc/localtime.orig
/etc/localtime.orig  Sat Nov 19 23:11:40 2016 STD
qis@core ~ zdump -v /etc/localtime.orig 
/etc/localtime.orig  -9223372036854775808 = NULL
/etc/localtime.orig  -9223372036854689408 = NULL
/etc/localtime.orig  Sun Mar 26 00:59:59 2006 UT = Sun Mar 26 01:59:59 2006 STD isdst=0 gmtoff=3600
/etc/localtime.orig  Sun Mar 26 01:00:00 2006 UT = Sun Mar 26 03:00:00 2006 DST isdst=1 gmtoff=7200
# === 1972 more lines ===
/etc/localtime.orig  Sun Oct 25 00:59:59 2499 UT = Sun Oct 25 02:59:59 2499 DST isdst=1 gmtoff=7200
/etc/localtime.orig  Sun Oct 25 01:00:00 2499 UT = Sun Oct 25 02:00:00 2499 STD isdst=0 gmtoff=3600
/etc/localtime.orig  9223372036854689407 = NULL
/etc/localtime.orig  9223372036854775807 = NULL
qis@core ~ strings /etc/localtime.orig
TZif2
TZif2
STD-1DST,M3.5.0/2:00:00,M10.5.0/3:00:00

Edit: Added strings output.

@HowardHinnant
Copy link
Owner

I see, thanks. That is almost useless for getting the current zone. We could get the approximate offset and abbreviation, but that's not enough to nail down the zone.

If you force the _WIN32 version of current_zone(), does it compile?

@HowardHinnant
Copy link
Owner

Nice bug report. I'll be anxious to see a response.

@qis
Copy link
Contributor Author

qis commented Nov 19, 2016

I'm not aware of a way to call Win32 APIs from within the bash environment. One could check the tzutil /g output but I don't have the new Windows 10 build that allows interop.

qis@core ~ /mnt/c/Windows/System32/tzutil.exe /g
bash: /mnt/c/Windows/System32/tzutil.exe: cannot execute binary file: Exec format error

Will respond again if I find something.

Edit: No solution in sight. Probably best to fix the WSL installation manually and let MS deal with it.

@NoSubstitute
Copy link

afaik, this is still not fixed on WSL install, but your fix is the correct way of fixing it.
Running dpkg-reconfigure tzdata will remove the broken file, setup a symlink and create /etc/timezone.
IT doesn't fix the missing /etc/sysconfig/clock though.

@eric-wieser
Copy link

@mattjohnsonpint
Copy link

See also microsoft/WSL#3747

@HowardHinnant
Copy link
Owner

Not to be fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants