From 27e12c9a39aa33f8815964adedd036cd6703099f Mon Sep 17 00:00:00 2001 From: daurnimator Date: Sun, 24 Nov 2013 05:42:23 -0500 Subject: [PATCH] Give tt_info objects a metatable; and document them --- doc/tzinfo.md | 8 ++++++-- luatz/tzfile.lua | 3 +++ luatz/tzinfo.lua | 3 +++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/doc/tzinfo.md b/doc/tzinfo.md index 7ae1b55..78d0453 100644 --- a/doc/tzinfo.md +++ b/doc/tzinfo.md @@ -13,7 +13,10 @@ so the following details can be skipped over. The table contains a sequence of tables that describe the timezone at a given point using a `transition_time`: the unix timestamp (in UTC) that this definition starts, and -a `info` table, which contains information about the change at that point: +a `tt_info` object. + +A `tt_info` object contains information about a time offset; +and contains the following fields: - `gmtoff` (number) The offset from GMT (UTC) in seconds - `isdst` (boolean): If this change was declared as daylight savings @@ -22,9 +25,10 @@ a `info` table, which contains information about the change at that point: - `isstd` (boolean) - `isgmt` (boolean) + ## `:find_current ( utc_ts )` -Returns the relevant `info` table at the given utc timestamp for the given UTC timestamp. +Returns the relevant `tt_info` object for the given UTC timestamp in the timezone. ## `:localise ( utc_ts )` and `:localize ( utc_ts )` diff --git a/luatz/tzfile.lua b/luatz/tzfile.lua index 96686dc..a0f8da5 100644 --- a/luatz/tzfile.lua +++ b/luatz/tzfile.lua @@ -1,4 +1,6 @@ local tz_info_mt = require "luatz.tzinfo".tz_info_mt +local tt_info_mt = require "luatz.tzinfo".tt_info_mt + local function read_int32be ( fd ) local data , err = fd:read ( 4 ) @@ -162,6 +164,7 @@ local function read_tz ( fd ) v.abbr = abbreviations:sub ( v.abbrind+1 , v.abbrind+3 ) v.isstd = isstd [ i ] or false v.isgmt = isgmt [ i ] or false + setmetatable ( v , tt_info_mt ) end --[[ diff --git a/luatz/tzinfo.lua b/luatz/tzinfo.lua index 11248ad..77d0656 100644 --- a/luatz/tzinfo.lua +++ b/luatz/tzinfo.lua @@ -4,6 +4,8 @@ local tz_info_methods = { } local tz_info_mt = { __index = tz_info_methods ; } +local tt_info_mt = { +} -- Binary search local function _find_current ( tzinfo , target , i , j ) @@ -75,4 +77,5 @@ end return { tz_info_mt = tz_info_mt ; + tt_info_mt = tt_info_mt ; } -- 2.39.5