`os.date` does not format times correctly.
Closed this issue · 6 comments
Bug: os.date
do not return the right time.
Example:
-- A file to be run by rlua
local formatted_time = os.date("It is %A %d %B %Y, at %I %M %p")
print(formatted_time)
Expected output: It is Wednesday 27 May 2020, at 2 24 pm
(currently)
Actual output: It is Wednesday 27 May 2020, at 10 24 pm
It works properly in lua.exe
:
$ lua
Lua 5.3.5 Copyright (C) 1994-2018 Lua.org, PUC-Rio
> = os.date("It is %A %d %B %Y, at %I %M %p")
It is Wednesday 27 May 2020, at 02 25 PM
>
However, os.time()
works properly:
-- Here's my best attempt at activating them at the same time.
-- rlua
os.time() --> 1590614826
-- lua.exe
os.time() --> 1590614829
I just tried this myself and I get the same It is Wednesday 27 May 2020, at 04 50 PM
both with rlua and just running the lua
repl on my linux machine.
My first guess is that you have some sort of timezone issue. I'd suggest you try running both with os.date("!It is %A %d %B %Y, at %I %M %p")
(note the !
at the beginning) to try printing formatted in UTC. Based on the fact that os.time() is correct, those should output the same value.
Assuming they do it's most likely some os-level config for timezone. Unfortunately, I'm not going to be much help for configuring that on windows, but some more information could be helpful. Like, are you running this in WSL or compiling natively to windows? If you're using WSL I'd trying running date
from the WSL shell and see if that time is correct.
Otherwise more context about how you're running rlua or a minimal reproduction would be helpful.
The !
at the beginning doesn't help, unfortunately. Currently it's 3:37; with the bang it says 10:37 and without it says 11:37.
I'm compiling natively to windows using cygwin.
I'm making a voice-activated digital assistant, like Alexa. You can check out the source code here! https://github.com/gamma-delta/mega 😛
Edit: I should mention my computer's time itself is fine. Or at least, it matches my phone. (If they are both wrong then we have bigger problems...)
The ! at the beginning doesn't help, unfortunately. Currently it's 3:37; with the bang it says 10:37 and without it says 11:37.
Are those both within rlua? I was suggesting you try with the !
both in rlua and in the native lua repl to see if those match.
I don't know much about cygwin either, does that have a shell where you can run date
and see what time it thinks it is/what timezone it's using?
It sounds like the timezone set in windows isn't making it into cygwin.
This might be helpful: https://cygwin.com/cygwin-ug-net/tzset.html
Cywin is like a Linux shell for Windows. It's not like WSL though, it just looks like Linux. AFAIK it's just an advanced terminal with a lot of abstractions to make it feel Linuxy.
date
works properly:
$ date
Wed, May 27, 2020 4:14:33 PM
The experiments with !
were in rlua. The native lua repl says It is Wednesday 27 May 2020, at 11 16 PM
with a bang; it;'s 4:16 now.
Well, it works in the native Windows console. Maybe Cygwin is just being weird... but date
works. I dunno.
At least it't not a problem with rlua. Sorry!