diff options
Diffstat (limited to 'lib/Object/Groupware/Event.pm')
-rw-r--r-- | lib/Object/Groupware/Event.pm | 57 |
1 files changed, 39 insertions, 18 deletions
diff --git a/lib/Object/Groupware/Event.pm b/lib/Object/Groupware/Event.pm index 52fa143..c5ccb6e 100644 --- a/lib/Object/Groupware/Event.pm +++ b/lib/Object/Groupware/Event.pm @@ -3,50 +3,71 @@ use Feature::Compat::Class 0.07; package Object::Groupware::Event 0.01; -class Object::Groupware::Event; +class Object::Groupware::Event : isa(Object::Groupware); use utf8; use Log::Any qw( ); use Feature::Compat::Try; +use DateTime::Locale; field $log = Log::Any->get_logger; field $entry : param; +field $dt_locale; -field $begin : reader = $entry->start; -field $date_begin : reader = $begin->strftime('%A %e. %B'); -field $time_begin : reader = $begin->strftime('%k.%M'); -field $end : reader = $entry->end; -field $date_end : reader; -field $time_end : reader; +field $begin : reader = $entry->start; +field $end : reader = $entry->end; field $datespan : reader; field $timespan : reader; field $time_brief : reader; field $summary : reader = $entry->summary; -field $description : reader = $entry->description; +field $description : reader = $entry->description || ''; field $location : reader = $entry->_simple_property('location'); field $price : reader; field @attendees; field @attachments; ADJUST { - if ( defined $end ) { - $date_end = $end->strftime('%A %e. %B'); - $time_end = $end->strftime('%k.%M'); + if ( $self->dt_locale ) { + $dt_locale = $self->dt_locale; + $begin->set_locale($dt_locale); + $end->set_locale($dt_locale) if defined $end; + } + else { + + # we need the object regardless, to fetch CLDR patterns + $dt_locale = DateTime::Locale->load('en_US'); + } + + $begin->set_locale( $self->dt_locale ); + + for ( $self->dt_time_zone || () ) { + $begin->set_time_zone($_); + $end->set_time_zone($_) if defined $end; } $datespan - = ( defined $end and $date_end ne $date_begin ) - ? ucfirst("$date_begin - $date_end") - : ucfirst("$date_begin"); - $timespan - = ( defined $end and not $entry->all_day ) - ? ucfirst("$date_begin kl. $time_begin-$time_end") + = ( defined $end + and $end->clone->truncate( to => 'day' ) ne + $begin->clone->truncate( to => 'day' ) ) + ? ucfirst( + sprintf '%s - %s', + $begin->format_cldr( $dt_locale->date_format_medium() ), + $end->format_cldr( $dt_locale->date_format_medium() ) + ) + : ucfirst( $begin->format_cldr( $dt_locale->date_format_medium() ) ); + $timespan = ( defined $end and not $entry->all_day ) + ? ucfirst( + sprintf '%s-%s', + $begin->format_cldr( $dt_locale->datetime_format_medium() ), + $end->format_cldr( $dt_locale->time_format_medium() ) + ) : undef; $time_brief = $entry->all_day ? $datespan - : ucfirst("$date_begin kl. $time_begin"); + : ucfirst( + $begin->format_cldr( $dt_locale->datetime_format_medium() ) ); $description =~ s/\n\n[Pp]ris:\s*((?!\n).+)\s*\z//m; $price = $1; |