Systemd/src/basic/calendarspec.h
Lennart Poettering 6d86f4bd11 analyze: add new "calendar" command
This little new command can parse, validate, normalize calendar events,
and calculate when they will elapse next. This should be useful for
anyone writing calendar events and who'd like to validate the expression
before running them as timer units.
2017-11-20 10:57:41 +01:00

66 lines
1.8 KiB
C

/* SPDX-License-Identifier: LGPL-2.1+ */
#pragma once
/***
This file is part of systemd.
Copyright 2012 Lennart Poettering
systemd is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
/* A structure for specifying (possibly repetitive) points in calendar
* time, a la cron */
#include <stdbool.h>
#include "time-util.h"
#include "util.h"
typedef struct CalendarComponent {
int start;
int stop;
int repeat;
struct CalendarComponent *next;
} CalendarComponent;
typedef struct CalendarSpec {
int weekdays_bits;
bool end_of_month;
bool utc;
int dst;
char *timezone;
CalendarComponent *year;
CalendarComponent *month;
CalendarComponent *day;
CalendarComponent *hour;
CalendarComponent *minute;
CalendarComponent *microsecond;
} CalendarSpec;
CalendarSpec* calendar_spec_free(CalendarSpec *c);
int calendar_spec_normalize(CalendarSpec *spec);
bool calendar_spec_valid(CalendarSpec *spec);
int calendar_spec_to_string(const CalendarSpec *spec, char **p);
int calendar_spec_from_string(const char *p, CalendarSpec **spec);
int calendar_spec_next_usec(const CalendarSpec *spec, usec_t usec, usec_t *next);
DEFINE_TRIVIAL_CLEANUP_FUNC(CalendarSpec*, calendar_spec_free);