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

(-)a/Koha/DateUtils.pm (+23 lines)
Lines 30-35 BEGIN { Link Here
30
        dt_from_string
30
        dt_from_string
31
        output_pref
31
        output_pref
32
        format_sqldatetime
32
        format_sqldatetime
33
        flatpickr_date_format
33
    );
34
    );
34
}
35
}
35
36
Lines 376-379 sub format_sqldatetime { Link Here
376
    return q{};
377
    return q{};
377
}
378
}
378
379
380
=head2 flatpickr_date_format
381
382
$date_format = flatpickr_date_format( $koha_date_format );
383
384
Converts Koha's date format to Flatpickr's. E.g. 'us' returns 'm/d/Y'.
385
386
If no argument is given, the dateformat preference is assumed.
387
388
Returns undef if format is unknown.
389
390
=cut
391
392
sub flatpickr_date_format {
393
    my $arg = shift // C4::Context->preference('dateformat');
394
    return {
395
        us     => 'm/d/Y',
396
        metric => 'd/m/Y',
397
        dmydot => 'd.m.Y',
398
        iso    => 'Y-m-d',
399
    }->{$arg};
400
}
401
379
1;
402
1;
(-)a/cataloguing/value_builder/dateaccessioned.pl (-8 / +2 lines)
Lines 21-40 Link Here
21
# along with Koha; if not, see <http://www.gnu.org/licenses>.
21
# along with Koha; if not, see <http://www.gnu.org/licenses>.
22
22
23
use Modern::Perl;
23
use Modern::Perl;
24
use Koha::DateUtils qw( dt_from_string output_pref );
24
use Koha::DateUtils qw( dt_from_string output_pref flatpickr_date_format );
25
25
26
my $builder = sub {
26
my $builder = sub {
27
    my ( $params ) = @_;
27
    my ( $params ) = @_;
28
    my $function_name = $params->{id};
28
    my $function_name = $params->{id};
29
29
30
    my $date = output_pref({ dt => dt_from_string, dateonly => 1 });
30
    my $date = output_pref({ dt => dt_from_string, dateonly => 1 });
31
31
    my $dateformat = flatpickr_date_format();
32
    my $dateformat_pref = C4::Context->preference('dateformat');
33
    my $dateformat =
34
        $dateformat_pref eq 'us'     ? 'm/d/Y'
35
      : $dateformat_pref eq 'metric' ? 'd/m/Y'
36
      : $dateformat_pref eq 'dmydot' ? 'd.m.Y'
37
      :                                'Y-m-d';
38
32
39
    my $res  = <<END_OF_JS;
33
    my $res  = <<END_OF_JS;
40
<script>
34
<script>
(-)a/t/DateUtils.t (-3 / +12 lines)
Lines 4-17 use DateTime::TimeZone; Link Here
4
4
5
use C4::Context;
5
use C4::Context;
6
6
7
use Test::More tests => 82;
7
use Test::More tests => 83;
8
8
9
use Test::MockModule;
9
use Test::MockModule;
10
use Test::Warn;
10
use Test::Warn;
11
use Time::HiRes qw/ gettimeofday /;
11
use Time::HiRes qw/ gettimeofday /;
12
use Try::Tiny;
12
use Try::Tiny;
13
13
14
use Koha::DateUtils qw( dt_from_string output_pref format_sqldatetime );
14
use Koha::DateUtils qw( dt_from_string output_pref format_sqldatetime flatpickr_date_format );
15
15
16
use t::lib::Mocks;
16
use t::lib::Mocks;
17
17
Lines 389-392 try { Link Here
389
    is( ref($_), 'Koha::Exceptions::WrongParameter', 'output_pref should throw an exception if str and dt parameters are passed together' );
389
    is( ref($_), 'Koha::Exceptions::WrongParameter', 'output_pref should throw an exception if str and dt parameters are passed together' );
390
};
390
};
391
391
392
subtest 'flatpickr_date_format' => sub {
393
    plan tests => 4;
394
395
    t::lib::Mocks::mock_preference('dateformat', 'iso');
396
    is( flatpickr_date_format(), 'Y-m-d', 'check fallback to pref' );
397
    is( flatpickr_date_format(q{}), undef, 'empty string' );
398
    is( flatpickr_date_format('metric'), 'd/m/Y', 'check valid arg' );
399
    is( flatpickr_date_format('zz'), undef, 'wrong arg' );
400
};
401
392
# End of tests
402
# End of tests
393
- 

Return to bug 30717