Bug 33132 - Searching by DOB still broken in 22.05.x
Summary: Searching by DOB still broken in 22.05.x
Status: CLOSED FIXED
Alias: None
Product: Koha
Classification: Unclassified
Component: Patrons (show other bugs)
Version: 22.05
Hardware: All All
: P5 - low normal
Assignee: Jonathan Druart
QA Contact: Marcel de Rooy
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-03-03 20:22 UTC by Lucas Gass (lukeg)
Modified: 2024-07-04 20:38 UTC (History)
7 users (show)

See Also:
Change sponsored?: ---
Patch complexity: ---
Documentation contact:
Documentation submission:
Text to go in the release notes:
Version(s) released in:
Circulation function:


Attachments
Bug 33132: Fix DOB search for 22.05 (1.45 KB, patch)
2023-03-03 20:29 UTC, Lucas Gass (lukeg)
Details | Diff | Splinter Review
Bug 33132: [ALTERNATE] [22.05.x] Add date_to_rfc3339 (1.13 KB, patch)
2023-06-02 07:10 UTC, Jonathan Druart
Details | Diff | Splinter Review
Bug 33132: [22.05.x] Add date_to_rfc3339 (1.19 KB, patch)
2023-06-06 16:23 UTC, Lucas Gass (lukeg)
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Lucas Gass (lukeg) 2023-03-03 20:22:33 UTC
In 22.05.x the fix for Bug 32505 is not working. I think it is because it relies on day.js, which is not in 22.05. We still need a fix for oldstable.
Comment 1 Lucas Gass (lukeg) 2023-03-03 20:29:25 UTC
Created attachment 147738 [details] [review]
Bug 33132: Fix DOB search for 22.05

To test:
1. Apply patch
2. Search for patrons given their date of birth. You need to select "date
of birth" in the "Search field" dropdown, or set it in
DefaultPatronSearchFields.
3. Try with all the different dateformat's to make sure it works with each.
Comment 2 Andrew Fuerste-Henry 2023-03-03 21:17:49 UTC
With the patch applied, I still only find patrons when searching YYYY-MM-DD.
Comment 3 Jonathan Druart 2023-06-02 07:10:43 UTC
Created attachment 151969 [details] [review]
Bug 33132: [ALTERNATE] [22.05.x] Add date_to_rfc3339
Comment 4 Jonathan Druart 2023-06-02 07:11:08 UTC
Andrew, could you try this patch?
Comment 5 Lucas Gass (lukeg) 2023-06-06 16:23:10 UTC
Created attachment 152052 [details] [review]
Bug 33132: [22.05.x] Add date_to_rfc3339

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
Comment 6 Marcel de Rooy 2023-07-07 08:00:46 UTC
Applies to 22.05.x. Not tested.

koha-tmpl/intranet-tmpl/prog/en/includes/js-date-format.inc:        window.$date_to_rfc3339 = function(value, options) {
koha-tmpl/intranet-tmpl/prog/en/includes/patron-search.inc:                                    let d = $date_to_rfc3339(pattern);

        window.$date_to_rfc3339 = function(value, options) {
            var dateformat = (options&&options.dateformat)||def_date_format;
            let m = moment(value, get_date_pattern(dateformat));
            return m.format("YYYY-MM-DD");
        }

Just some observations, not blocking:
Why do you have options if you do not use them?
Why do you call get_date_pattern if you format YMD later on?
Looks good to me for the rest.
Comment 7 Jonathan Druart 2023-07-07 08:10:14 UTC
(In reply to Marcel de Rooy from comment #6)
> Applies to 22.05.x. Not tested.
> 
> koha-tmpl/intranet-tmpl/prog/en/includes/js-date-format.inc:       
> window.$date_to_rfc3339 = function(value, options) {
> koha-tmpl/intranet-tmpl/prog/en/includes/patron-search.inc:                 
> let d = $date_to_rfc3339(pattern);
> 
>         window.$date_to_rfc3339 = function(value, options) {
>             var dateformat = (options&&options.dateformat)||def_date_format;
>             let m = moment(value, get_date_pattern(dateformat));
>             return m.format("YYYY-MM-DD");
>         }
> 
> Just some observations, not blocking:
> Why do you have options if you do not use them?

This function has a bad and wrong history. This version is the one in master. options is there because it was there before, and it is consistent with the other function in the same file.

> Why do you call get_date_pattern if you format YMD later on?
> Looks good to me for the rest.

You need to tell moment in which format is the string you are passing it.

What we are doing is:
let m = moment("20/06/2023", "DD/MM/YYYY"); // DD/MM/YYYY (indirectly) coming from dateformat
m is a moment object
you want to dispay the rfc3339/ymd version, and you ask moment to format it like that:
m.format("YYYY-MM-DD")

Does that make sense now?
Comment 8 Marcel de Rooy 2023-07-07 08:17:54 UTC
(In reply to Jonathan Druart from comment #7)
> You need to tell moment in which format is the string you are passing it.
> 
> What we are doing is:
> let m = moment("20/06/2023", "DD/MM/YYYY"); // DD/MM/YYYY (indirectly)
> coming from dateformat
> m is a moment object
> you want to dispay the rfc3339/ymd version, and you ask moment to format it
> like that:
> m.format("YYYY-MM-DD")
> 
> Does that make sense now?

Look at this code in the same file:

        window.$date = function(value, options) {
            if(!value) return '';
            var tz = (options&&options.tz)||def_tz;
            var m = moment(value);
Comment 9 Jonathan Druart 2023-07-07 08:49:47 UTC
Really, here we are just copying the code from master. All this needs to be rewritten, I agree with that.
Comment 10 Jonathan Druart 2023-09-21 15:15:47 UTC
Why is this still here?
Comment 11 Lucas Gass (lukeg) 2023-09-22 18:10:49 UTC
Backported to 22.05.x for upcomoing 22.05.16.