-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DATE type casting #605
Comments
Hi, what version of the |
Seems to me that the default type cast for TIME and DATE database types should be JavaScript string. And the default type cast for TIMESTAMP and DATETIME database types should be JavaScript Date. It would be nice if the encoder would recognize fractional seconds and properly encode milliseconds into the JavaScript Date. |
I was using alpha8. Agreed with Craig. It seems to me it would be best if TIME and DATE simply returned as a string. |
When MySQL returns a date time string that includes fractional seconds, |
I also get something strange like this |
You can do that by setting |
@dougwilson Thank you so much! That's exactly what I expected. |
@dougwilson Can you elaborate on how to set the |
@habahut, see if the follow code is helpful to you or not. (function () {
"use strict";
var config = {
"host": "server_ip",
"port": 3306,
"user": "username",
"password": "password",
"connectionLimit": 20,
"dateStrings": true
};
var mysql = require('mysql');
exports.pool = mysql.createPool(config);
})(); |
@habahut it is in the readme:
var db = mysql.createConnection({ user: 'foo', password: 'bar', dateStrings: true }); |
@elgs @sidorares having looked again I see it right there in the readme. Sorry about that, I'm not sure how I missed it before. Thanks for the quick response. |
@dougwilson I agree with @CraigLRussell. I would expect the following behaviour:
The current behaviour really needs to change. DATE and TIME are unusable with |
@dougwilson any thoughts on this? I have run into problems with this so many times it's not funny. DATE fields absolutely MUST NOT use a timezone-aware format. It is far too fragile. If the client/server use different timezones, one creates a date object with a time of midnight, sends it over the wire, it gets converted to the other timezone - if you're lucky it'll be 01:00, if you're unlucky it'll be 23:00 and now your date is wrong. Worse, this will also break if the host environments use a differing timezone libraries, which is just horrific. Try 1970-06-28 with your timezone set to Europe/London on Linux and Windows and you will get different results. I don't want to set
|
We can do this in 3.0, which does not have any target yet. It's the reason I haven't closed the issue :) |
Is the implication in one of the comments true -- namely, node-mysql converts datetimes to GMT/UTC automatically? It seems to be happening in my case but I want to be sure. This is a bad thing because my datetimes are already GMT/UTC in the DB and are getting converted somewhere to GMT/UTC assuming that they are in the local timezone. |
Hi @ravi , it is converted based on what you set in your |
@dougwilson thank you. I also found from another issue reported here that I can set |
Adding checks to allow true OR "DATE" as dateStrings values "DATE" should only effect DATE fields whereas true retains original behavior, effecting DATE, DATETIME and TIMESTAMP fields. See: mysqljs#605 , loopbackio/loopback-connector-mysql#120 , loopbackio/loopback-connector-mysql#149
I have made a PR, #1481 , that hopes to address |
Adding checks to allow true OR "DATE" as dateStrings values "DATE" should only effect DATE fields whereas true retains original behavior, effecting DATE, DATETIME and TIMESTAMP fields. See: mysqljs#605 , loopbackio/loopback-connector-mysql#120 , loopbackio/loopback-connector-mysql#149
Add 'date' as dateStrings value option. The connection option dateStrings: 'date' will only affect DATE fields whereas any truthy value (except 'date') retains original behavior, effecting DATE, DATETIME and TIMESTAMP fields. See: mysqljs#605 , loopbackio/loopback-connector-mysql#120 , loopbackio/loopback-connector-mysql#149
DATE type casting should be turned off due to incorrect formatting it receives when it gets converted back a string. It should return from MYSQL as YYYY-MM-DD, however after type casting is shows as: yyyy-MM-ddTHH:mm:ss.000Z. If you store a field as DATE, why would you want an arbitrary time appended?
The text was updated successfully, but these errors were encountered: