From b3c3cba87ba31012d56b9e9e384604d8187aaf76 Mon Sep 17 00:00:00 2001 From: Thijs Schreijer Date: Mon, 3 Dec 2018 15:25:59 +0100 Subject: [PATCH] housekeeping, adding CI, moving some source files, fix linter --- .busted | 8 +++- .editorconfig | 13 ++++++ .gitignore | 2 + .luacheckrc | 31 +++++++++++++ .luacov | 6 +++ .travis.yml | 45 ++++++++++--------- README.md | 9 ++-- ...-2.1.2-1.rockspec => date-2.1.2-2.rockspec | 4 +- spec/date_spec.lua | 28 ++++++------ date.lua => src/date.lua | 19 ++++---- 10 files changed, 112 insertions(+), 53 deletions(-) create mode 100644 .editorconfig create mode 100644 .gitignore create mode 100644 .luacheckrc create mode 100644 .luacov rename date-2.1.2-1.rockspec => date-2.1.2-2.rockspec (92%) rename date.lua => src/date.lua (98%) diff --git a/.busted b/.busted index 045beaf..d8f1eff 100644 --- a/.busted +++ b/.busted @@ -1,5 +1,11 @@ return { default = { - output = "TAP" + verbose = true, + coverage = true, + output = "gtest", + ROOT = { + "spec/", + --"examples/vcache.lua", + }, }, } diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..dac40a4 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,13 @@ +root = true + +[*] +end_of_line = lf +insert_final_newline = true +charset = utf-8 + +[*.lua] +indent_style = space +indent_size = 2 + +[Makefile] +indent_style = tab diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4ef5f66 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.DS_store +luacov.* diff --git a/.luacheckrc b/.luacheckrc new file mode 100644 index 0000000..c4a9f82 --- /dev/null +++ b/.luacheckrc @@ -0,0 +1,31 @@ +--std = "ngx_lua+busted" +unused_args = false +redefined = false +max_line_length = false + + +globals = { + --"_KONG", + --"kong", + --"ngx.IS_CLI", +} + + +not_globals = { + "string.len", + "table.getn", +} + + +ignore = { + --"6.", -- ignore whitespace warnings +} + + +exclude_files = { + "here/**", + "samples/**", + --"spec/fixtures/invalid-module.lua", + --"spec-old-api/fixtures/invalid-module.lua", +} + diff --git a/.luacov b/.luacov new file mode 100644 index 0000000..8240883 --- /dev/null +++ b/.luacov @@ -0,0 +1,6 @@ +modules = { + ["date"] = "src/date.lua", + ["date.*"] = "src" +} +runreport = true +deletestats = false diff --git a/.travis.yml b/.travis.yml index 3d9da62..41f057f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,28 +1,29 @@ -language: erlang +language: python +sudo: false env: - - LUA="luajit-2.0.0-beta9" + - LUA="lua 5.1" + - LUA="lua 5.2" + - LUA="lua 5.3" + - LUA="luajit 2.0" + - LUA="luajit 2.0 --compat 5.2" + - LUA="luajit 2.1" + - LUA="luajit 2.1 --compat 5.2" + +before_install: + - pip install hererocks + - hererocks here -r^ --$LUA + - source here/bin/activate + - luarocks install luacheck + - luarocks install busted + - luarocks install luacov-coveralls install: - - sudo apt-get update -qq - - sudo apt-get install -qq git luajit luarocks - - sudo ln -s /usr/bin/luajit-2.0.0-beta9 /usr/bin/luajit - - sudo luarocks install busted - - git clone git://github.com/Tieske/date.git - - cd date + - luarocks make -script: "sudo busted" +script: + - luacheck . + - busted -notifications: - webhooks: - - http://exobot.herokuapp.com/hubot/travis - recipients: - - thijs@thijsschreijer.nl - email: - on_success: always - on_failure: always - -branches: - except: - - gh-pages - +after_success: + - luacov-coveralls diff --git a/README.md b/README.md index be19305..878fa69 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,11 @@ -#LuaDate v2.1 +# LuaDate v2.1 -[![travis-ci status](https://secure.travis-ci.org/Tieske/date.png)](http://travis-ci.org/#!/Tieske/date/builds) +[![Build Status](https://travis-ci.org/Tieske/date.svg?branch=master)](https://travis-ci.org/Tieske/date) +[![Coverage Status](https://coveralls.io/repos/github/Tieske/date/badge.svg?branch=master)](https://coveralls.io/github/Tieske/date?branch=master) Lua Date and Time module for Lua 5.x. -##Features: +## Features: * Date and Time string parsing. * Time addition and subtraction. @@ -26,7 +27,7 @@ Documentation is available in the `doc` folder, or [online at Github](http://tie Tests are located in the `spec` directory and can be run using [busted](http://olivinelabs.com/busted/). -##Changes: +## Changes: - v2.1.2 fix scientific notation [#9](https://github.com/Tieske/date/pull/9), now available for Lua 5.3 - v2.1.1 fix for '>=' operator [#3](https://github.com/Tieske/date/pull/3), added test suite, added Travis CI, license MIT diff --git a/date-2.1.2-1.rockspec b/date-2.1.2-2.rockspec similarity index 92% rename from date-2.1.2-1.rockspec rename to date-2.1.2-2.rockspec index 2abe688..2e8984f 100644 --- a/date-2.1.2-1.rockspec +++ b/date-2.1.2-2.rockspec @@ -1,5 +1,5 @@ package = "date" -version = "2.1.2-1" +version = "2.1.2-2" description = { summary = "Date & Time module for Lua 5.x", @@ -24,7 +24,7 @@ source = { build = { type = "builtin", modules = { - date = "date.lua" + date = "src/date.lua" } } diff --git a/spec/date_spec.lua b/spec/date_spec.lua index 716b2aa..4841388 100644 --- a/spec/date_spec.lua +++ b/spec/date_spec.lua @@ -20,12 +20,12 @@ describe("Testing the 'date' module", function() assert(date("Jul 27 2006 MDT") == date(2006,07,27,6,0,0)) assert(date("Jul 27 2006 PST") == date(2006,07,27,8,0,0)) assert(date("Jul 27 2006 PDT") == date(2006,07,27,7,0,0)) - -- Date Format. Short dates can use either a "/" or "-" date separator, + -- Date Format. Short dates can use either a "/" or "-" date separator, -- but must follow the month/day/year format assert(date("02-03-04")==date(1904,02,03)) assert(date("12/25/98")==date(1998,12,25)) - -- Long dates of the form "July 10 1995" can be given with the year, month, - -- and day in any order, and the year in 2-digit or 4-digit form. If you use + -- Long dates of the form "July 10 1995" can be given with the year, month, + -- and day in any order, and the year in 2-digit or 4-digit form. If you use -- the 2-digit form, the year must be greater than or equal to 70. assert(date("Feb-03-04")==date(1904,02,03)) assert(date("December 25 1998")==date(1998,12,25)) @@ -33,20 +33,20 @@ describe("Testing the 'date' module", function() assert(date("Feb 3 0003 BC")==date(-2,02,03)) assert(date("December 25 0001 BC")==date(0,12,25)) - -- Supported ISO 8601 Formats. - -- YYYY-MM-DDwhere YYYY is the year, MM is the month of the year, and DD is the - -- day of the month. + -- Supported ISO 8601 Formats. + -- YYYY-MM-DDwhere YYYY is the year, MM is the month of the year, and DD is the + -- day of the month. assert(date("2000-12-31")==date(2000,12,31)) assert(date(" 20001231 ")==date(2000,12,31)) -- Compact version - -- YYYY-DDDwhere YYYY is the year, DDD is the day of the year. + -- YYYY-DDDwhere YYYY is the year, DDD is the day of the year. assert(date("1995-035")==date(1995,02,04)) assert(date("1995035 ")==date(1995,02,04)) -- Compact version - -- YYYY-WDD-Dwhere YYYY is the year, DD is the week of the year, D is the day of - -- the week. + -- YYYY-WDD-Dwhere YYYY is the year, DD is the week of the year, D is the day of + -- the week. assert(date("1997-W01-1")==date(1996,12,30)) assert(date(" 1997W017")==date(1997,01,05)) -- Compact version - -- DATE HH:MM:SS.SSSWhere DATE is the date format discuss above, HH is the hour, - -- MM is the miute, SS.SSS is the seconds (fraction is optional). + -- DATE HH:MM:SS.SSSWhere DATE is the date format discuss above, HH is the hour, + -- MM is the miute, SS.SSS is the seconds (fraction is optional). assert(date("1995-02-04 24:00:51.536")==date(1995,2,5,0,0,51.536)) assert(date("1976-W01-1 12:12:12.123")==date(1975,12,29,12,12,12.123)) assert(date("1995-035 23:59:59.99999")==date(1995,02,04,23,59,59.99999)) @@ -55,8 +55,8 @@ describe("Testing the 'date' module", function() assert(date(" 1976W011T121212.123 ")==date(1975,12,29,12,12,12.123)) assert(date(" 1995035T235959.99999 ")==date(1995,02,04,23,59,59.99999)) -- DATE TIME +HH:MM, DATE TIME -HHMM, DATE TIME Z,Where DATE and TIME is the date - -- and time format discuss above. First character is a sign "+" (east of UTC) or "-" - -- (west of UTC). HH and MM is Hours and minutes offset. The Z stands for the zero offset. + -- and time format discuss above. First character is a sign "+" (east of UTC) or "-" + -- (west of UTC). HH and MM is Hours and minutes offset. The Z stands for the zero offset. assert(date("1976-W01-1 12:00Z ")==date(1975,12,29,12)) assert(date("1976-W01-1 13:00+01:00")==date(1975,12,29,12)) assert(date("1976-W01-1 0700-0500 ")==date(1975,12,29,12)) @@ -261,7 +261,7 @@ describe("Testing the 'date' module", function() end) it("Tests 'getweekday()'", function() - d = date(1970, 1, 1) + local d = date(1970, 1, 1) assert(d:getweekday() == 5) end) diff --git a/date.lua b/src/date.lua similarity index 98% rename from date.lua rename to src/date.lua index 0bd0580..b5964ab 100644 --- a/date.lua +++ b/src/date.lua @@ -38,7 +38,7 @@ local fmt = string.format local lwr = string.lower local rep = string.rep - local len = string.len + local len = string.len -- luacheck: ignore local sub = string.sub local gsub = string.gsub local gmatch = string.gmatch or string.gfind @@ -131,9 +131,9 @@ local y = (n400*400) + (n100*100) + (n004*4) + n001 - ((n001 == 4 or n100 == 4) and 1 or 0) local d = g - dayfromyear(y) local mi = floor((100*d + 52)/3060) - return (floor((mi + 2)/12) + y), mod(mi + 2,12), (d - floor((mi*306 + 5)/10) + 1) + return (floor((mi + 2)/12) + y), mod(mi + 2,12), (d - floor((mi*306 + 5)/10) + 1) end - ]] + ]] -- day fraction from time local function makedayfrc(h,r,s,t) return ((h*60 + r)*60 + s)*TICKSPERSEC + t @@ -215,7 +215,8 @@ local function getequivyear(y) assert(not yt) yt = {} - local de, dw, dy = date_epoch:copy() + local de = date_epoch:copy() + local dw, dy for _ = 0, 3000 do de:setyear(de:getyear() + 1, 1, 1) dy = de:getyear() @@ -294,7 +295,7 @@ if is then self.e, self.i = self.i, 1+ie; if f then f(unpack(self)) end return self end end local function date_parse(str) - local y,m,d, h,r,s, z, w,u, j, e, k, x,c, dn,df; + local y,m,d, h,r,s, z, w,u, j, e, x,c, dn,df local sw = newstrwalker(gsub(gsub(str, "(%b())", ""),"^(%s*)","")) -- remove comment, trim leading space --local function error_out() print(y,m,d,h,r,s) end local function error_dup(q) --[[error_out()]] error("duplicate value: " .. (q or "") .. sw:aimchr()) end @@ -317,7 +318,7 @@ or sw:finish() or (sw"^%s*$" or sw"^%s*[Zz]%s*$" or sw("^%s-([%+%-])(%d%d):?(%d%d)%s*$",setzc) or sw("^%s*([%+%-])(%d%d)%s*$",setzn)) ) ) then --print(y,m,d,h,r,s,z,w,u,j) - sw:restart(); y,m,d,h,r,s,z,w,u,j = nil; + sw:restart(); y,m,d,h,r,s,z,w,u,j = nil,nil,nil,nil,nil,nil,nil,nil,nil,nil repeat -- print(sw:aimchr()) if sw("^[tT:]?%s*(%d%d?):",seth) then --print("$Time") _ = sw("^%s*(%d%d?)",setr) and sw("^%s*:%s*(%d%d?)",sets) and sw("^(%.%d+)",adds) @@ -336,9 +337,7 @@ elseif inlist(x, sl_timezone, 2, sw) then c = fix(sw[0]) -- ignore gmt and utc if c ~= 0 then setz(c, x) end - elseif inlist(x, sl_weekdays, 2, sw) then - k = sw[0] - else + elseif not inlist(x, sl_weekdays, 2, sw) then sw:back() -- am pm bce ad ce bc if sw("^([bB])%s*(%.?)%s*[Cc]%s*(%2)%s*[Ee]%s*(%2)%s*") or sw("^([bB])%s*(%.?)%s*[Cc]%s*(%2)%s*") then @@ -582,7 +581,7 @@ -- Misc -- -- Year, if year is in BCE, prints the BCE Year representation, otherwise result is similar to "%Y" (1 BCE, 40 BCE) ['%\b']=function(self) local x = self:getyear() return fmt("%.4d%s", x>0 and x or (-x+1), x>0 and "" or " BCE") end, - -- Seconds including fraction (59.998, 01.123) + -- Seconds including fraction (59.998, 01.123) ['%\f']=function(self) local x = self:getfracsec() return fmt("%s%.9f",x >= 10 and "" or "0", x) end, -- percent character % ['%%']=function(self) return "%" end,