]> git.proxmox.com Git - pve-common.git/blame_incremental - src/PVE/CalendarEvent.pm
bump version to 8.2.1
[pve-common.git] / src / PVE / CalendarEvent.pm
... / ...
CommitLineData
1package PVE::CalendarEvent;
2
3use strict;
4use warnings;
5use Data::Dumper;
6use Time::Local;
7use PVE::JSONSchema;
8use PVE::Tools qw(trim);
9use Proxmox::RS::CalendarEvent;
10
11# Note: This class implements a parser/utils for systemd like calendar exents
12# Date specification is currently not implemented
13
14my $dow_names = {
15 sun => 0,
16 mon => 1,
17 tue => 2,
18 wed => 3,
19 thu => 4,
20 fri => 5,
21 sat => 6,
22};
23
24PVE::JSONSchema::register_format('pve-calendar-event', \&pve_verify_calendar_event);
25sub pve_verify_calendar_event {
26 my ($text, $noerr) = @_;
27
28 eval { parse_calendar_event($text); };
29 if (my $err = $@) {
30 return undef if $noerr;
31 die "invalid calendar event '$text' - $err\n";
32 }
33 return $text;
34}
35
36# The parser.
37# returns a $calspec hash which can be passed to compute_next_event()
38sub parse_calendar_event {
39 my ($event) = @_;
40
41 $event = trim($event);
42
43 if ($event eq '') {
44 die "unable to parse calendar event - event is empty\n";
45 }
46
47 return Proxmox::RS::CalendarEvent->new($event);
48}
49
50sub compute_next_event {
51 my ($calspec, $last) = @_;
52
53 return $calspec->compute_next_event($last);
54}
55
561;