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

DST issue when winter is coming #36

Open
oktoberfest6 opened this issue Oct 14, 2023 · 1 comment
Open

DST issue when winter is coming #36

oktoberfest6 opened this issue Oct 14, 2023 · 1 comment

Comments

@oktoberfest6
Copy link

Hi,

First of all, congratulations for this excellent module which greatly simplifies the use of dates in Lua.

I'm writing a timestamp -> iso8601 converter using this module and I'm having a problem when the clock switches from summer time to winter time.
I am in France and on October 29, 2023 we switch to winter time.

I wrote this little piece of code:

local date = require('date')

local ts1 = 1698537600 -- 2023-10-29T00:00:00Z or 2023-10-29T02:00:00+02:00
local ts2 = 1698541200 -- 2023-10-29T01:00:00Z or 2023-10-29T02:00:00+01:00
local d1, d2 = date(ts1), date(ts2)
local d1, d2 = date(ts1), date(ts2)
print("ts1 iso8601 UTC  :", d1:fmt("${iso}Z"))
print("ts2 iso8601 UTC  :", d2:fmt("${iso}Z"))
local d1local, d2local = date(ts1):tolocal(), date(ts2):tolocal()
print("ts1 iso8601 local:", d1local:fmt("${iso}") .. d1local:fmt("%z"))
print("ts2 iso8601 local:", d2local:fmt("${iso}") .. d2local:fmt("%z"))

And I get the following display::

ts1 iso8601 UTC  :	2023-10-29T00:00:00Z --> good
ts2 iso8601 UTC  :	2023-10-29T01:00:00Z --> good
ts1 iso8601 local:	2023-10-29T02:00:00+0100 --> bad
ts2 iso8601 local:	2023-10-29T02:00:00+0100 --> good

Is there a problem in the module or is it a problem using the module on my side?

@oktoberfest6
Copy link
Author

I solved my issue using os.date("%z")

print("ts1 iso8601 local:", d1local:fmt("${iso}") .. os.date("%z", ts1))
--> ts1 iso8601 local: 2023-10-29T02:00:00+0200
print("ts2 iso8601 local:", d2local:fmt("${iso}") .. os.date("%z", ts2))
--> ts2 iso8601 local: 2023-10-29T02:00:00+0100

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

No branches or pull requests

1 participant