From eabec5f434225aa68aa33565d8cf5055f287662e Mon Sep 17 00:00:00 2001 From: daurnimator Date: Wed, 4 Nov 2015 11:09:33 -0600 Subject: [PATCH] luatz/: Fix luacheck warnings Adds 'future' field to tz_info objects when available --- luatz/gettime.lua | 4 ++-- luatz/parse.lua | 2 +- luatz/strftime.lua | 12 ++++++------ luatz/timetable.lua | 6 +++--- luatz/tzfile.lua | 1 + 5 files changed, 13 insertions(+), 12 deletions(-) diff --git a/luatz/gettime.lua b/luatz/gettime.lua index 65366bd..e0da6b4 100644 --- a/luatz/gettime.lua +++ b/luatz/gettime.lua @@ -32,8 +32,8 @@ _M.source , _M.resolution , _M.gettime = (function() return "socket.gettime()" , 1e-6 , socket.gettime end - if ngx and ngx.now then - return "ngx.now()" , 1e-3 , ngx.now + if ngx and ngx.now then -- luacheck: ignore 113 + return "ngx.now()" , 1e-3 , ngx.now -- luacheck: ignore 113 end return "os.time()" , 1 , os.time diff --git a/luatz/parse.lua b/luatz/parse.lua index 8de9a36..0bfd820 100644 --- a/luatz/parse.lua +++ b/luatz/parse.lua @@ -26,7 +26,7 @@ local function rfc_3339 ( str , init ) local hour_offset , min_offset = str:match ( "^([+-]%d%d):(%d%d)" , patt_end ) if hour_offset then tz_offset = tonumber ( hour_offset ) * 3600 + tonumber ( min_offset ) * 60 - else + else -- luacheck: ignore 542 -- Invalid RFC 3339 timestamp offset (should be Z or (+/-)hour:min) -- tz_offset will be nil end diff --git a/luatz/strftime.lua b/luatz/strftime.lua index 51410cf..b82c22b 100644 --- a/luatz/strftime.lua +++ b/luatz/strftime.lua @@ -24,7 +24,7 @@ end local iso_8601_week do -- Years that have 53 weeks according to ISO-8601 local long_years = { } - for i, v in ipairs { + for _, v in ipairs { 4, 9, 15, 20, 26, 32, 37, 43, 48, 54, 60, 65, 71, 76, 82, 88, 93, 99, 105, 111, 116, 122, 128, 133, 139, 144, 150, 156, 161, 167, 172, 178, 184, 189, 195, 201, 207, 212, 218, 224, 229, 235, 240, 246, 252, @@ -117,7 +117,7 @@ function t:M ( ) return "%02d" , self.min end -- New-line character ('\n') -function t:n ( ) +function t:n ( ) -- luacheck: ignore 212 return "\n" end function t:p ( locale ) @@ -140,7 +140,7 @@ function t:S ( ) return "%02d" , self.sec end -- Horizontal-tab character ('\t') -function t:t ( ) +function t:t ( ) -- luacheck: ignore 212 return "\t" end -- ISO 8601 time format (HH:MM:SS), equivalent to %H:%M:%S @@ -176,14 +176,14 @@ function t:Y ( ) return "%d" , self.year end -- TODO timezones -function t:z ( ) +function t:z ( ) -- luacheck: ignore 212 return "+0000" end -function t:Z ( ) +function t:Z ( ) -- luacheck: ignore 212 return "GMT" end -- A literal '%' character. -t["%"] = function ( self ) +t["%"] = function ( self ) -- luacheck: ignore 212 return "%%" end diff --git a/luatz/timetable.lua b/luatz/timetable.lua index 5c234b6..e2930d8 100644 --- a/luatz/timetable.lua +++ b/luatz/timetable.lua @@ -3,7 +3,7 @@ local strformat = string.format local floor = math.floor local idiv do -- Try and use actual integer division when available (Lua 5.3+) - local idiv_loader, err = (loadstring or load)([[return function(n,d) return n//d end]], "idiv") + local idiv_loader = (loadstring or load)([[return function(n,d) return n//d end]], "idiv") -- luacheck: ignore 113 if idiv_loader then idiv = idiv_loader() else @@ -179,8 +179,8 @@ function timetable_methods:timestamp ( ) end function timetable_methods:rfc_3339 ( ) - local year , month , day , hour , min , sec = self:unpack ( ) - local sec , msec = borrow ( sec , 0 , 1000 ) + local year, month, day, hour, min, fsec = self:unpack() + local sec, msec = borrow(fsec, 0, 1000) msec = math.floor(msec) return strformat ( "%04u-%02u-%02uT%02u:%02u:%02d.%03d" , year , month , day , hour , min , sec , msec ) end diff --git a/luatz/tzfile.lua b/luatz/tzfile.lua index 4fddddf..ec10bc0 100644 --- a/luatz/tzfile.lua +++ b/luatz/tzfile.lua @@ -218,6 +218,7 @@ local function read_tz ( fd ) end local res = { + future = TZ; [0] = { transition_time = MIN_TIME ; info = ttinfos [ first ] ; -- 2.39.5