use Koha::Database;
use Koha::Exceptions::Object;
+use Koha::DateUtils;
=head1 NAME
# is ported to whatever distro we support by that time
$unblessed->{$col} += 0;
}
+ elsif ( _datetime_column_type( $columns_info->{$col}->{data_type} ) ) {
+ eval {
+ return undef unless $unblessed->{$col};
+ $unblessed->{$col} = output_pref({
+ dateformat => 'rfc3339',
+ dt => dt_from_string($unblessed->{$col}, 'sql'),
+ });
+ };
+ }
}
return $unblessed;
}
+sub _datetime_column_type {
+ my ($column_type) = @_;
+
+ my @dt_types = (
+ 'timestamp',
+ 'datetime'
+ );
+
+ return ( grep { $column_type eq $_ } @dt_types) ? 1 : 0;
+}
+
sub _numeric_column_type {
# TODO: Remove once the solution for
# https://rt.cpan.org/Ticket/Display.html?id=119904
subtest 'TO_JSON tests' => sub {
- plan tests => 5;
+ plan tests => 7;
$schema->storage->txn_begin;
+ my $dt = dt_from_string();
my $borrowernumber = $builder->build(
{ source => 'Borrower',
value => { lost => 1,
- gonenoaddress => 0 } })->{borrowernumber};
+ gonenoaddress => 0,
+ updated_on => $dt,
+ lastseen => $dt, } })->{borrowernumber};
my $patron = Koha::Patrons->find($borrowernumber);
my $lost = $patron->TO_JSON()->{lost};
my $gonenoaddress = $patron->TO_JSON->{gonenoaddress};
+ my $updated_on = $patron->TO_JSON->{updated_on};
+ my $lastseen = $patron->TO_JSON->{lastseen};
ok( $lost->isa('JSON::PP::Boolean'), 'Boolean attribute type is correct' );
is( $lost, 1, 'Boolean attribute value is correct (true)' );
ok( !isvstring($patron->borrowernumber), 'Integer values are not coded as strings' );
+ my $rfc3999_regex = qr/
+ (?<year>\d{4})
+ -
+ (?<month>\d{2})
+ -
+ (?<day>\d{2})
+ ([Tt\s])
+ (?<hour>\d{2})
+ :
+ (?<minute>\d{2})
+ :
+ (?<second>\d{2})
+ (([Zz])|([\+|\-]([01][0-9]|2[0-3]):[0-5][0-9]))
+ /xms;
+ like( $updated_on, $rfc3999_regex, "Date-time $updated_on formatted correctly");
+ like( $lastseen, $rfc3999_regex, "Date-time $updated_on formatted correctly");
+
$schema->storage->txn_rollback;
};