Bug 37903 - Timezone ignored when passing rfc3339 formatted date (POST,PUT,PATCH)
Summary: Timezone ignored when passing rfc3339 formatted date (POST,PUT,PATCH)
Status: NEW
Alias: None
Product: Koha
Classification: Unclassified
Component: REST API (show other bugs)
Version: unspecified
Hardware: All All
: P5 - low enhancement
Assignee: Bugs List
QA Contact: Testopia
URL:
Keywords:
Depends on: 37831 37902
Blocks:
  Show dependency treegraph
 
Reported: 2024-09-12 12:23 UTC by Jonathan Druart
Modified: 2024-09-17 08:31 UTC (History)
2 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

Note You need to log in before you can comment on or make changes to this bug.
Description Jonathan Druart 2024-09-12 12:23:12 UTC Comment hidden (obsolete)
Comment 1 Jonathan Druart 2024-09-12 13:24:02 UTC
When requesting the REST API we are getting datetimes in the RFC3339 format, for instance: 2024-09-04T06:03:34-03:00

This is retrieving the value that is stored DB, and using the timezone defined in the $KOHA_CONF file.

However this format is not correctly into account when we search or, more importantly, when we create/update objects.

Examples (Using the Buenos Aires timezome, which is UTC-3 "America/Argentina/Buenos_Aires"):

1. POST /api/v1/checkouts with 
  "due_date": "2024-09-09T23:59:00-00:00",
And you will get
  "due_date": "2024-09-09T23:59:00-03:00",

in DB: date_due: 2024-09-09 23:59:00
Comment 2 Jonathan Druart 2024-09-12 13:24:14 UTC
This should actually work in most places. It does not work however for checkouts because we are using AddIssue instead of the usual Koha::Object->new_from_api
Comment 3 Jonathan Druart 2024-09-12 13:39:01 UTC
(In reply to Jonathan Druart from comment #2)
> This should actually work in most places. It does not work however for
> checkouts because we are using AddIssue instead of the usual
> Koha::Object->new_from_api

It does not work, even on top of bug 37902:

If I POST /api/v1/patrons

        "last_seen": "2024-09-12T03:29:05-04:00",
response is

    "last_seen": "2024-09-12T03:29:05-03:00",

and in DB: lastseen: 2024-09-12 03:29:05
Comment 4 Jonathan Druart 2024-09-16 09:01:59 UTC
Possible places affected:

Koha/REST/V1/Authorities.pm
  * add (AddAuthority)
  * update (ModAuthority)

Koha/REST/V1/Biblios/ItemGroups/Items.pm
  * add (why? No good reason it seems)

Koha/REST/V1/Checkouts.pm
  * add (AddIssue)

Koha/REST/V1/Clubs/Holds.pm
  * add

Koha/REST/V1/Holds.pm
  * add (AddReserve)
  * edit (ModReserve)
  * suspend (certainly needs to be fixed)

Koha/REST/V1/ILL/**
  Not reviewed
Comment 5 Jonathan Druart 2024-09-16 09:02:56 UTC
Using Koha::Object-based objects must be required for the REST API controllers.
Comment 6 Tomás Cohen Arazi (tcohen) 2024-09-16 14:56:14 UTC
Hi, I'm a bit confused here. I understand where this is coming from, but POST /checkouts doesn't have any datetime parameter that would get passed to AddIssue. So maybe this is a worse bug (e.g. in AddIssue).
Comment 7 Jonathan Druart 2024-09-17 08:28:20 UTC
(In reply to Jonathan Druart from comment #3)
> (In reply to Jonathan Druart from comment #2)
> > This should actually work in most places. It does not work however for
> > checkouts because we are using AddIssue instead of the usual
> > Koha::Object->new_from_api
> 
> It does not work, even on top of bug 37902:
> 
> If I POST /api/v1/patrons
> 
>         "last_seen": "2024-09-12T03:29:05-04:00",
> response is
> 
>     "last_seen": "2024-09-12T03:29:05-03:00",
> 
> and in DB: lastseen: 2024-09-12 03:29:05

To clarify, this is fixed by bug 37902:

in $KOHA_CONF
403  <timezone>America/Argentina/Buenos_Aires</timezone>

Without 37902:
POST        "last_seen": "2024-09-12T03:29:05-01:00",
response    "last_seen": "2024-09-12T03:29:05-03:00",
DB has "2024-09-12 03:29:05"

With 37902:
POST        "last_seen": "2024-09-12T03:29:05-01:00",
response    "last_seen": "2024-09-12T01:29:05-03:00",
DB has "2024-09-12 01:29:05"
Comment 8 Jonathan Druart 2024-09-17 08:31:34 UTC
(In reply to Tomás Cohen Arazi from comment #6)
> Hi, I'm a bit confused here. I understand where this is coming from, but
> POST /checkouts doesn't have any datetime parameter that would get passed to
> AddIssue. So maybe this is a worse bug (e.g. in AddIssue).

Indeed! My test was wrong, I was assuming my parameter was taken into account but it's not!

Tried today with
POST    "due_date": "2024-09-09T23:59:00-00:00",
and the response is 
       "due_date": "2024-09-22T23:59:00-03:00",
(ie. it's ignored!)

So it's a bug in the spec I guess, not related to DT handling.