diff options
Diffstat (limited to 'bin/events2md.pl')
-rwxr-xr-x | bin/events2md.pl | 65 |
1 files changed, 62 insertions, 3 deletions
diff --git a/bin/events2md.pl b/bin/events2md.pl index e9ef842..7192cb0 100755 --- a/bin/events2md.pl +++ b/bin/events2md.pl @@ -15,6 +15,9 @@ use URI; use DateTime; use Path::Tiny; use Text::Xslate; +use POSIX qw(locale_h); # resolve LC_TIME +use locale; +use DateTime::TimeZone; use Object::Groupware::DAV; use Object::Groupware::Calendar; @@ -24,7 +27,9 @@ if ( IO::Interactive::Tiny::is_interactive() ) { } # set defaults and parse command-line options -my ( $BASE_URI, $CALENDAR_URI, $SKELDIR, $OUTPUT_FILE ); +my ($BASE_URI, $CALENDAR_URI, $SKELDIR, $OUTPUT_FILE, $CALENDAR_LANG, + $CALENDAR_TIME_ZONE, %GROUPWARE_OPTIONS +); $BASE_URI = $ENV{CAL_DAV_URL_BASE}; $CALENDAR_URI = $ENV{CAL_DAV_URL_CALENDAR}; $SKELDIR = $ENV{SKELDIR} || "$Bin/../templates"; @@ -34,6 +39,53 @@ $CALENDAR_URI ||= shift @ARGV if @ARGV; $OUTPUT_FILE = shift @ARGV if @ARGV; +$CALENDAR_LANG = $ENV{CAL_LANG} || setlocale(LC_TIME); +$CALENDAR_TIME_ZONE + = DateTime::TimeZone->new( name => ( $ENV{CAL_TIME_ZONE} || 'local' ), ); + +# extend DateTime locale with form LONGER +# * omit year and second +# * unabbreviate weekday and month +# * interpose time preposition in combined date and time, where known +my %at = ( + C => " 'at' ", + ar => " 'في' ", + da => " 'kl.' ", + de => " 'um' ", + en => " 'at' ", + es => " 'a las' ", + fr => " 'à' ", + he => " 'בשעה' ", + it => " 'alle' ", + ja => "'に'", + no => " 'kl.' ", + ru => " 'в' ", + zh => "'在'", +); +my $dt_locale = DateTime::Locale->load($CALENDAR_LANG); +my ( $locale, $lang ) = $dt_locale->code =~ /^((\w+)(?:-\w+)?)/; +my $dt = DateTime->now( locale => $dt_locale ); +my %dt_locale_data = $dt_locale->locale_data; +$dt_locale_data{code} = "${locale}-LONGER"; +$dt_locale_data{name} .= ' nouns unabbreviated'; +$dt_locale_data{date_format_medium} = $dt->locale->format_for('MMMMEd'); +$dt_locale_data{date_format_medium} ||= $dt->locale->format_for('MMMEd'); +$dt_locale_data{date_format_medium} =~ s/\bMMM\b/MMMM/; +$dt_locale_data{date_format_medium} =~ s/\bMMM\b/MMMM/; +$dt_locale_data{date_format_medium} =~ s/\bE\b/EEEE/; +$dt_locale_data{time_format_medium} = $dt->locale->format_for('Hm'); +$dt_locale_data{datetime_format_medium} + =~ s/^\{1\}\K,? (?=\{0\}$)/$at{$lang}/ + if $at{$lang}; +%GROUPWARE_OPTIONS = ( + dt_locale => DateTime::Locale::FromData->new( \%dt_locale_data ), + dt_time_zone => $CALENDAR_TIME_ZONE, +); +$log->infof( + 'Will use locale %s and time zone %s', + $GROUPWARE_OPTIONS{dt_locale}->code, + $GROUPWARE_OPTIONS{dt_time_zone}->name, +); # resolve calendar URIs my ( $base_uri, $calendar_uri, $calendar ); @@ -56,6 +108,7 @@ if ( $base_uri->scheme eq 'http' or $base_uri->scheme eq 'https' ) { user => $ENV{CAL_DAV_USER}, pass => $ENV{CAL_DAV_PASS}, uri => $base_uri, + %GROUPWARE_OPTIONS, ); $calendar = $session->get($calendar_uri); } @@ -68,12 +121,18 @@ elsif ( $base_uri->scheme eq 'file' ) { $log->debug('parse local calendar data...'); my $path = path( $base_uri->file ); if ( $path->is_file ) { - $calendar = Object::Groupware::Calendar->new( filename => "$path" ); + $calendar = Object::Groupware::Calendar->new( + filename => "$path", + %GROUPWARE_OPTIONS, + ); } else { my $data; $path->visit( sub { $data .= $_->slurp_raw if $_->is_file } ); - $calendar = Object::Groupware::Calendar->new( data => $data ); + $calendar = Object::Groupware::Calendar->new( + data => $data, + %GROUPWARE_OPTIONS, + ); } } if ( $log->is_trace ) { |