Skip to content
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

timezone pain #642

Closed
magnusjt opened this issue Sep 8, 2017 · 3 comments
Closed

timezone pain #642

magnusjt opened this issue Sep 8, 2017 · 3 comments

Comments

@magnusjt
Copy link

magnusjt commented Sep 8, 2017

The timezone option does not appear to do anything. If this package is supposed to be a dropin replacement for node-mysql, why isn't this at least mentioned somewhere? I've seen a few attempts at using the typeCast function instead, but this function doesn't work with pool (at least when I tried it). Are you planning on adding any of these soon?

The reason I need these is because my node application and the mysql server are running on different timezones, and I don't know what they are beforehand.

@ssypi
Copy link

ssypi commented Nov 28, 2017

typeCast does work in pool. Are you using .execute? typeCast seems only to work currently with .query as mentioned in #649

@magnusjt
Copy link
Author

You're probably right about that.

In the meantime I've switched back to https://github.com/mysqljs/mysql

I'm using the timezone settings shown below:

let config = {
	// ...
	timezone: 'UTC', // Interpret all received timestamps as UTC. Otherwise local timezone is assumed.
	dateStrings: [
		'DATE', // DATE's are returned as strings (otherwise they would be interpreted as YYYY-MM-DD 00:00:00+00:00)
		'DATETIME' // DATETIME's return as strings (otherwise they would interpreted as YYYY-MM-DD HH:mm:ss+00:00)
	]
};

let pool = mysql.createPool(config);
pool.on('connection', conn => {
	conn.query("SET time_zone='+00:00';", error => {
		if(error){
			throw error;
		}
	});
});

These settings work no matter what the client/server timezones are.

@magnusjt
Copy link
Author

I didn't notice this was fixed until now. Just wanted to say, thanks for fixing it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants