Bug 37831 - [OMNIBUS] Timezone ignored when passing rfc3339 formatted date
Summary: [OMNIBUS] Timezone ignored when passing rfc3339 formatted date
Status: NEW
Alias: None
Product: Koha
Classification: Unclassified
Component: REST API (show other bugs)
Version: unspecified
Hardware: All All
: P5 - low major
Assignee: Bugs List
QA Contact: Testopia
URL:
Keywords:
Depends on:
Blocks: 25621 37902 37903 37904
  Show dependency treegraph
 
Reported: 2024-09-04 13:41 UTC by Jonathan Druart
Modified: 2024-09-12 14:24 UTC (History)
4 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 37831: Adjust timezone (1.37 KB, patch)
2024-09-12 14: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 Jonathan Druart 2024-09-04 13:41:48 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/patrons 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

2. GET /api/v1/jobs?q={"enqueued_on":{">":"2024-09-04T09:26:52-03:00"}}
is generating the following query

SELECT `me`.`id`, `me`.`status`, `me`.`progress`, `me`.`size`, `me`.`borrowernumber`, `me`.`type`, `me`.`queue`, `me`.`data`, `me`.`context`, `me`.`enqueued_on`, `me`.`started_on`, `me`.`ended_on` 
  FROM `background_jobs` `me` 
WHERE `enqueued_on` > '2024-09-04T09:26:52-03:00' 

But when you run it manually, you get a warning:
  | Warning | 1292 | Truncated incorrect datetime value: '2024-09-04T09:26:52-03:00' |
Comment 1 David Cook 2024-09-05 00:35:23 UTC
Yeah, bug 36217 is just one example where we send UTC but the server interprets it as whatever local time zone the DB is set to.
Comment 2 Jonathan Druart 2024-09-11 12:33:23 UTC
For 2. We are not hitting the code that is supposed to deal with rfc3339 (in Koha::Object->attributes_from_api) because the date is in 'q'.

Koha/REST/Plugin/Objects.pm
160             my ( $filtered_params, $reserved_params ) = $c->extract_reserved_params($args);

212             # Call the to_model function by reference, if defined
213             if ( defined $filtered_params ) {
214 
215                 # Apply the mapping function to the passed params
216                 $filtered_params =
217                   $result_set->attributes_from_api($filtered_params);
218                 $filtered_params =
219                   $c->build_query_params( $filtered_params, $reserved_params );
220             }


q is in $reserved_params;
{
    q   [
        [0] "{\"enqueued_on\":{\">\":\"2024-09-04T09:26:52-03:00\"}}"
    ]
}
Comment 3 Jonathan Druart 2024-09-12 12:22:04 UTC
(In reply to Jonathan Druart from comment #0)
> 2. GET /api/v1/jobs?q={"enqueued_on":{">":"2024-09-04T09:26:52-03:00"}}
> is generating the following query
> 
> SELECT `me`.`id`, `me`.`status`, `me`.`progress`, `me`.`size`,
> `me`.`borrowernumber`, `me`.`type`, `me`.`queue`, `me`.`data`,
> `me`.`context`, `me`.`enqueued_on`, `me`.`started_on`, `me`.`ended_on` 
>   FROM `background_jobs` `me` 
> WHERE `enqueued_on` > '2024-09-04T09:26:52-03:00' 
> 
> But when you run it manually, you get a warning:
>   | Warning | 1292 | Truncated incorrect datetime value:
> '2024-09-04T09:26:52-03:00' |

Moved to bug 37902.
Comment 4 Jonathan Druart 2024-09-12 12:23:24 UTC
(In reply to Jonathan Druart from comment #0)
> 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/patrons 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

Moved to bug 37903.
Comment 5 Jonathan Druart 2024-09-12 12:26:12 UTC
Not caused by bug 36432.
Comment 6 Jonathan Druart 2024-09-12 14:24:22 UTC
Created attachment 171401 [details] [review]
Bug 37831: Adjust timezone

We didn't take into account the server's timezone.

This does not feel right, we are not supposed to deal with time zone
outside of Koha::DateUtils.