node-mysql2: Compatible timezone value (and missing docs)
Coming from mysql
to mysql2
has learning curve, how to set timezone?
Currently, there’s zero documentation about a such option, but using it, the library prints a warning:
Ignoring invalid timezone passed to Connection: UTC. This is currently a warning, but in future versions of MySQL2, an error will be thrown if you pass an invalid configuration option to a Connection
from searching the source code I found that equivalent would be Z
.
perhaps add UTC
to the list as well (to be identical to Z
)?
About this issue
- Original URL
- State: open
- Created 2 years ago
- Comments: 17 (8 by maintainers)
I figured out the issue. Let’s start by stating that there is no issue in the mysql2 library.
We have several large applications that read/write to the same database. Some of our schemas use DATETIME columns to store dates. All of our servers are running in the Europe/Amsterdam timezone, but our MySQL server is running on UTC.
It seems that every application is writing to the database in the local timezone. I thought there was an issue because I’m writing a new application that does use correct timezone configuration, but got strange results. Because of this, I expected something bad to be happening in this library, since all other applications ran fine.
I solved it by treating all incoming and outgoing DATETIME values as strings (thanks for the
dateStrings
configuration 😅) to ensure the database stores the values in the same way as when they are retrieved. By treating the values as plain strings, we just let the application do the timezone conversion automatically based on the server configuration.It’s not pretty - not by a long shot - but at least the behavior is now consistent with the other applications.
Apologies for the fuzz 😅