libvieter/include/vieter_cron.h

53 lines
1.3 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>
2023-01-18 13:53:50 +01:00
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;
2023-01-18 13:53:50 +01:00
} vieter_cron_expression;
2023-01-17 23:09:06 +01:00
2023-01-18 13:53:50 +01:00
typedef struct vieter_cron_simple_time {
int year;
int month;
int day;
int hour;
int minute;
2023-01-18 13:53:50 +01:00
} vieter_cron_simple_time;
2023-01-17 23:09:06 +01:00
2023-01-18 13:53:50 +01:00
vieter_cron_expression *ce_init();
2023-01-17 23:09:06 +01:00
2023-01-18 14:12:02 +01:00
void vieter_cron_expr_free(vieter_cron_expression *ce);
2023-01-17 23:09:06 +01:00
2023-01-18 14:12:02 +01:00
void vieter_cron_expr_next(vieter_cron_simple_time *out,
vieter_cron_expression *ce,
vieter_cron_simple_time *ref);
2023-01-17 23:09:06 +01:00
2023-01-18 14:12:02 +01:00
void vieter_cron_expr_next_from_now(vieter_cron_simple_time *out,
vieter_cron_expression *ce);
2023-01-17 23:09:06 +01:00
2023-01-18 14:12:02 +01:00
enum vieter_cron_parse_error vieter_cron_expr_parse(vieter_cron_expression *out,
const char *expression);
2023-01-17 23:09:06 +01:00
#endif