diff --git a/src/cron/c/expression.c b/src/cron/c/expression.c index 4e1ca3c..59d1bf0 100644 --- a/src/cron/c/expression.c +++ b/src/cron/c/expression.c @@ -102,8 +102,7 @@ void ce_next_from_now(cron_simple_time *out, cron_expression *ce) { gmtime_r(&t, &gm); cron_simple_time ref = { - // tm_year contains years since 1900 - .year = 1900 + gm.tm_year, + .year = gm.tm_year, // tm_mon goes from 0 to 11 .month = gm.tm_mon + 1, .day = gm.tm_mday, diff --git a/src/cron/c/parse.c b/src/cron/c/parse.c index 7a66200..f54b818 100644 --- a/src/cron/c/parse.c +++ b/src/cron/c/parse.c @@ -40,6 +40,18 @@ const uint8_t max_parts = 4; * - a-b/c */ cron_parse_error ce_parse_range(uint64_t *out, char *s, uint8_t min, uint8_t max) { + // The * expression means "every possible value" + if (s[0] == '*') { + // A '*' is only valid on its own + if (s[1] != '\0') { + return cron_parse_invalid_expression; + } + + *out = ~0; + + return cron_parse_ok; + } + size_t slash_index = 0; size_t dash_index = 0; size_t i = 0; @@ -62,17 +74,14 @@ cron_parse_error ce_parse_range(uint64_t *out, char *s, uint8_t min, uint8_t max } // Parse the three possible numbers in the pattern - uint8_t start = min; + uint8_t start = 0; uint8_t end = max; uint8_t interval = 1; - // * simply sets start as min and end as max - if (!(s[0] == '*' && strlen(s) == 1)) { - SAFE_ATOI(start, s, min, max); + SAFE_ATOI(start, s, min, max); - if (dash_index > 0) { - SAFE_ATOI(end, &s[dash_index + 1], min, max); - } + if (dash_index > 0) { + SAFE_ATOI(end, &s[dash_index + 1], min, max); } if (slash_index > 0) { diff --git a/src/cron/expression.c.v b/src/cron/expression.c.v index cd4b8b0..0698432 100644 --- a/src/cron/expression.c.v +++ b/src/cron/expression.c.v @@ -36,7 +36,6 @@ enum ParseError as u8 { too_many_parts = 4 } -// str returns the string representation of a ParseError. fn (e ParseError) str() string { return match e { .ok { '' } diff --git a/src/cron/expression.v b/src/cron/expression.v index c463d06..4a0d04c 100644 --- a/src/cron/expression.v +++ b/src/cron/expression.v @@ -2,13 +2,11 @@ module cron import time -// free the memory associated with the Expression. [unsafe] pub fn (ce &Expression) free() { C.ce_free(ce) } -// parse_expression parses a string into an Expression. pub fn parse_expression(exp string) !&Expression { out := C.ce_init() res := C.ce_parse_expression(out, exp.str) @@ -20,8 +18,6 @@ pub fn parse_expression(exp string) !&Expression { return out } -// next calculates the next occurence of the cron schedule, given a reference -// point. pub fn (ce &Expression) next(ref time.Time) time.Time { st := SimpleTime{ year: ref.year @@ -43,8 +39,6 @@ pub fn (ce &Expression) next(ref time.Time) time.Time { }) } -// next_from_now calculates the next occurence of the cron schedule with the -// current time as reference. pub fn (ce &Expression) next_from_now() time.Time { out := SimpleTime{} C.ce_next_from_now(&out, ce) diff --git a/src/cron/expression_test.v b/src/cron/expression_test.v index 9863ef5..7d1516d 100644 --- a/src/cron/expression_test.v +++ b/src/cron/expression_test.v @@ -34,11 +34,3 @@ fn test_next_simple() ! { //// Overlap to next year util_test_time('0 3', '2002-12-31 04:00:00', '2003-01-01 03:00:00')! } - -fn test_leading_star() { - mut x := false - - parse_expression('*5 8') or { x = true } - - assert x -}