Skip to content

Commit 48bf9b1

Browse files
joubutomascohen
authored andcommitted
Bug 30718: Use flatpickr's altInput
The idea rely on the KohaDates TT plugin for the date formatting. We should not have any output_pref calls in pl or pm (there are some exceptions, for ILSDI for instance). Also flatpickr will deal with the places where dates are inputed. We will pass the raw SQL value (what we call 'iso' in Koha::DateUtils), and the controller will receive the same value, no need to additional conversion. Note that DBIC has the capability to auto-deflate DateTime objects, which makes things way easier. We can either pass the value we receive from the controller, or pass a DT object to our methods. Signed-off-by: Victor Grousset/tuxayo <victor@tuxayo.net> Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
1 parent b02b66a commit 48bf9b1

File tree

113 files changed

+294
-698
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

113 files changed

+294
-698
lines changed

C4/Acquisition.pm

+4-9
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use C4::Biblio qw( GetMarcFromKohaField GetMarcStructure IsMarcStructureInternal
2727
use C4::Contract qw( GetContract );
2828
use C4::Log qw( logaction );
2929
use C4::Templates qw(gettemplate);
30-
use Koha::DateUtils qw( dt_from_string output_pref );
30+
use Koha::DateUtils qw( dt_from_string );
3131
use Koha::Acquisition::Baskets;
3232
use Koha::Acquisition::Booksellers;
3333
use Koha::Acquisition::Orders;
@@ -1374,13 +1374,8 @@ sub ModReceiveOrder {
13741374
my $received_items = $params->{received_items};
13751375

13761376
my $dbh = C4::Context->dbh;
1377-
$datereceived = output_pref(
1378-
{
1379-
dt => ( $datereceived ? dt_from_string( $datereceived ) : dt_from_string ),
1380-
dateformat => 'iso',
1381-
dateonly => 1,
1382-
}
1383-
);
1377+
$datereceived = $datereceived ? dt_from_string( $datereceived ) : dt_from_string;
1378+
$datereceived = $datereceived->ymd;
13841379

13851380
my $suggestionid = GetSuggestionFromBiblionumber( $biblionumber );
13861381
if ($suggestionid) {
@@ -2728,7 +2723,7 @@ sub CloseInvoice {
27282723
27292724
Reopen an invoice
27302725
2731-
Equivalent to ModInvoice(invoiceid => $invoiceid, closedate => output_pref({ dt=>dt_from_string, dateonly=>1, otputpref=>'iso' }))
2726+
Equivalent to ModInvoice(invoiceid => $invoiceid, closedate => $closedate );
27322727
27332728
=cut
27342729

C4/Barcodes/annual.pm

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ use Carp qw( carp );
2424

2525
use C4::Context;
2626

27+
# FIXME We should certainly remove output_pref from here
2728
use Koha::DateUtils qw( dt_from_string output_pref );
2829

2930
use vars qw(@ISA);

C4/Barcodes/hbyymmincr.pm

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use Carp qw( carp );
2323

2424
use C4::Context;
2525

26+
# FIXME We should certainly remove output_pref from here
2627
use Koha::DateUtils qw( dt_from_string output_pref );
2728

2829
use constant WIDTH => 4; # FIXME: too small for sizeable or multi-branch libraries?

C4/Circulation.pm

+15-19
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ use POSIX qw( floor );
2424
use YAML::XS;
2525
use Encode;
2626

27-
use Koha::DateUtils qw( dt_from_string output_pref );
2827
use C4::Context;
2928
use C4::Stats qw( UpdateStats );
3029
use C4::Reserves qw( CheckReserves CanItemBeReserved MoveReserve ModReserve ModReserveMinusPriority RevertWaitingStatus IsItemOnHoldAndFound IsAvailableForItemLevelRequest ItemsAnyAvailableAndNotRestricted );
@@ -43,7 +42,7 @@ use Koha::Account;
4342
use Koha::AuthorisedValues;
4443
use Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue;
4544
use Koha::Biblioitems;
46-
use Koha::DateUtils qw( dt_from_string output_pref );
45+
use Koha::DateUtils qw( dt_from_string );
4746
use Koha::Calendar;
4847
use Koha::Checkouts;
4948
use Koha::Illrequests;
@@ -798,7 +797,7 @@ sub CanBookBeIssued {
798797
my $now = dt_from_string();
799798
$duedate ||= CalcDateDue( $now, $effective_itemtype, $circ_library->branchcode, $patron_unblessed );
800799
if (DateTime->compare($duedate,$now) == -1 ) { # duedate cannot be before now
801-
$needsconfirmation{INVALID_DATE} = output_pref($duedate);
800+
$needsconfirmation{INVALID_DATE} = $duedate;
802801
}
803802

804803
my $fees = Koha::Charges::Fees->new(
@@ -1235,19 +1234,16 @@ sub CanBookBeIssued {
12351234
my $check = checkHighHolds( $item_object, $patron );
12361235

12371236
if ( $check->{exceeded} ) {
1237+
my $highholds = {
1238+
num_holds => $check->{outstanding},
1239+
duration => $check->{duration},
1240+
returndate => $check->{due_date},
1241+
};
12381242
if ($override_high_holds) {
1239-
$alerts{HIGHHOLDS} = {
1240-
num_holds => $check->{outstanding},
1241-
duration => $check->{duration},
1242-
returndate => output_pref( { dt => dt_from_string($check->{due_date}), dateformat => 'iso', timeformat => '24hr' }),
1243-
};
1243+
$alerts{HIGHHOLDS} = $highholds;
12441244
}
12451245
else {
1246-
$needsconfirmation{HIGHHOLDS} = {
1247-
num_holds => $check->{outstanding},
1248-
duration => $check->{duration},
1249-
returndate => output_pref( { dt => dt_from_string($check->{due_date}), dateformat => 'iso', timeformat => '24hr' }),
1250-
};
1246+
$needsconfirmation{HIGHHOLDS} = $highholds;
12511247
}
12521248
}
12531249
}
@@ -1462,8 +1458,8 @@ Calculated if empty.
14621458
14631459
=item C<$cancelreserve> is 1 to override and cancel any pending reserves for the item (optional).
14641460
1465-
=item C<$issuedate> is the date to issue the item in iso (YYYY-MM-DD) format (optional).
1466-
Defaults to today. Unlike C<$datedue>, NOT a DateTime object, unfortunately.
1461+
=item C<$issuedate> is a DateTime object for the date to issue the item (optional).
1462+
Defaults to today.
14671463
14681464
AddIssue does the following things :
14691465
@@ -1635,8 +1631,8 @@ sub AddIssue {
16351631

16361632
my $issue_attributes = {
16371633
borrowernumber => $borrower->{'borrowernumber'},
1638-
issuedate => $issuedate->strftime('%Y-%m-%d %H:%M:%S'),
1639-
date_due => $datedue->strftime('%Y-%m-%d %H:%M:%S'),
1634+
issuedate => $issuedate,
1635+
date_due => $datedue,
16401636
branchcode => C4::Context->userenv->{'branch'},
16411637
onsite_checkout => $onsite_checkout,
16421638
auto_renew => $auto_renew ? 1 : 0,
@@ -4423,7 +4419,7 @@ sub _CalculateAndUpdateFine {
44234419
itemnumber => $issue->itemnumber,
44244420
borrowernumber => $issue->borrowernumber,
44254421
amount => $amount,
4426-
due => output_pref($datedue),
4422+
due => $datedue,
44274423
});
44284424
}
44294425
elsif ($return_date) {
@@ -4436,7 +4432,7 @@ sub _CalculateAndUpdateFine {
44364432
itemnumber => $issue->itemnumber,
44374433
borrowernumber => $issue->borrowernumber,
44384434
amount => 0,
4439-
due => output_pref($datedue),
4435+
due => $datedue,
44404436
});
44414437
}
44424438
}

C4/ILSDI/Services.pm

+5-18
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,7 @@ sub RenewLoan {
694694
# Hashref building
695695
my $out;
696696
$out->{'renewals'} = $issue->renewals_count;
697+
# FIXME Unusual date formatting
697698
$out->{date_due} = dt_from_string($issue->date_due)->strftime('%Y-%m-%d %H:%M');
698699
$out->{'success'} = $renewal[0];
699700
$out->{'error'} = $renewal[1];
@@ -774,15 +775,8 @@ sub HoldTitle {
774775
return { code => 'libraryNotPickupLocation' } unless $destination->pickup_location;
775776
return { code => 'cannotBeTransferred' } unless $biblio->can_be_transferred({ to => $destination });
776777

777-
my $resdate;
778-
if ( $cgi->param('start_date') ) {
779-
$resdate = $cgi->param('start_date');
780-
}
781-
782-
my $expdate;
783-
if ( $cgi->param('expiry_date') ) {
784-
$expdate = $cgi->param('expiry_date');
785-
}
778+
my $resdate = $cgi->param('start_date');
779+
my $expdate = $cgi->param('expiry_date');
786780

787781
# Add the reserve
788782
# $branch, $borrowernumber, $biblionumber,
@@ -876,15 +870,8 @@ sub HoldItem {
876870
my $canitembereserved = C4::Reserves::CanItemBeReserved( $patron, $item, $branch )->{status};
877871
return { code => $canitembereserved } unless $canitembereserved eq 'OK';
878872

879-
my $resdate;
880-
if ( $cgi->param('start_date') ) {
881-
$resdate = $cgi->param('start_date');
882-
}
883-
884-
my $expdate;
885-
if ( $cgi->param('expiry_date') ) {
886-
$expdate = $cgi->param('expiry_date');
887-
}
873+
my $resdate = $cgi->param('start_date');
874+
my $expdate = $cgi->param('expiry_date');
888875

889876
# Add the reserve
890877
my $priority = C4::Reserves::CalculatePriority($biblionumber);

C4/Items.pm

+2-6
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ use Carp qw( croak );
5151
use C4::Context;
5252
use C4::Koha;
5353
use C4::Biblio qw( GetMarcStructure TransformMarcToKoha );
54-
use Koha::DateUtils qw( dt_from_string output_pref );
5554
use MARC::Record;
5655
use C4::ClassSource qw( GetClassSort GetClassSources GetClassSource );
5756
use C4::Log qw( logaction );
@@ -60,7 +59,7 @@ use DateTime::Format::MySQL;
6059
# debugging; so please don't remove this
6160

6261
use Koha::AuthorisedValues;
63-
use Koha::DateUtils qw( dt_from_string output_pref );
62+
use Koha::DateUtils qw( dt_from_string );
6463
use Koha::Database;
6564

6665
use Koha::Biblios;
@@ -403,10 +402,8 @@ The last optional parameter allows for passing skip_record_index through to the
403402
sub ModDateLastSeen {
404403
my ( $itemnumber, $leave_item_lost, $params ) = @_;
405404

406-
my $today = output_pref({ dt => dt_from_string, dateformat => 'iso', dateonly => 1 });
407-
408405
my $item = Koha::Items->find($itemnumber);
409-
$item->datelastseen($today);
406+
$item->datelastseen(dt_from_string);
410407
$item->itemlost(0) unless $leave_item_lost;
411408
$item->store({ log_action => 0, skip_record_index => $params->{skip_record_index}, skip_holds_queue => $params->{skip_holds_queue} });
412409
}
@@ -587,7 +584,6 @@ sub GetItemsForInventory {
587584
}
588585

589586
if ($datelastseen) {
590-
$datelastseen = output_pref({ str => $datelastseen, dateformat => 'iso', dateonly => 1 });
591587
push @where_strings, '(datelastseen < ? OR datelastseen IS NULL)';
592588
push @bind_params, $datelastseen;
593589
}

C4/Letters.pm

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ use C4::Members;
2929
use C4::Log qw( logaction );
3030
use C4::SMS;
3131
use C4::Templates;
32-
use Koha::DateUtils qw( dt_from_string output_pref );
3332
use Koha::SMS::Providers;
3433

3534
use Koha::Email;
@@ -788,6 +787,7 @@ sub _parseletter {
788787
# in callers ( by changing / formatting values )
789788
my $values = $values_in ? { %$values_in } : {};
790789

790+
# FIXME Dates formatting must be done in notice's templates
791791
if ( $table eq 'borrowers' && $values->{'dateexpiry'} ){
792792
$values->{'dateexpiry'} = output_pref({ dt => dt_from_string( $values->{'dateexpiry'} ), dateonly => 1 });
793793
}

C4/Members.pm

+1
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,7 @@ sub IssueSlip {
596596

597597
# FIXME We keep newdate and timestamp for backward compatibility (from GetNewsToDisplay)
598598
# But we should remove them and adjust the existing templates in a db rev
599+
# FIXME This must be formatted in the notice template
599600
my $published_on_dt = output_pref({ dt => dt_from_string( $all->{published_on} ), dateonly => 1 });
600601
$all->{newdate} = $published_on_dt;
601602
$all->{timestamp} = $published_on_dt;

C4/Overdues.pm

+3-3
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ use C4::Accounts;
3131
use C4::Context;
3232
use Koha::Account::Lines;
3333
use Koha::Account::Offsets;
34+
use Koha::DateUtils qw( output_pref );
3435
use Koha::Libraries;
3536
use Koha::Recalls;
3637
use Koha::Logger;
@@ -512,7 +513,7 @@ has the book on loan.
512513
513514
C<$amount> is the current amount owed by the patron.
514515
515-
C<$due> is the due date formatted to the currently specified date format
516+
C<$due> is the date
516517
517518
C<&UpdateFine> looks up the amount currently owed on the given item
518519
and sets it to C<$amount>, creating, if necessary, a new entry in the
@@ -552,7 +553,6 @@ sub UpdateFine {
552553

553554
my $accountline;
554555
my $total_amount_other = 0.00;
555-
my $due_qr = qr/$due/;
556556
# Cycle through the fines and
557557
# - find line that relates to the requested $itemnum
558558
# - accumulate fines for other items
@@ -610,7 +610,7 @@ sub UpdateFine {
610610
items => $itemnum,
611611
},
612612
) };
613-
my $desc = $letter ? $letter->{content} : "Item $itemnum - due $due";
613+
my $desc = $letter ? $letter->{content} : sprintf("Item %s - due %s", $itemnum, output_pref($due) );
614614

615615
my $account = Koha::Account->new({ patron_id => $borrowernumber });
616616
$accountline = $account->add_debit(

C4/Reports/Guided.pm

+1-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use JSON qw( from_json );
2525
use C4::Context;
2626
use C4::Templates qw/themelanguage/;
2727
use C4::Koha qw( GetAuthorisedValues );
28-
use Koha::DateUtils qw( dt_from_string output_pref );
28+
use Koha::DateUtils qw( dt_from_string );
2929
use Koha::Patrons;
3030
use Koha::Reports;
3131
use C4::Output;
@@ -753,7 +753,6 @@ sub get_saved_reports {
753753
my (@cond,@args);
754754
if ($filter) {
755755
if (my $date = $filter->{date}) {
756-
$date = eval { output_pref( { dt => dt_from_string( $date ), dateonly => 1, dateformat => 'iso' }); };
757756
push @cond, "DATE(last_modified) = ? OR
758757
DATE(last_run) = ?";
759758
push @args, $date, $date;

C4/Reserves.pm

+3-12
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ use Koha::Biblios;
3838
use Koha::Calendar;
3939
use Koha::CirculationRules;
4040
use Koha::Database;
41-
use Koha::DateUtils qw( dt_from_string output_pref );
41+
use Koha::DateUtils qw( dt_from_string );
4242
use Koha::Hold;
4343
use Koha::Holds;
4444
use Koha::ItemTypes;
@@ -194,10 +194,7 @@ sub AddReserve {
194194
my $itemtype = $params->{itemtype};
195195
my $non_priority = $params->{non_priority};
196196

197-
$resdate = output_pref( { str => dt_from_string( $resdate ), dateonly => 1, dateformat => 'iso' })
198-
or output_pref({ dt => dt_from_string, dateonly => 1, dateformat => 'iso' });
199-
200-
$patron_expiration_date = output_pref({ str => $patron_expiration_date, dateonly => 1, dateformat => 'iso' });
197+
$resdate ||= dt_from_string;
201198

202199
# if we have an item selectionned, and the pickup branch is the same as the holdingbranch
203200
# of the document, we force the value $priority and $found .
@@ -1124,7 +1121,7 @@ sub ModReserve {
11241121
if C4::Context->preference('HoldsLog');
11251122

11261123
# The only column that can be updated for a found hold is the expiration date
1127-
$hold->expirationdate(dt_from_string($date))->store();
1124+
$hold->expirationdate($date)->store();
11281125
}
11291126
elsif ($rank =~ /^\d+/ and $rank > 0) {
11301127
logaction( 'HOLDS', 'MODIFY', $hold->reserve_id, $hold )
@@ -1148,7 +1145,6 @@ sub ModReserve {
11481145

11491146
if ( defined( $suspend_until ) ) {
11501147
if ( $suspend_until ) {
1151-
$suspend_until = eval { dt_from_string( $suspend_until ) };
11521148
$hold->suspend_hold( $suspend_until );
11531149
} else {
11541150
# If the hold is suspended leave the hold suspended, but convert it to an indefinite hold.
@@ -1523,8 +1519,6 @@ be cleared when it is unsuspended.
15231519
sub ToggleSuspend {
15241520
my ( $reserve_id, $suspend_until ) = @_;
15251521

1526-
$suspend_until = dt_from_string($suspend_until) if ($suspend_until);
1527-
15281522
my $hold = Koha::Holds->find( $reserve_id );
15291523

15301524
if ( $hold->is_suspended ) {
@@ -1558,9 +1552,6 @@ sub SuspendAll {
15581552
my $suspend_until = $params{'suspend_until'} || undef;
15591553
my $suspend = defined( $params{'suspend'} ) ? $params{'suspend'} : 1;
15601554

1561-
$suspend_until = eval { dt_from_string($suspend_until) }
1562-
if ( defined($suspend_until) );
1563-
15641555
return unless ( $borrowernumber || $biblionumber );
15651556

15661557
my $params;

C4/Search/History.pm

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ sub add_to_session {
5151
query_cgi => $query_cgi,
5252
total => "$total",
5353
type => $type,
54+
# FIXME We shouldn't store the formatted date
5455
time => output_pref( { dt => $now, dateformat => 'iso', timeformat => '24hr' } ),
5556
id => $id,
5657
};

0 commit comments

Comments
 (0)