| index eb4c10d..d855f10 100644 | ||
| --- a/README.md | ||
| +++ b/README.md | ||
| @@ -172,7 +172,7 @@ Plugin identity, version, supported actions, capabilities and the trust notice. | ||
| 172 | 172 | - **No network.** No sockets, no HTTP client, no telemetry. |
| 173 | 173 | - **Two external programs, both query-only:** `crontab -l` and `schtasks /Query`. |
| 174 | 174 | - **No user input reaches a shell.** Fixture paths come from the environment, not the query. |
| 175 | -- **Next-run horizon** is four years, which covers every expression including | |
| 175 | +- **Next-run horizon** is twenty years, which covers every expression including | |
| 176 | 176 | `0 0 29 2 *` (29 February) and `0 0 1 1 *` (1 January). |
| 177 | 177 | |
| 178 | 178 | --- |
| index 7524065..2c1c785 100644 | ||
| --- a/src/plugin_crontab.c | ||
| +++ b/src/plugin_crontab.c | ||
| @@ -52,7 +52,7 @@ | ||
| 52 | 52 | #define MAX_CMD 512 |
| 53 | 53 | #define MAX_SRC 64 |
| 54 | 54 | #define MAX_RUNS 5 |
| 55 | -#define HORIZON_DAYS 1461 | |
| 55 | +#define HORIZON_DAYS 7305 /* twenty years: five runs even for 29 February */ | |
| 56 | 56 | #define READ_LINE 2048 |
| 57 | 57 | |
| 58 | 58 | /* ------------------------------------------------------------------ */ |
| @@ -332,13 +332,28 @@ static int count_set(const unsigned char *flags, int lo, int hi) | ||
| 332 | 332 | /* Portable UTC mktime */ |
| 333 | 333 | /* ---------------------------------------------------------------- */ |
| 334 | 334 | |
| 335 | +/* Days since the Unix epoch for a civil date (Howard Hinnant's algorithm). */ | |
| 336 | +static long days_from_civil(int y, int m, int d) | |
| 337 | +{ | |
| 338 | + long era, yoe, doy, doe; | |
| 339 | + | |
| 340 | + y -= (m <= 2); | |
| 341 | + era = (y >= 0 ? y : y - 399) / 400; | |
| 342 | + yoe = (long)(y - era * 400); | |
| 343 | + doy = (153L * (m + (m > 2 ? -3 : 9)) + 2) / 5 + d - 1; | |
| 344 | + doe = yoe * 365 + yoe / 4 - yoe / 100 + doy; | |
| 345 | + return era * 146097L + doe - 719468L; | |
| 346 | +} | |
| 347 | + | |
| 348 | +/* | |
| 349 | + * Portable UTC mktime. Implemented directly rather than calling timegm(), | |
| 350 | + * which is not declared by default on macOS and is missing on Windows. | |
| 351 | + */ | |
| 335 | 352 | static time_t timegm_portable(struct tm *tmv) |
| 336 | 353 | { |
| 337 | -#if defined(_WIN32) | |
| 338 | - return _mkgmtime(tmv); | |
| 339 | -#else | |
| 340 | - return timegm(tmv); | |
| 341 | -#endif | |
| 354 | + long days = days_from_civil(tmv->tm_year + 1900, tmv->tm_mon + 1, tmv->tm_mday); | |
| 355 | + return (time_t)(days * 86400L + (long)tmv->tm_hour * 3600L | |
| 356 | + + (long)tmv->tm_min * 60L + (long)tmv->tm_sec); | |
| 342 | 357 | } |
| 343 | 358 | /* ---------------------------------------------------------------- */ |
| 344 | 359 | /* Human readable description of a parsed schedule */ |
| 345 | 360 |
| index eb4c10d..d855f10 100644 | index eb4c10d..d855f10 100644 | ||
| --- a/README.md | --- a/README.md | ||
| +++ b/README.md | +++ b/README.md | ||
| @@ -172,7 +172,7 @@ Plugin identity, version, supported actions, capabilities and the trust notice. | @@ -172,7 +172,7 @@ Plugin identity, version, supported actions, capabilities and the trust notice. | ||
| 172 | - **No network.** No sockets, no HTTP client, no telemetry. | 172 | - **No network.** No sockets, no HTTP client, no telemetry. |
| 173 | - **Two external programs, both query-only:** `crontab -l` and `schtasks /Query`. | 173 | - **Two external programs, both query-only:** `crontab -l` and `schtasks /Query`. |
| 174 | - **No user input reaches a shell.** Fixture paths come from the environment, not the query. | 174 | - **No user input reaches a shell.** Fixture paths come from the environment, not the query. |
| 175 | -- **Next-run horizon** is four years, which covers every expression including | 175 | +- **Next-run horizon** is twenty years, which covers every expression including |
| 176 | `0 0 29 2 *` (29 February) and `0 0 1 1 *` (1 January). | 176 | `0 0 29 2 *` (29 February) and `0 0 1 1 *` (1 January). |
| 177 | 177 | ||
| 178 | --- | 178 | --- |
| index 7524065..2c1c785 100644 | index 7524065..2c1c785 100644 | ||
| --- a/src/plugin_crontab.c | --- a/src/plugin_crontab.c | ||
| +++ b/src/plugin_crontab.c | +++ b/src/plugin_crontab.c | ||
| @@ -52,7 +52,7 @@ | @@ -52,7 +52,7 @@ | ||
| 52 | #define MAX_CMD 512 | 52 | #define MAX_CMD 512 |
| 53 | #define MAX_SRC 64 | 53 | #define MAX_SRC 64 |
| 54 | #define MAX_RUNS 5 | 54 | #define MAX_RUNS 5 |
| 55 | -#define HORIZON_DAYS 1461 | 55 | +#define HORIZON_DAYS 7305 /* twenty years: five runs even for 29 February */ |
| 56 | #define READ_LINE 2048 | 56 | #define READ_LINE 2048 |
| 57 | 57 | ||
| 58 | /* ------------------------------------------------------------------ */ | 58 | /* ------------------------------------------------------------------ */ |
| @@ -332,13 +332,28 @@ static int count_set(const unsigned char *flags, int lo, int hi) | @@ -332,13 +332,28 @@ static int count_set(const unsigned char *flags, int lo, int hi) | ||
| 332 | /* Portable UTC mktime */ | 332 | /* Portable UTC mktime */ |
| 333 | /* ---------------------------------------------------------------- */ | 333 | /* ---------------------------------------------------------------- */ |
| 334 | 334 | ||
| 335 | +/* Days since the Unix epoch for a civil date (Howard Hinnant's algorithm). */ | ||
| 336 | +static long days_from_civil(int y, int m, int d) | ||
| 337 | +{ | ||
| 338 | + long era, yoe, doy, doe; | ||
| 339 | + | ||
| 340 | + y -= (m <= 2); | ||
| 341 | + era = (y >= 0 ? y : y - 399) / 400; | ||
| 342 | + yoe = (long)(y - era * 400); | ||
| 343 | + doy = (153L * (m + (m > 2 ? -3 : 9)) + 2) / 5 + d - 1; | ||
| 344 | + doe = yoe * 365 + yoe / 4 - yoe / 100 + doy; | ||
| 345 | + return era * 146097L + doe - 719468L; | ||
| 346 | +} | ||
| 347 | + | ||
| 348 | +/* | ||
| 349 | + * Portable UTC mktime. Implemented directly rather than calling timegm(), | ||
| 350 | + * which is not declared by default on macOS and is missing on Windows. | ||
| 351 | + */ | ||
| 335 | static time_t timegm_portable(struct tm *tmv) | 352 | static time_t timegm_portable(struct tm *tmv) |
| 336 | { | 353 | { |
| 337 | -#if defined(_WIN32) | 354 | + long days = days_from_civil(tmv->tm_year + 1900, tmv->tm_mon + 1, tmv->tm_mday); |
| 338 | - return _mkgmtime(tmv); | 355 | + return (time_t)(days * 86400L + (long)tmv->tm_hour * 3600L |
| 339 | -#else | 356 | + + (long)tmv->tm_min * 60L + (long)tmv->tm_sec); |
| 340 | - return timegm(tmv); | ||
| 341 | -#endif | ||
| 342 | } | 357 | } |
| 343 | /* ---------------------------------------------------------------- */ | 358 | /* ---------------------------------------------------------------- */ |
| 344 | /* Human readable description of a parsed schedule */ | 359 | /* Human readable description of a parsed schedule */ |
| 345 | 360 |