View | Details | Raw Unified | Return to bug 18330
Collapse All | Expand All

(-)a/Koha/Object.pm (+21 lines)
Lines 25-30 use Mojo::JSON; Link Here
25
25
26
use Koha::Database;
26
use Koha::Database;
27
use Koha::Exceptions::Object;
27
use Koha::Exceptions::Object;
28
use Koha::DateUtils;
28
29
29
=head1 NAME
30
=head1 NAME
30
31
Lines 221-230 sub TO_JSON { Link Here
221
            # is ported to whatever distro we support by that time
222
            # is ported to whatever distro we support by that time
222
            $unblessed->{$col} += 0;
223
            $unblessed->{$col} += 0;
223
        }
224
        }
225
        elsif ( _datetime_column_type( $columns_info->{$col}->{data_type} ) ) {
226
            eval {
227
                return undef unless $unblessed->{$col};
228
                $unblessed->{$col} = output_pref({
229
                    dateformat => 'rfc3339',
230
                    dt         => dt_from_string($unblessed->{$col}, 'sql'),
231
                });
232
            };
233
        }
224
    }
234
    }
225
    return $unblessed;
235
    return $unblessed;
226
}
236
}
227
237
238
sub _datetime_column_type {
239
    my ($column_type) = @_;
240
241
    my @dt_types = (
242
        'timestamp',
243
        'datetime'
244
    );
245
246
    return ( grep { $column_type eq $_ } @dt_types) ? 1 : 0;
247
}
248
228
sub _numeric_column_type {
249
sub _numeric_column_type {
229
    # TODO: Remove once the solution for
250
    # TODO: Remove once the solution for
230
    # https://rt.cpan.org/Ticket/Display.html?id=119904
251
    # https://rt.cpan.org/Ticket/Display.html?id=119904
(-)a/t/db_dependent/Koha/Object.t (-3 / +24 lines)
Lines 146-163 subtest 'discard_changes' => sub { Link Here
146
146
147
subtest 'TO_JSON tests' => sub {
147
subtest 'TO_JSON tests' => sub {
148
148
149
    plan tests => 5;
149
    plan tests => 7;
150
150
151
    $schema->storage->txn_begin;
151
    $schema->storage->txn_begin;
152
152
153
    my $dt = dt_from_string();
153
    my $borrowernumber = $builder->build(
154
    my $borrowernumber = $builder->build(
154
        { source => 'Borrower',
155
        { source => 'Borrower',
155
          value => { lost => 1,
156
          value => { lost => 1,
156
                     gonenoaddress => 0 } })->{borrowernumber};
157
                     gonenoaddress => 0,
158
                     updated_on => $dt,
159
                     lastseen   => $dt, } })->{borrowernumber};
157
160
158
    my $patron = Koha::Patrons->find($borrowernumber);
161
    my $patron = Koha::Patrons->find($borrowernumber);
159
    my $lost = $patron->TO_JSON()->{lost};
162
    my $lost = $patron->TO_JSON()->{lost};
160
    my $gonenoaddress = $patron->TO_JSON->{gonenoaddress};
163
    my $gonenoaddress = $patron->TO_JSON->{gonenoaddress};
164
    my $updated_on = $patron->TO_JSON->{updated_on};
165
    my $lastseen = $patron->TO_JSON->{lastseen};
161
166
162
    ok( $lost->isa('JSON::PP::Boolean'), 'Boolean attribute type is correct' );
167
    ok( $lost->isa('JSON::PP::Boolean'), 'Boolean attribute type is correct' );
163
    is( $lost, 1, 'Boolean attribute value is correct (true)' );
168
    is( $lost, 1, 'Boolean attribute value is correct (true)' );
Lines 167-172 subtest 'TO_JSON tests' => sub { Link Here
167
172
168
    ok( !isvstring($patron->borrowernumber), 'Integer values are not coded as strings' );
173
    ok( !isvstring($patron->borrowernumber), 'Integer values are not coded as strings' );
169
174
175
    my $rfc3999_regex = qr/
176
            (?<year>\d{4})
177
            -
178
            (?<month>\d{2})
179
            -
180
            (?<day>\d{2})
181
            ([Tt\s])
182
            (?<hour>\d{2})
183
            :
184
            (?<minute>\d{2})
185
            :
186
            (?<second>\d{2})
187
            (([Zz])|([\+|\-]([01][0-9]|2[0-3]):[0-5][0-9]))
188
        /xms;
189
    like( $updated_on, $rfc3999_regex, "Date-time $updated_on formatted correctly");
190
    like( $lastseen, $rfc3999_regex, "Date-time $updated_on formatted correctly");
191
170
    $schema->storage->txn_rollback;
192
    $schema->storage->txn_rollback;
171
};
193
};
172
194
173
- 

Return to bug 18330