libvieter/include/vieter_cron.h

51 lines
1.1 KiB
C

#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
} 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;
} cron_expression;
typedef struct cron_simple_time {
int year;
int month;
int day;
int hour;
int minute;
} 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);
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);
#endif