summaryrefslogtreecommitdiffstats
path: root/example.lua
blob: dad7154be315096aff0624f3e15fa40f71975395 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env lua

require("posixtz")

print(posixtz.from_file("/usr/share/zoneinfo/Europe/Stockholm"))


t = posixtz.parse("CET-1CEST,M3.5.0,M10.5.0/3")

local out = ""
out = out .. "POSIX TZ: '"..t.std.."'\n"
out = out .. "GMT Offset, where positive is West of GMT: '"..t.offset.total.."'\n"

if t.dst then
	out = out .. "DST zone is called '"..t.dst.name.."'\n"
	local function dstinfo (pos)
		local info = ""
		if t.dst[pos].hour then
			info = info .. "at '"..t.dst[pos].hour.."' hours (0-23) "
		end
		if t.dst[pos].week then
			info = info .. "on weekday '"..t.dst[pos].weekday.."' "
			info = info .. "of week '"..t.dst[pos].week.."' "
			info = info .. "of the month '"..t.dst[pos].month.."'"
		else
			info = info .. "on day '"..t.dst[pos].day.."' "
			info = info .. "of month '"..t.dst[pos].month.."'"
		end
		return info
	end
	out = out .. "DST begins "
	out = out .. dstinfo("start") .. "\n"
	out = out .. "DST ends "
	out = out .. dstinfo("stop") .. "\n"

end

io.write(out)