+$dt = dt_from_string('2014-03-30 02:00:00');
+isa_ok( $dt, 'DateTime', 'dt_from_string should return a DateTime object if a DST is given' );
+
+# Test dt_from_string
+t::lib::Mocks::mock_preference('dateformat', 'metric');
+t::lib::Mocks::mock_preference('TimeFormat', '24hr');
+
+# dt_from_string should take into account the dateformat pref, or the given parameter
+$dt = dt_from_string('31/01/2015');
+is( ref($dt), 'DateTime', '31/01/2015 is a correct date in metric format' );
+is( output_pref( { dt => $dt, dateonly => 1 } ), '31/01/2015' );
+$dt = eval { dt_from_string( '31/01/2015', 'iso' ); };
+is( ref($dt), '', '31/01/2015 is not a correct date in iso format' );
+$dt = eval { dt_from_string( '01/01/2015', 'iso' ); };
+is( ref($dt), '', '01/01/2015 is not a correct date in iso format' );
+$dt = eval { dt_from_string( '01/01/2015', 'rfc3339' ); };
+is( ref($dt), '', '01/01/2015 is not a correct date in rfc3339 format' );
+$dt = eval { dt_from_string( '31/01/2015', 'us' ); };
+is( ref($dt), '', '31/01/2015 is not a correct date in us format' );
+$dt = dt_from_string( '01/01/2015', 'us' );
+is( ref($dt), 'DateTime', '01/01/2015 is a correct date in us format' );
+$dt = dt_from_string( '01.01.2015', 'dmydot' );
+is( ref($dt), 'DateTime', '01.01.2015 is a correct date in dmydot format' );
+
+
+# default value for hh and mm is 00:00
+$dt = dt_from_string('31/01/2015');
+is( output_pref( { dt => $dt } ), '31/01/2015 00:00', 'dt_from_string should generate a DT object with 00:00 as default hh:mm' );
+
+$dt = dt_from_string('31/01/2015 12:34');
+is( output_pref( { dt => $dt } ), '31/01/2015 12:34', 'dt_from_string should match hh:mm' );
+
+$dt = dt_from_string('31/01/2015 12:34:56');
+is( output_pref( { dt => $dt } ), '31/01/2015 12:34', 'dt_from_string should match hh:mm:ss' );
+
+# date before 1900
+$dt = dt_from_string('01/01/1900');
+is( output_pref( { dt => $dt, dateonly => 1 } ), '01/01/1900', 'dt_from_string should manage date < 1900' );
+
+# fallback
+$dt = dt_from_string('2015-01-31 01:02:03');
+is( output_pref( {dt => $dt} ), '31/01/2015 01:02', 'dt_from_string should fallback to sql format' );
+
+# output_pref with no parameters, single parameter (no hash)
+is( output_pref(), undef, 'Call output_pref without parameters' );
+try {
+ output_pref( 'no_dt' );
+ ok( 0, 'Passed single invalid dt to output_pref' );
+} catch {
+ is( ref($_), 'Koha::Exceptions::WrongParameter',
+ 'Passed single invalid dt to output_pref' );
+};
+
+# pass invalid dt via hash
+try {
+ output_pref({ dt => 'no_dt' });
+ ok( 0, 'Passed invalid dt in hash to output_pref' );
+} catch {
+ is( ref($_), 'Koha::Exceptions::WrongParameter',
+ 'Passed invalid dt in hash to output_pref' );
+};
+
+# output_pref with str parameter
+is( output_pref( { 'str' => $testdate_iso, dateformat => 'iso', dateonly => 1 } ), $testdate_iso, 'output_pref should handle correctly the iso parameter' );
+my $output_for_invalid_date;
+try {
+ $output_for_invalid_date = output_pref({ str => 'invalid_date' });
+ ok( 0, 'Invalid date string passed to output_pref' );
+} catch {
+ is( ref($_), 'Koha::Exceptions::WrongParameter',
+ 'Invalid date string passed to output_pref' );
+};
+is( $output_for_invalid_date, undef, 'No return value from output_pref' );
+try {
+ output_pref({ 'str' => $testdate_iso, dt => $dt, dateformat => 'iso', dateonly => 1 });
+ ok( 0, 'output_pref should carp if str and dt parameters are passed together' );
+} catch {
+ is( ref($_), 'Koha::Exceptions::WrongParameter', 'output_pref should throw an exception if str and dt parameters are passed together' );
+};
+
+# End of tests