-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
It seems that loopback-datasource-juggler is converting any type: Date (if defined as so in the model) to UTC before saving to the database.
By doing some digging, this is where it happens.
What makes things more confusing is that whenever the same data is fetched, it does not undergo this conversion backwards. i.e. it is displayed exactly as it is saved in the database.
Steps to reproduce
-
Create a model with a property of the type Date:
@property({type: Date,...})) -
In a machine with a timezone other than UTC (for example UTC+7), create a record with the date value: '2019-07-25T08:00'
Current Behavior
The data will be saved to the database as '2019-07-25T01:00', not taking into consideration any timezone set anywhere.
Expected Behavior
I propose that adding a timezone property in the datasource be honoured instead of defaulting to UTC. So the behaviour of converting to UTC should remain, but after that conversion a check should be made whether a different timezone is defined in the datasource and convert to it if exists: {"timezone": "UTC+07:00"}
Example:
{ "host": "127.0.0.1", "port": 3306, "database": "mydb", "username": "root", "password": "root", "name": "mydb", "connector": "mysql", "timezone": "UTC+07:00" }
My only current workaround is to change type: Date to type: String in the model property definition.
Link to reproduction sandbox
Additional information
I am reporting this as a bug since the framework's behavior is as described even if the app server (on the os level) and the database server (for example mysql, my.cnf: default-time-zone='+07:00') have a timezone set to other than UTC.
And also because this behavior is enforced even if the value of the date is defined as string. The dao overrides any possible value and performs this conversion.
Related Issues
See Reporting Issues for more tips on writing good issues