[Bug 30059] New: Add a JS equivalent to Koha::Patron->get_age
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=30059 Bug ID: 30059 Summary: Add a JS equivalent to Koha::Patron->get_age Change sponsored?: --- Product: Koha Version: unspecified Hardware: All OS: All Status: ASSIGNED Severity: enhancement Priority: P5 - low Component: Architecture, internals, and plumbing Assignee: jonathan.druart+koha@gmail.com Reporter: jonathan.druart+koha@gmail.com QA Contact: testopia@bugs.koha-community.org Blocks: 30055 To display the age of patrons in a table we will need to do the calculation in JS Referenced Bugs: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=30055 [Bug 30055] Rewrite patron searches to make them use the REST API routes -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=30059 Jonathan Druart <jonathan.druart+koha@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- 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=30059 --- Comment #1 from Jonathan Druart <jonathan.druart+koha@gmail.com> --- Created attachment 130358 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=130358&action=edit Bug 30059: Add JS equivalent for Koha::Patron->get_age On bug 30055 we are going to use the REST API to display the patron search result, we will then need to calculate patron's age client-side. This is moved to its own bug report in case we need to reuse it somewhere else. Test plan: Copy/paste the JS function in your browser's console then call it and confirm that the result is correct For instance: $get_age('2000-01-01') -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=30059 Tomás Cohen Arazi <tomascohen@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |martin.renvoize@ptfs-europe | |.com, | |nick@bywatersolutions.com, | |tomascohen@gmail.com -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=30059 Owen Leonard <oleonard@myacpl.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|Needs Signoff |Signed Off Patch complexity|--- |Small patch -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=30059 Owen Leonard <oleonard@myacpl.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #130358|0 |1 is obsolete| | --- Comment #2 from Owen Leonard <oleonard@myacpl.org> --- Created attachment 130665 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=130665&action=edit Bug 30059: Add JS equivalent for Koha::Patron->get_age On bug 30055 we are going to use the REST API to display the patron search result, we will then need to calculate patron's age client-side. This is moved to its own bug report in case we need to reuse it somewhere else. Test plan: Copy/paste the JS function in your browser's console then call it and confirm that the result is correct For instance: $get_age('2000-01-01') -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=30059 Nick Clemens <nick@bywatersolutions.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|Signed Off |Failed QA --- Comment #3 from Nick Clemens <nick@bywatersolutions.com> --- get_age('1979-02-17') = 43 get_age('1979-02-18') = 43 get_age('1979-02-19') = 43 XXX Today is 2022-02-18 - Not birthday yet! Stop calling me old!!! get_age('1979-02-20') = 42 -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=30059 --- Comment #4 from Martin Renvoize <martin.renvoize@ptfs-europe.com> --- Might be an unpopular view.. but don't we already pull in moment.js for other date manipulations.. so couldn't we use https://momentjs.com/docs/#/displaying/difference/ to get a rather accurate result? -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=30059 --- Comment #5 from Jonathan Druart <jonathan.druart+koha@gmail.com> --- (In reply to Nick Clemens from comment #3)
get_age('1979-02-17') = 43 get_age('1979-02-18') = 43 get_age('1979-02-19') = 43 XXX Today is 2022-02-18 - Not birthday yet! Stop calling me old!!! get_age('1979-02-20') = 42
Are you sure? Today is 2022-02-21: $get_age("1979-02-19") = 43 $get_age("1979-02-20") = 43 $get_age("1979-02-21") = 43 # today $get_age("1979-02-22") = 42 So I modified the function with "var today = new Date("2022-02-18");" $get_age('1979-02-17') = 43 $get_age('1979-02-18') = 43 # "today" $get_age('1979-02-19') = 42 $get_age('1979-02-20') = 42 -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=30059 --- Comment #6 from Nick Clemens <nick@bywatersolutions.com> --- (In reply to Jonathan Druart from comment #5)
Are you sure?
Yes, tested again this morning, same results, I believe time portion causes problems: let dob = new Date('2022-02-23'); dob: Date Thu Feb 22 1979 19:00:00 GMT-0500 (Eastern Standard Time) -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=30059 --- Comment #7 from Tomás Cohen Arazi <tomascohen@gmail.com> --- (In reply to Martin Renvoize from comment #4)
Might be an unpopular view.. but don't we already pull in moment.js for other date manipulations.. so couldn't we use https://momentjs.com/docs/#/displaying/difference/ to get a rather accurate result?
I'd agree with this. I also wonder... if the browser date should be used, or the server's... I guess it is not that important. But if we think the UI could make a decision, based on the age, and place a request, this could be rejected because the server could have its own age check, leading to inconsistent behavior. In that case, I'd just allow embedding the age like in: GET /patrons x-koha-emebed: age (it would require renaming the ->get_age method) -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=30059 --- Comment #8 from Jonathan Druart <jonathan.druart+koha@gmail.com> --- The problem is the timezone, not the calculation. I don't think we need a lib for that. (In reply to Martin Renvoize from comment #4)
Might be an unpopular view.. but don't we already pull in moment.js for other date manipulations.. so couldn't we use https://momentjs.com/docs/#/displaying/difference/ to get a rather accurate result?
I didn't manage to make it work, I get "tz is not a function". I've tried with moment-timezone as well, and both with the latest version. Also worth noting: "Moment.js is a legacy project, now in maintenance mode. In most cases, you should choose a different library.", from https://github.com/moment/moment (In reply to Tomás Cohen Arazi from comment #7)
In that case, I'd just allow embedding the age like in:
GET /patrons x-koha-emebed: age
(it would require renaming the ->get_age method)
I had that concern some months ago (we will have twice the same business logic), but we agreed on providing a "JS equivalent" (bug 28874). Here it's over-complicating things anyway, we just want to subtract two dates. We can also rely on the client to make extra processing, which is good for server perfs. -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=30059 Jonathan Druart <jonathan.druart+koha@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|Failed QA |Needs Signoff -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=30059 --- Comment #9 from Jonathan Druart <jonathan.druart+koha@gmail.com> --- Created attachment 131309 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=131309&action=edit Bug 30059: Deal with timezones -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=30059 --- Comment #10 from Jonathan Druart <jonathan.druart+koha@gmail.com> --- This patches fixes the problem. Test plan: open the console and define a timezone: let tz = "UTC" or "America/Buenos_Aires" then call the function. -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=30059 Tomás Cohen Arazi <tomascohen@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- 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=30059 Tomás Cohen Arazi <tomascohen@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #130665|0 |1 is obsolete| | -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=30059 Tomás Cohen Arazi <tomascohen@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #131309|0 |1 is obsolete| | -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=30059 --- Comment #11 from Tomás Cohen Arazi <tomascohen@gmail.com> --- Created attachment 131672 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=131672&action=edit Bug 30059: Add JS equivalent for Koha::Patron->get_age On bug 30055 we are going to use the REST API to display the patron search result, we will then need to calculate patron's age client-side. This is moved to its own bug report in case we need to reuse it somewhere else. Test plan: Copy/paste the JS function in your browser's console then call it and confirm that the result is correct For instance: $get_age('2000-01-01') Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=30059 --- Comment #12 from Tomás Cohen Arazi <tomascohen@gmail.com> --- Created attachment 131673 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=131673&action=edit Bug 30059: Deal with timezones Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=30059 Fridolin Somers <fridolin.somers@biblibre.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |fridolin.somers@biblibre.co | |m --- Comment #13 from Fridolin Somers <fridolin.somers@biblibre.com> --- Does Bug 30061 have any impact here ? -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=30059 --- Comment #14 from Tomás Cohen Arazi <tomascohen@gmail.com> --- (In reply to Fridolin Somers from comment #13)
Does Bug 30061 have any impact here ?
Unrelated. -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=30059 Nick Clemens <nick@bywatersolutions.com> changed: What |Removed |Added ---------------------------------------------------------------------------- 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=30059 Nick Clemens <nick@bywatersolutions.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #131672|0 |1 is obsolete| | Attachment #131673|0 |1 is obsolete| | --- Comment #15 from Nick Clemens <nick@bywatersolutions.com> --- Created attachment 132178 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=132178&action=edit Bug 30059: Add JS equivalent for Koha::Patron->get_age On bug 30055 we are going to use the REST API to display the patron search result, we will then need to calculate patron's age client-side. This is moved to its own bug report in case we need to reuse it somewhere else. Test plan: Copy/paste the JS function in your browser's console then call it and confirm that the result is correct For instance: $get_age('2000-01-01') Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> Signed-off-by: Nick Clemens <nick@bywatersolutions.com> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=30059 --- Comment #16 from Nick Clemens <nick@bywatersolutions.com> --- Created attachment 132179 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=132179&action=edit Bug 30059: Deal with timezones Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> Signed-off-by: Nick Clemens <nick@bywatersolutions.com> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=30059 Fridolin Somers <fridolin.somers@biblibre.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Version(s)| |22.05.00 released in| | Status|Passed QA |Pushed to master -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=30059 --- Comment #17 from Fridolin Somers <fridolin.somers@biblibre.com> --- Pushed to master for 22.05, thanks to everybody involved 🦄 -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=30059 Kyle M Hall <kyle@bywatersolutions.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Resolution|--- |FIXED CC| |kyle@bywatersolutions.com Status|Pushed to master |RESOLVED -- You are receiving this mail because: You are watching all bug changes.
participants (1)
-
bugzilla-daemon@bugs.koha-community.org