From 7882795d10fc28a696a4784d24fbb2990a5e5707 Mon Sep 17 00:00:00 2001 From: aalatchm Date: Tue, 22 Mar 2011 18:27:12 +0000 Subject: added to Lua example to demonstrate posixtz.parse --- example.lua | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'example.lua') diff --git a/example.lua b/example.lua index f140553..dad7154 100644 --- a/example.lua +++ b/example.lua @@ -4,3 +4,35 @@ 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) -- cgit v1.2.3