libvieter/include/vieter_cron.h

51 lines
1.1 KiB
C
Raw Normal View History

2023-01-17 23:09:06 +01:00
#ifndef VIETER_CRON
#define VIETER_CRON
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
typedef enum cron_parse_error {
cron_parse_ok = 0,
cron_parse_invalid_expression = 1,
cron_parse_invalid_number = 2,
cron_parse_out_of_range = 3,
cron_parse_too_many_parts = 4,
cron_parse_not_enough_parts = 5
2023-01-17 23:09:06 +01:00
} cron_parse_error;
typedef struct cron_expression {
uint8_t *minutes;
uint8_t *hours;
uint8_t *days;
uint8_t *months;
uint8_t minute_count;
uint8_t hour_count;
uint8_t day_count;
uint8_t month_count;
2023-01-17 23:09:06 +01:00
} cron_expression;
typedef struct cron_simple_time {
int year;
int month;
int day;
int hour;
int minute;
2023-01-17 23:09:06 +01:00
} cron_simple_time;
cron_expression *ce_init();
void cron_ce_free(cron_expression *ce);
void cron_ce_next(cron_simple_time *out, cron_expression *ce,
cron_simple_time *ref);
2023-01-17 23:09:06 +01:00
void cron_ce_next_from_now(cron_simple_time *out, cron_expression *ce);
enum cron_parse_error cron_ce_parse_expression(cron_expression *out,
const char *expression);
2023-01-17 23:09:06 +01:00
#endif