1

According to the current date, How I could know if it the hour is in summer time in Lua.

For example, the value in France would be actually true (CEST is currently used). During winter it would be false.
Forget is this is too specific: I am just expecting the rules for France. But at this point, I couldn't know if Lua has a native function.

The list of available builtins functions is here.

user2284570
  • 2,891
  • 3
  • 26
  • 74

3 Answers3

7

The table returned by os.date("*t", someday) has a field isdst representing if it's daylight saving time.

local someday = os.time{year=2013, month=6, day=20}
local t = os.date("*t", someday)
print(t.isdst)

Getting the current time is easier, calling os.time without arguments will return the current date and time.

local now = os.time()
local t = os.date("*t", now)
print(t.isdst)
Yu Hao
  • 119,891
  • 44
  • 235
  • 294
2

os.date("%Z") returns "CEST" if your system is using Central European Summer Time, which is what France is using now. Outside summer time, it returns "CET".

lhf
  • 70,581
  • 9
  • 108
  • 149
  • thanks this short way of doing it. Does it return a string ("CEST" or "CET")? If Yes, I can say that this is exactly that I want my function to output. I wanted something shorter than with #ifeq in wikisyntax. – user2284570 Sep 26 '13 at 18:53
  • Yes, `os.date("%Z")` returns a string. – lhf Sep 26 '13 at 19:12
  • It was working on command line, but finally it seems there is a kind of problem: https://fr.wikipedia.org/wiki/Module:Wrapper – user2284570 Sep 30 '13 at 21:21
0

In addition to the other two answers (by @lhf and @Yu Hao) which are right, note that dealing correctly with time is complicated. If I were you I would consider using a library for it, such as Penlight. Note that even Penlight is not perfect but at least people are using it so issues get fixed eventually.

catwell
  • 6,770
  • 1
  • 23
  • 21
  • Thanks you. I am sorry, but i was looking for something working with https://www.mediawiki.org/wiki/Extension:Scribunto . I don't have enough privileges to add third party libraries, because I am a simple user of the wiki. – user2284570 Sep 26 '13 at 18:56
  • Then you can just look at https://github.com/stevedonovan/Penlight/blob/62fc78dd0d4834619106797f8978ffdb302cb484/lua/pl/Date.lua for inspiration I guess. – catwell Sep 27 '13 at 08:17
  • It was working on command line, but finally it seems there is a kind of problem: http://fr.wikipedia.org/wiki/Module:Wrapper – user2284570 May 19 '14 at 21:27