From 77966981556153fe0c475a38847622d8ecc91264 Mon Sep 17 00:00:00 2001 From: dreamer Date: Mon, 12 Oct 2020 17:39:52 +0200 Subject: [PATCH] fix delimiter for . --- code/handlers/splhandler.lua | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/code/handlers/splhandler.lua b/code/handlers/splhandler.lua index 5b64a1b..dbcfa36 100644 --- a/code/handlers/splhandler.lua +++ b/code/handlers/splhandler.lua @@ -1,4 +1,5 @@ local db = require("lapis.db") +local to_json = require("lapis.util").to_json local autoload = require("lapis.util").autoload local models = autoload("models") @@ -70,17 +71,34 @@ function Splhandler(self) end -- we have to split the `hr:min:sec` and `month/day/year` strings from SPL - local function Split(s, delimiter) - local result = {} - for match in (s..delimiter):gmatch("(.-)"..delimiter) do - table.insert(result, match) + -- and since SPL uses both "." and "-" for dates .. somehow .. we have to do more dirty tricks .. + local function Split(s, delimiters) + + for i, delimiter in ipairs(delimiters) do + local result = {} + + if delimiter == "." then + for match in string.gmatch(s, "[^%.]+") do + table.insert(result, match) + end + else + for match in (s..delimiter):gmatch("(.-)"..delimiter) do + table.insert(result, match) + end + end + + if table.getn(result) == 3 then + return result + else + print("something is wrong: ".. s) + end + end - return result end - local split_airtime = Split(airtime, ":") + local split_airtime = Split(airtime, {":"}) local airtime_hr, airtime_min, airtime_sec = split_airtime[1], split_airtime[2], split_airtime[3] - local split_airdate = Split(airdate, "/") + local split_airdate = Split(airdate, {"/", ".", "-"}) local airdate_month, airdate_day, airdate_year = split_airdate[1], split_airdate[2], split_airdate[3] local airtime_stamp = os.time{year=airdate_year, month=airdate_month, day=airdate_day, hour=airtime_hr, min=airtime_min, sec=airtime_sec}