mysql
mysql copied to clipboard
Setting incorrect value for `timestamp` causes date to be set as UTC and to return as a string
I had accidentally set { "timestamp": "America/Denver" } and I would get back MySQL strings instead of JavaScript Dates.
I would have expected
- an exception - bad values should throw errors
- or the default to be used - bad values could also be ignored, and the default used
What I got was
- inserted values would be transposed - as if the UTC hours value was used, but set as if it were local
- selected values would return as strings - rather than returning as date objects
The solution was to use { "timestamp": "local" }.
As far as I can tell { "timestamp": "UTC" } and { "timestamp": "-06:00" } had no effect.
The driver doesn’t validate the option strictly, it treats unknown values as “don’t parse dates,” so it just returns strings. That’s why you didn’t see an error, just strange behavior.