aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonas Smedegaard <dr@jones.dk>2023-08-13 12:57:59 +0200
committerJonas Smedegaard <dr@jones.dk>2024-08-27 23:39:36 +0200
commitfcce5186541fcec0b182023506bfed35b8010201 (patch)
tree0789a3032728ab3cfb4a0f732391d6da0244fc06
parent11a67dddc81f128b47f856c89aad86eed19fd46a (diff)
parse time shift from environment variable CAL_DAV_NOW
-rwxr-xr-xbin/events2md.pl18
1 files changed, 16 insertions, 2 deletions
diff --git a/bin/events2md.pl b/bin/events2md.pl
index 14524b1..3a35a32 100755
--- a/bin/events2md.pl
+++ b/bin/events2md.pl
@@ -125,8 +125,22 @@ if ( $log->is_trace ) {
# serialize calendar events
$log->debug('serialize calendar events...');
-my $start = DateTime->now;
-my $end = $start->clone->add( months => 6 );
+my $start;
+if ( $ENV{CAL_DAV_NOW} ) {
+ try { require DateTimeX::Easy }
+ catch ($e) {
+ $log->fatalf( 'failed parsing CAL_DAV_NOW: %s', $e ) && exit 2
+ }
+ $start = DateTimeX::Easy->new( $ENV{CAL_DAV_NOW} );
+ $log->fatalf(
+ 'failed parsing CAL_DAV_NOW: unknown start time "%s"',
+ $ENV{CAL_DAV_NOW}
+ )
+ && exit 2
+ unless defined $start;
+}
+$start ||= DateTime->now;
+my $end = $start->clone->add( months => 6 );
$log->infof( 'will pick events between %s and %s', $start, $end );
my $span = DateTime::Span->from_datetimes( start => $start, end => $end );
my @events = sort {