]>
Commit | Line | Data |
---|---|---|
2244b271 DM |
1 | package PVE::CalendarEvent; |
2 | ||
3 | use strict; | |
4 | use warnings; | |
5 | use Data::Dumper; | |
6 | use Time::Local; | |
55c6e2cd | 7 | use PVE::JSONSchema; |
a5ffa49f | 8 | use PVE::Tools qw(trim); |
4656d14a | 9 | use Proxmox::RS::CalendarEvent; |
2244b271 | 10 | |
fb3a1b29 | 11 | # Note: This class implements a parser/utils for systemd like calendar exents |
2244b271 DM |
12 | # Date specification is currently not implemented |
13 | ||
14 | my $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 | ||
55c6e2cd DM |
24 | PVE::JSONSchema::register_format('pve-calendar-event', \&pve_verify_calendar_event); |
25 | sub pve_verify_calendar_event { | |
26 | my ($text, $noerr) = @_; | |
27 | ||
28 | eval { parse_calendar_event($text); }; | |
29 | if (my $err = $@) { | |
30 | return undef if $noerr; | |
05477bfe | 31 | die "invalid calendar event '$text' - $err\n"; |
55c6e2cd DM |
32 | } |
33 | return $text; | |
34 | } | |
35 | ||
2244b271 DM |
36 | # The parser. |
37 | # returns a $calspec hash which can be passed to compute_next_event() | |
38 | sub parse_calendar_event { | |
39 | my ($event) = @_; | |
40 | ||
a5ffa49f DC |
41 | $event = trim($event); |
42 | ||
43 | if ($event eq '') { | |
44 | die "unable to parse calendar event - event is empty\n"; | |
45 | } | |
46 | ||
4656d14a | 47 | return Proxmox::RS::CalendarEvent->new($event); |
1457ffef WB |
48 | } |
49 | ||
2244b271 | 50 | sub compute_next_event { |
0b7ba044 | 51 | my ($calspec, $last) = @_; |
2244b271 | 52 | |
9572e104 | 53 | return $calspec->compute_next_event($last); |
2244b271 DM |
54 | } |
55 | ||
56 | 1; |