Bugzilla – Attachment 134948 Details for
Bug 30717
Dates displayed in ISO format when editing items
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 30717: (QA follow-up) Move to module
Bug-30717-QA-follow-up-Move-to-module.patch (text/plain), 3.63 KB, created by
Marcel de Rooy
on 2022-05-13 07:48:10 UTC
(
hide
)
Description:
Bug 30717: (QA follow-up) Move to module
Filename:
MIME Type:
Creator:
Marcel de Rooy
Created:
2022-05-13 07:48:10 UTC
Size:
3.63 KB
patch
obsolete
>From 7b2d96163bd61e71eac947bad74311203c8e4bd3 Mon Sep 17 00:00:00 2001 >From: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >Date: Fri, 13 May 2022 07:29:04 +0000 >Subject: [PATCH] Bug 30717: (QA follow-up) Move to module >Content-Type: text/plain; charset=utf-8 > >We will probably use this a bit more :) >Let's put it in a module (with a trivial test). > >Test plan: >Repeat item edit. >Run t/DateUtils.t > >Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >--- > Koha/DateUtils.pm | 23 ++++++++++++++++++++ > cataloguing/value_builder/dateaccessioned.pl | 10 ++------- > t/DateUtils.t | 14 ++++++++++-- > 3 files changed, 37 insertions(+), 10 deletions(-) > >diff --git a/Koha/DateUtils.pm b/Koha/DateUtils.pm >index acd5dd13ff..2ee889aac5 100644 >--- a/Koha/DateUtils.pm >+++ b/Koha/DateUtils.pm >@@ -30,6 +30,7 @@ BEGIN { > dt_from_string > output_pref > format_sqldatetime >+ flatpickr_date_format > ); > } > >@@ -376,4 +377,26 @@ sub format_sqldatetime { > return q{}; > } > >+=head2 flatpickr_date_format >+ >+$date_format = flatpickr_date_format( $koha_date_format ); >+ >+Converts Koha's date format to Flatpickr's. E.g. 'us' returns 'm/d/Y'. >+ >+If no argument is given, the dateformat preference is assumed. >+ >+Returns undef if format is unknown. >+ >+=cut >+ >+sub flatpickr_date_format { >+ my $arg = shift // C4::Context->preference('dateformat'); >+ return { >+ us => 'm/d/Y', >+ metric => 'd/m/Y', >+ dmydot => 'd.m.Y', >+ iso => 'Y-m-d', >+ }->{$arg}; >+} >+ > 1; >diff --git a/cataloguing/value_builder/dateaccessioned.pl b/cataloguing/value_builder/dateaccessioned.pl >index 272b5aecfe..2f027c8e9a 100755 >--- a/cataloguing/value_builder/dateaccessioned.pl >+++ b/cataloguing/value_builder/dateaccessioned.pl >@@ -21,20 +21,14 @@ > # along with Koha; if not, see <http://www.gnu.org/licenses>. > > use Modern::Perl; >-use Koha::DateUtils qw( dt_from_string output_pref ); >+use Koha::DateUtils qw( dt_from_string output_pref flatpickr_date_format ); > > my $builder = sub { > my ( $params ) = @_; > my $function_name = $params->{id}; > > my $date = output_pref({ dt => dt_from_string, dateonly => 1 }); >- >- my $dateformat_pref = C4::Context->preference('dateformat'); >- my $dateformat = >- $dateformat_pref eq 'us' ? 'm/d/Y' >- : $dateformat_pref eq 'metric' ? 'd/m/Y' >- : $dateformat_pref eq 'dmydot' ? 'd.m.Y' >- : 'Y-m-d'; >+ my $dateformat = flatpickr_date_format(); > > my $res = <<END_OF_JS; > <script> >diff --git a/t/DateUtils.t b/t/DateUtils.t >index 27bea28d28..575e9c1358 100755 >--- a/t/DateUtils.t >+++ b/t/DateUtils.t >@@ -4,14 +4,14 @@ use DateTime::TimeZone; > > use C4::Context; > >-use Test::More tests => 82; >+use Test::More tests => 83; > > use Test::MockModule; > use Test::Warn; > use Time::HiRes qw/ gettimeofday /; > use Try::Tiny; > >-use Koha::DateUtils qw( dt_from_string output_pref format_sqldatetime ); >+use Koha::DateUtils qw( dt_from_string output_pref format_sqldatetime flatpickr_date_format ); > > use t::lib::Mocks; > >@@ -389,4 +389,14 @@ try { > is( ref($_), 'Koha::Exceptions::WrongParameter', 'output_pref should throw an exception if str and dt parameters are passed together' ); > }; > >+subtest 'flatpickr_date_format' => sub { >+ plan tests => 4; >+ >+ t::lib::Mocks::mock_preference('dateformat', 'iso'); >+ is( flatpickr_date_format(), 'Y-m-d', 'check fallback to pref' ); >+ is( flatpickr_date_format(q{}), undef, 'empty string' ); >+ is( flatpickr_date_format('metric'), 'd/m/Y', 'check valid arg' ); >+ is( flatpickr_date_format('zz'), undef, 'wrong arg' ); >+}; >+ > # End of tests >-- >2.20.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 30717
:
134781
|
134797
|
134947
| 134948 |
137613