use Modern::Perl;
use DateTime;
use C4::Context;
-use Carp;
+use Koha::Exceptions;
use base 'Exporter';
-use version; our $VERSION = qv('1.0.0');
our @EXPORT = (
qw( dt_from_string output_pref format_sqldatetime )
(?<year>\d{4})
|xms;
}
+ elsif ( $date_format eq 'dmydot' ) {
+ # dmydot format is "dd.mm.yyyy[ hh:mm:ss]"
+ $regex = qr|
+ (?<day>\d{2})
+ .
+ (?<month>\d{2})
+ .
+ (?<year>\d{4})
+ |xms;
+ }
elsif ( $date_format eq 'us' ) {
# us format is "mm/dd/yyyy[ hh:mm:ss]"
$regex = qr|
$dt = $params;
}
- carp "output_pref should not be called with both dt and str parameters"
- and return
- if $dt and $str;
+ Koha::Exceptions::WrongParameter->throw( 'output_pref should not be called with both dt and str parameter' ) if $dt and $str;
- $dt = eval { dt_from_string( $str ) } if $str;
- carp "Invalid date '$str' passed to output_pref\n" if $@;
+ if ( $str ) {
+ local $@;
+ $dt = eval { dt_from_string( $str ) };
+ Koha::Exceptions::WrongParameter->throw("Invalid date '$str' passed to output_pref" ) if $@;
+ }
- return unless defined $dt;
+ return if !defined $dt; # NULL date
+ Koha::Exceptions::WrongParameter->throw( 'dt is not a datetime' ) if ref($dt) ne 'DateTime';
# FIXME: see bug 13242 => no TZ for dates 'infinite'
if ( $dt->ymd !~ /^9999/ ) {
? $dt->strftime("%d/%m/%Y")
: $dt->strftime("%d/%m/%Y $time");
}
+ elsif ( $pref =~ m/^dmydot/ ) {
+ $date = $dateonly
+ ? $dt->strftime("%d.%m.%Y")
+ : $dt->strftime("%d.%m.%Y $time");
+ }
+
elsif ( $pref =~ m/^us/ ) {
$date = $dateonly
? $dt->strftime("%m/%d/%Y")