You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, I have an issue with saving timestamp fields to the database using the @cap-js/postgres adapter.
The entered timestamp data is equipped with a time zone that is lost when the data gets saved to the database.
Example
I have a very simple entity with some test fields:
namespacemilo.db.test;
using { managed, cuid } from'@sap/cds/common';
@odata.draft.enabledentityTest01:managed, cuid {
dati:DateTime;
tist:Timestamp;
da:Date;
ti:Time;
}
Now I am using Chrome in Windows 11 with Time Zone CEST.
When I enter the value 23.10.2024, 12:00:00 in my fiori elements app and save, it will change to 23.10.2024, 14:00:00. So my input is interpreted as UTC while I meant it to be in my local time.
The outgoing batch request issued by my browser contains the CEST time:
[sql] [DEBUG] UPDATE milo_srv_TestService_Test01_drafts AS drafts SET dati=$1,ID=$2,modifiedAt=coalesce(CAST(NULL as TIMESTAMP), current_setting('cap.now')::timestamp),modifiedBy=coalesce(NULL, current_setting('cap.applicationuser')) WHERE drafts.ID = $3 2024-10-23T12:00:00+02:00 bbeecf3a-85b8-47b5-9185-97676a79e3eb bbeecf3a-85b8-47b5-9185-97676a79e3eb
So you see the CEST time (dati = 2024-10-23T12:00:00+02:00) is forwarded to the database. CAP itself does not convert the timestamp to UTC, contrary to what the documentation claims here.
I tried setting the time zone to Europe/Berlin or Etc using the TZ environment variable, but it did not change anything.
Also, due to draft handling, I cannot seem to intervene using some CAP middlewares. When my before handler executes, it only gets the data from the drafts table, which might be correct, or not.
Both fields Timestamp and DateTime show this behavior.
Version information
milo
(non-published)
@cap-js/cds-typer
0.27.0
@cap-js/cds-types
0.6.5
@cap-js/db-service
1.14.0
@cap-js/postgres
1.10.1
@cap-js/sqlite
1.7.4
@sap/cds
8.3.1
@sap/cds-compiler
5.3.2
@sap/cds-fiori
1.2.7
@sap/cds-foss
5.0.1
Node.js
v20.18.0
home
/workspaces/milo/node_modules/@sap/cds
I found some SAP question that looks exactly like my issue, but does not contain a real solution. Sending the data as UTC via OData would probably help but unfortunately that is not what Fiori Elements does, and debugging Fiori Elements is quite hard.
Thanks a lot in advance!
Lennart
The text was updated successfully, but these errors were encountered:
lennart-m
changed the title
Timezone gets ignored when writing to the database
[postgres] Timezone gets ignored when writing to the database
Oct 26, 2024
Hi @hakimio
According to the logs it's the new one.
[cds] - using new OData adapter
I tested it with the legacy adapter and it seems to work. Are there any downsides to be expected with the legacy adapter? I'm currently not using any special OData features like aggregate so feature-wise it shouldn't make a lot of difference.
Also, should I raise this issue somewhere else, if the problem is not with the DB service itself? Will I have to create a SAP incident?
I don't know what I tested before, but it still does not work, even with the legacy adapter. The input always gets interpreted as UTC, resulting in the app displaying different data after saving.
Hi, I have an issue with saving timestamp fields to the database using the
@cap-js/postgres
adapter.The entered timestamp data is equipped with a time zone that is lost when the data gets saved to the database.
Example
I have a very simple entity with some test fields:
And a simple test service:
Now I am using Chrome in Windows 11 with Time Zone CEST.
When I enter the value
23.10.2024, 12:00:00
in my fiori elements app and save, it will change to23.10.2024, 14:00:00
. So my input is interpreted as UTC while I meant it to be in my local time.The outgoing batch request issued by my browser contains the CEST time:
CAP logs this request as follows:
So you see the CEST time (
dati = 2024-10-23T12:00:00+02:00
) is forwarded to the database. CAP itself does not convert the timestamp to UTC, contrary to what the documentation claims here.I tried setting the time zone to
Europe/Berlin
orEtc
using theTZ
environment variable, but it did not change anything.Also, due to draft handling, I cannot seem to intervene using some CAP middlewares. When my
before
handler executes, it only gets the data from the drafts table, which might be correct, or not.Both fields
Timestamp
andDateTime
show this behavior.Version information
I found some SAP question that looks exactly like my issue, but does not contain a real solution. Sending the data as UTC via OData would probably help but unfortunately that is not what Fiori Elements does, and debugging Fiori Elements is quite hard.
Thanks a lot in advance!
Lennart
The text was updated successfully, but these errors were encountered: