diff --git a/.gitmodules b/.gitmodules index 6ed1421..5314122 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ [submodule "ccronexpr"] path = ccronexpr - url = https://github.com/staticlibs/ccronexpr + url = https://github.com/exander77/supertinycron diff --git a/ccronexpr b/ccronexpr index 17475e1..1adaf35 160000 --- a/ccronexpr +++ b/ccronexpr @@ -1 +1 @@ -Subproject commit 17475e10c2053650a86b1d25a692c2c20d74c420 +Subproject commit 1adaf358287a8a382f6221500ecd972908035fbe diff --git a/cron-parser.lua b/cron-parser.lua index 94cfeb1..7a16980 100644 --- a/cron-parser.lua +++ b/cron-parser.lua @@ -7,6 +7,9 @@ typedef struct { uint8_t days_of_week[1]; uint8_t days_of_month[4]; uint8_t months[2]; + int8_t day_in_month[1]; + uint8_t flags[1]; + uint8_t years[29]; } cron_expr; void cron_parse_expr(const char* expression, cron_expr* target, const char** error); time_t cron_next(cron_expr* expr, time_t date); @@ -25,68 +28,21 @@ local function parse(raw_expr) return nil, ffi.string(err[0]) end - local lua_parsed_expr = { - seconds = {}, - minutes = {}, - hours = {}, - days_of_week = nil, - days_of_month = {}, - months = {} + return { + __expr = parsed_expr, } - - for i = 0,7 do - lua_parsed_expr.seconds[i + 1] = parsed_expr[0].seconds[i] - lua_parsed_expr.minutes[i + 1] = parsed_expr[0].minutes[i] - end - - for i = 0,2 do - lua_parsed_expr.hours[i + 1] = parsed_expr[0].hours[i] - end - - lua_parsed_expr.days_of_week = parsed_expr[0].days_of_week[0] - - for i = 0,3 do - lua_parsed_expr.days_of_month[i + 1] = parsed_expr[0].days_of_month[i] - end - - for i = 0,1 do - lua_parsed_expr.months[i + 1] = parsed_expr[0].months[i] - end - - return lua_parsed_expr end -local function next(lua_parsed_expr, from_time) - local parsed_expr = ffi.new('cron_expr[1]') - - for i = 0,7 do - parsed_expr[0].seconds[i] = lua_parsed_expr.seconds[i + 1] - parsed_expr[0].minutes[i] = lua_parsed_expr.minutes[i + 1] - end - - for i = 0,2 do - parsed_expr[0].hours[i] = lua_parsed_expr.hours[i + 1] - end - - parsed_expr[0].days_of_week[0] = lua_parsed_expr.days_of_week - - for i = 0,3 do - parsed_expr[0].days_of_month[i] = lua_parsed_expr.days_of_month[i + 1] - end - - for i = 0,1 do - parsed_expr[0].months[i] = lua_parsed_expr.months[i + 1] - end - +local function next(parsed, from_time) if from_time == nil then from_time = os.time() end - local ts = cron.cron_next(parsed_expr, from_time) + local ts = cron.cron_next(parsed.__expr, from_time) return tonumber(ts) end return { parse = parse, - next = next + next = next, }