Bug 21824 - Add ability to format dates in various formats in templates
Summary: Add ability to format dates in various formats in templates
Status: Signed Off
Alias: None
Product: Koha
Classification: Unclassified
Component: Templates (show other bugs)
Version: master
Hardware: All All
: P5 - low enhancement (vote)
Target Milestone: ---
Assignee: Kyle M Hall
QA Contact: Testopia
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-11-13 15:59 UTC by Nick Clemens
Modified: 2019-02-21 11:42 UTC (History)
4 users (show)

See Also:
Change sponsored?: ---
Patch complexity: Small patch
Bot Control: ---
When did the bot last check this:
Who signed the patch off:
Text to go in the release notes:


Attachments
Bug 21824: Add ability to format dates in various formats in templates (2.21 KB, patch)
2018-11-13 16:10 UTC, Kyle M Hall
Details | Diff | Splinter Review
Bug 21824: Add KohaDates method 'output_preference' to make it easy to store formatted dates in TT variable (1.83 KB, patch)
2018-11-13 17:36 UTC, Kyle M Hall
Details | Diff | Splinter Review
Bug 21824: Add ability to format dates in various formats in templates (2.24 KB, patch)
2018-12-05 16:54 UTC, Owen Leonard
Details | Diff | Splinter Review
Bug 21824: Add KohaDates method 'output_preference' to make it easy to store formatted dates in TT variable (1.85 KB, patch)
2018-12-05 16:54 UTC, Owen Leonard
Details | Diff | Splinter Review
Bug 21824: Add tests (2.68 KB, patch)
2018-12-13 21:24 UTC, Jonathan Druart
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Nick Clemens 2018-11-13 15:59:42 UTC
Since enabling template toolkit for notices we have found we are trying to do date comparisons and more advanced manipulations. We have been using 'manip' but this is complicated.

We should build in some utils to allow for more advanced formatting and comparison
Comment 1 Kyle M Hall 2018-11-13 16:10:44 UTC
Created attachment 82308 [details] [review]
Bug 21824: Add ability to format dates in various formats in templates

This patch adds the ability to set a date format for the Template Toolkit filter KohaDates

Test plan:
1) Apply this patch
2) In a template, use the filter param "dateformat => 'iso'"
3) Note the output is in ISO format
Comment 2 Kyle M Hall 2018-11-13 17:36:30 UTC
Created attachment 82316 [details] [review]
Bug 21824: Add KohaDates method 'output_preference' to make it easy to store formatted dates in TT variable
Comment 3 Owen Leonard 2018-12-05 16:54:48 UTC
Created attachment 82879 [details] [review]
Bug 21824: Add ability to format dates in various formats in templates

This patch adds the ability to set a date format for the Template Toolkit filter KohaDates

Test plan:
1) Apply this patch
2) In a template, use the filter param "dateformat => 'iso'"
3) Note the output is in ISO format

Signed-off-by: Owen Leonard <oleonard@myacpl.org>
Comment 4 Owen Leonard 2018-12-05 16:54:51 UTC
Created attachment 82880 [details] [review]
Bug 21824: Add KohaDates method 'output_preference' to make it easy to store formatted dates in TT variable

Signed-off-by: Owen Leonard <oleonard@myacpl.org>
Comment 5 Jonathan Druart 2018-12-13 19:06:12 UTC
Hi Nick, Kyle,
Can you give more info about the use cases? Which problems are you trying to solve with these patches?
Comment 6 Nick Clemens 2018-12-13 20:05:26 UTC
(In reply to Jonathan Druart from comment #5)
> Hi Nick, Kyle,
> Can you give more info about the use cases? Which problems are you trying to
> solve with these patches?

When libraries want to format the date in various ways in slip/notices it is currently difficult, the goal is to make it easy to use Koha tools for date formatting
Comment 7 Jonathan Druart 2018-12-13 21:12:20 UTC
Kyle, Can you give an example please? How would you display table.column in iso format without the time part?
Comment 8 Jonathan Druart 2018-12-13 21:14:35 UTC
(In reply to Jonathan Druart from comment #7)
> Kyle, Can you give an example please? How would you display table.column in
> iso format without the time part?

[% table.column | $KohaDates dateformat => 'iso' %]
Comment 9 Jonathan Druart 2018-12-13 21:21:13 UTC
(In reply to Jonathan Druart from comment #8)
> (In reply to Jonathan Druart from comment #7)
> > Kyle, Can you give an example please? How would you display table.column in
> > iso format without the time part?
> 
> [% table.column | $KohaDates dateformat => 'iso' %]

or [% KohaDate.output_preference( str => table.column, dateformat => 'iso', dateonly => 1 %]

Is that what you had in mind?
Comment 10 Jonathan Druart 2018-12-13 21:24:56 UTC
Created attachment 83188 [details] [review]
Bug 21824: Add tests
Comment 11 Jonathan Druart 2018-12-13 21:32:00 UTC
I am not convinced we really need this additional parameter (and even less the new subroutine).

The following is much more readable IMO:
  [% USE date %]
  [% date.format(biblio.timestamp, '%F') %]
  [% date.format(biblio.timestamp, '%Y-%m-%d') %]


The only advantage would be to take into account the timezone if defined in the config.
Comment 12 Katrin Fischer 2019-02-17 10:15:16 UTC
(In reply to Jonathan Druart from comment #11)
> I am not convinced we really need this additional parameter (and even less
> the new subroutine).
> 
> The following is much more readable IMO:
>   [% USE date %]
>   [% date.format(biblio.timestamp, '%F') %]
>   [% date.format(biblio.timestamp, '%Y-%m-%d') %]
> 
> 
> The only advantage would be to take into account the timezone if defined in
> the config.

Just some thoughts here:

So without the patch the above constructs only display the server time, but not the configured time? If that's correct a syntax taking the timezone into account might prove really helpful over time.

The advantage I see with using standard template toolkit operations is better documentation and flexibility. At the moment the TT notices remain rather unhelpful to libraries, because we lack documentation and examples (Josef++ for his work on documentation this week)

What other formats would the new parameter support? In what kind of situations would it be useful? I miss a 'real life example' in the test plan to make things more clear.
Comment 13 Josef Moravec 2019-02-18 08:53:05 UTC
What is the use real use case? When librarians want to show date in various formats? I prefer to show date and time in human readable format for patrons...

Just my 2 cents
Comment 14 Kyle M Hall 2019-02-21 11:42:52 UTC
(In reply to Josef Moravec from comment #13)
> What is the use real use case? When librarians want to show date in various
> formats? I prefer to show date and time in human readable format for
> patrons...
> 
> Just my 2 cents

Sometimes librarians want or need specific formats. It's as simple as that :)