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 )
$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/ ) {