diff --git a/code/handlers/splhandler.lua b/code/handlers/splhandler.lua index aa27263..570d291 100644 --- a/code/handlers/splhandler.lua +++ b/code/handlers/splhandler.lua @@ -71,23 +71,35 @@ 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 = {} - if delimiter == "." then - for match in string.gmatch(s, "[^%.]+") do - table.insert(result, match) - end - else - for match in (s..delimiter):gmatch("(.-)"..delimiter) do + -- 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 + print(delimiter) + 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}