https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=38758
Bug ID: 38758
Summary: Make formatting date and datetime fields in notices a
bit shorter/easier
Change sponsored?: ---
Product: Koha
Version: Main
Hardware: All
OS: All
Status: NEW
Severity: enhancement
Priority: P5 - low
Component: Notices
Assignee: [email protected]
Reporter: [email protected]
QA Contact: [email protected]
Currently, date formatting in notices with the TT Date plugin is a bit user
unfriendly since the plugin has very simplistic parsing that only works on
datetime or timestamp fields but not on date only fields (like commonly used
fields as borrower.dateexpiry or reserves.reservedate etc.) Should a user of
Reports know that? (No.)
So this works:
[% date.format(borrower.updated_on, "%B %d, %Y") %]
But this does not:
[% date.format(borrower.dateexpiry, "%B %d, %Y") %]
ERROR PROCESSING TEMPLATE: date error - bad time/date string: expects
'h:m:s d:m:y'
But we can overcome that by doing something like (for both date as well as
datetime):
[% KohaDates.datetime_from_string(mydate).strftime("%B %d, %Y") %] #
where e.g. mydate == borrower.dateexpiry
Note that it is a bit long and somewhat complex (unfriendly). (And btw,
datetime_from_string does not check the result of dt_from_string but just
assumes to get a DateTime object.)
What about the shorter and more intuitive (for both date and datetime fields):
[% mydate.strftime("%B %d, %Y") %]
Or giving yet another example with a locale different from the default en_US:
[%
KohaDates.datetime_from_string(mydate).set_locale('nl_NL').strftime("%d %B %Y")
%]
Would this not read better:
[% mydate.strftime("%d %B %Y", "nl_NL") %]
The proposed patch adds a TT virtual method strftime that can be run on scalars
as in the examples above (for date and datetime). No mention of KohaDates
needed, no chaining of set_locale. Wont crash on invalid dates, just passes the
original value if date could not be parsed. And importantly, the former
KohaDates constructs with strftime still work (going via DateTime->strftime),
so backwards compatible.
Shorter and easier! What do you think?
--
You are receiving this mail because:
You are the assignee for the bug.
You are watching all bug changes.
_______________________________________________
Koha-bugs mailing list
[email protected]
https://lists.koha-community.org/cgi-bin/mailman/listinfo/koha-bugs
website : http://www.koha-community.org/
git : http://git.koha-community.org/
bugs : http://bugs.koha-community.org/