Skip to content

update cron-parser submodule #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "ccronexpr"]
path = ccronexpr
url = https://github.com/staticlibs/ccronexpr
url = https://github.com/exander77/supertinycron
2 changes: 1 addition & 1 deletion ccronexpr
60 changes: 8 additions & 52 deletions cron-parser.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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,
}