libvieter/include/vieter_cron.h

53 lines
1.3 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 vieter_cron_parse_error {
vieter_cron_parse_ok = 0,
vieter_cron_parse_invalid_expression = 1,
vieter_cron_parse_invalid_number = 2,
vieter_cron_parse_out_of_range = 3,
vieter_cron_parse_too_many_parts = 4,
vieter_cron_parse_not_enough_parts = 5
} vieter_cron_parse_error;
typedef struct vieter_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;
} vieter_cron_expression;
typedef struct vieter_cron_simple_time {
int year;
int month;
int day;
int hour;
int minute;
} vieter_cron_simple_time;
vieter_cron_expression *ce_init();
void vieter_cron_expr_free(vieter_cron_expression *ce);
void vieter_cron_expr_next(vieter_cron_simple_time *out,
vieter_cron_expression *ce,
vieter_cron_simple_time *ref);
void vieter_cron_expr_next_from_now(vieter_cron_simple_time *out,
vieter_cron_expression *ce);
enum vieter_cron_parse_error vieter_cron_expr_parse(vieter_cron_expression *out,
const char *expression);
#endif