[Bug 38758] New: Make formatting date and datetime fields in notices a bit shorter/easier
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: koha-bugs@lists.koha-community.org Reporter: m.de.rooy@rijksmuseum.nl QA Contact: testopia@bugs.koha-community.org 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.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=38758 Marcel de Rooy <m.de.rooy@rijksmuseum.nl> changed: What |Removed |Added ---------------------------------------------------------------------------- Assignee|koha-bugs@lists.koha-commun |m.de.rooy@rijksmuseum.nl |ity.org | -- You are receiving this mail because: You are watching all bug changes. You are the assignee for the bug.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=38758 Marcel de Rooy <m.de.rooy@rijksmuseum.nl> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |ASSIGNED -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=38758 Marcel de Rooy <m.de.rooy@rijksmuseum.nl> changed: What |Removed |Added ---------------------------------------------------------------------------- Patch complexity|--- |Small patch Status|ASSIGNED |Needs Signoff -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=38758 --- Comment #1 from Marcel de Rooy <m.de.rooy@rijksmuseum.nl> --- Created attachment 175818 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=175818&action=edit Bug 38758: Add strftime as TT virtual method Test plan: Try things like [% borrower.dateexpiry.strftime('%d-%m-%y') %] in a notice. Also test datetime fields like borrower.lastseen. Add locale support with strftime('%d %B', 'nl_NL') etc. Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=38758 --- Comment #2 from Marcel de Rooy <m.de.rooy@rijksmuseum.nl> --- Created attachment 175819 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=175819&action=edit Bug 38758: Add subtest to Letters.t Test plan: Run t/db_dependent/Letters.t Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=38758 Paul Derscheid <paul.derscheid@lmscloud.de> changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #175818|0 |1 is obsolete| | --- Comment #3 from Paul Derscheid <paul.derscheid@lmscloud.de> --- Created attachment 175820 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=175820&action=edit Bug 38758: Add strftime as TT virtual method Test plan: Try things like [% borrower.dateexpiry.strftime('%d-%m-%y') %] in a notice. Also test datetime fields like borrower.lastseen. Add locale support with strftime('%d %B', 'nl_NL') etc. Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> Signed-off-by: Paul Derscheid <paul.derscheid@lmscloud.de> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=38758 Paul Derscheid <paul.derscheid@lmscloud.de> changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #175819|0 |1 is obsolete| | --- Comment #4 from Paul Derscheid <paul.derscheid@lmscloud.de> --- Created attachment 175821 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=175821&action=edit Bug 38758: Add subtest to Letters.t Test plan: Run t/db_dependent/Letters.t Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> Signed-off-by: Paul Derscheid <paul.derscheid@lmscloud.de> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=38758 Paul Derscheid <paul.derscheid@lmscloud.de> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |paul.derscheid@lmscloud.de Status|Needs Signoff |Signed Off -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=38758 Martin Renvoize (ashimema) <martin.renvoize@ptfs-europe.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #175820|0 |1 is obsolete| | --- Comment #5 from Martin Renvoize (ashimema) <martin.renvoize@ptfs-europe.com> --- Created attachment 175822 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=175822&action=edit Bug 38758: Add strftime as TT virtual method Test plan: Try things like [% borrower.dateexpiry.strftime('%d-%m-%y') %] in a notice. Also test datetime fields like borrower.lastseen. Add locale support with strftime('%d %B', 'nl_NL') etc. Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> Signed-off-by: Paul Derscheid <paul.derscheid@lmscloud.de> Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=38758 Martin Renvoize (ashimema) <martin.renvoize@ptfs-europe.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #175821|0 |1 is obsolete| | --- Comment #6 from Martin Renvoize (ashimema) <martin.renvoize@ptfs-europe.com> --- Created attachment 175823 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=175823&action=edit Bug 38758: Add subtest to Letters.t Test plan: Run t/db_dependent/Letters.t Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> Signed-off-by: Paul Derscheid <paul.derscheid@lmscloud.de> Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=38758 Martin Renvoize (ashimema) <martin.renvoize@ptfs-europe.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |martin.renvoize@ptfs-europe | |.com QA Contact|testopia@bugs.koha-communit |martin.renvoize@ptfs-europe |y.org |.com Status|Signed Off |Passed QA -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=38758 --- Comment #7 from Martin Renvoize (ashimema) <martin.renvoize@ptfs-europe.com> --- I'd be tempted to add the option to the filter call too I've confirmed it works as is.. though I'm not entirely sure I understand the innards of TT plugins to know why. It might be nice to be able to call it as so [% borrower.lastseen | $KohaDates with_format = '%d-%m' %] -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=38758 Martin Renvoize (ashimema) <martin.renvoize@ptfs-europe.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Keywords| |release-notes-needed -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=38758 --- Comment #8 from Marcel de Rooy <m.de.rooy@rijksmuseum.nl> --- (In reply to Martin Renvoize (ashimema) from comment #7)
I'd be tempted to add the option to the filter call too
I've confirmed it works as is.. though I'm not entirely sure I understand the innards of TT plugins to know why.
It might be nice to be able to call it as so
[% borrower.lastseen | $KohaDates with_format = '%d-%m' %]
Thanks for QA. I would prefer to change the filter sub of KohaDates on another report though. -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=38758 Katrin Fischer <katrin.fischer@bsz-bw.de> changed: What |Removed |Added ---------------------------------------------------------------------------- Keywords| |additional_work_needed --- Comment #9 from Katrin Fischer <katrin.fischer@bsz-bw.de> --- We have a bit of documentation for formatting dates in the TT notices in the wiki, can you please update? https://wiki.koha-community.org/wiki/Notices_with_Template_Toolkit#Example:_... -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=38758 Katrin Fischer <katrin.fischer@bsz-bw.de> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|Passed QA |Pushed to main Version(s)| |25.05.00 released in| | -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=38758 --- Comment #10 from Katrin Fischer <katrin.fischer@bsz-bw.de> --- Pushed for 25.05! Well done everyone, thank you! -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=38758 Paul Derscheid <paul.derscheid@lmscloud.de> changed: What |Removed |Added ---------------------------------------------------------------------------- Version(s)|25.05.00 |25.05.00,24.11.01 released in| | Status|Pushed to main |Pushed to stable -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=38758 --- Comment #11 from Paul Derscheid <paul.derscheid@lmscloud.de> --- Nice work everyone! Pushed to 24.11.x for 24.11.01 -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=38758 David Nind <david@davidnind.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Text to go in the| |This enhancement adds an release notes| |easier way to format dates | |in notices, and minimise | |potential errors - | |strftime. It can be used | |for both date and date time | |fields, and is locale | |friendly. | | | |Examples: | |- Date | |field: [% | |borrower.dateexpiry.strftim | |e('%d-%m-%y') %] | |- Date and | |time field: [% | |borrower.lastseen.strftime( | |"%d-%m-%y %H:%M") %] | |- | |Locale: [% | |borrower.dateexpiry.strftim | |e("%d %B %Y", "nl_NL") %] CC| |david@davidnind.com --- Comment #12 from David Nind <david@davidnind.com> --- I had a go at a relase note - I'm not sure if I've got this right, particularly showing the date time field example. -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=38758 Jonathan Druart <jonathan.druart@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |jonathan.druart@gmail.com --- Comment #13 from Jonathan Druart <jonathan.druart@gmail.com> --- That's elegant but definitely not consistent with anything else. IMO it should have been a method of KohaDates (matching the existing pattern: KohaDates.output_preference) -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=38758 Wainui Witika-Park <wainuiwitikapark@catalyst.net.nz> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |wainuiwitikapark@catalyst.n | |et.nz --- Comment #14 from Wainui Witika-Park <wainuiwitikapark@catalyst.net.nz> --- Not backporting to 24.05 unless requested -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=38758 --- Comment #15 from Marcel de Rooy <m.de.rooy@rijksmuseum.nl> --- (In reply to Katrin Fischer from comment #9)
We have a bit of documentation for formatting dates in the TT notices in the wiki, can you please update?
https://wiki.koha-community.org/wiki/Notices_with_Template_Toolkit#Example: _Format_dates
Added a few lines. -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=38758 Katrin Fischer <katrin.fischer@bsz-bw.de> changed: What |Removed |Added ---------------------------------------------------------------------------- Keywords|additional_work_needed, | |release-notes-needed | -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=38758 Elizabeth Hoffman <ehoffman@plumcreeklibrary.net> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |ehoffman@plumcreeklibrary.n | |et -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=38758 Wainui Witika-Park <wainuiwitikapark@catalyst.net.nz> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|Pushed to stable |Needs documenting --- Comment #16 from Wainui Witika-Park <wainuiwitikapark@catalyst.net.nz> --- Not backporting to 22.11.x as it wasn't backported to 24.05.x (or 23.XX) -- You are receiving this mail because: You are watching all bug changes.
participants (1)
-
bugzilla-daemon@bugs.koha-community.org