Skip to content

Test Failure: test-type-casting DATE #636

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

Closed
iarna opened this issue Nov 12, 2013 · 4 comments
Closed

Test Failure: test-type-casting DATE #636

iarna opened this issue Nov 12, 2013 · 4 comments

Comments

@iarna
Copy link
Contributor

iarna commented Nov 12, 2013

The specific test is this one:

{type: 'date', insert: new Date('2012-05-12 00:00:00 Z')},

The error message is:

[0:00:14 0 58/73 79.5% node test/integration/connection/test-type-casting.js]

  assert.js:92
    throw new assert.AssertionError({
          ^
  AssertionError: got: "Thu May 10 2012 20:00:00 GMT-0400 (EDT)" (string) expected: "Fri May 11 2012 20:00:00 GMT-0400 (EDT)" (string) test: date
      at /opt/home/turner/Dropbox/Code/node-mysql/test/integration/connection/test-type-casting.js:115:14
      at Array.forEach (native)
      at process.<anonymous> (/opt/home/turner/Dropbox/Code/node-mysql/test/integration/connection/test-type-casting.js:91:9)
      at process.EventEmitter.emit (events.js:100:17)

MySQL and Node are running on the same system. The system timezone is America/New_York (-05:00 EST / -04:00 EDT). MySQL configuration is below:

mysql> select @@time_zone,timediff(now(),UTC_TIMESTAMP) as offset;
+-------------+-----------+
| @@time_zone | offset    |
+-------------+-----------+
| SYSTEM      | -05:00:00 |
+-------------+-----------+
1 row in set (0.00 sec)
@tgpfeiffer
Copy link
Contributor

Which OS are you on? What is your MySQL and node version? I tried to reproduce your issue (setting computer and MySQL time zone to yours), but didn't succeed; the test always passes.
Since the assertion fail dates are exactly one day apart, I guess that '2012-05-12 00:00:00 Z' is maybe interpreted as the date 2012-05-11 at one place, but as 2012-05-12 at another. Will be a mess to find out where the conversion fails... ;-)

@tgpfeiffer
Copy link
Contributor

Could you, just for fun, change the timestamp one second into the future and check whether it still fails on your system?

@tgpfeiffer
Copy link
Contributor

@iarna I can now reproduce your problem. I don't know why the tests run fine for me, but it seems as if for any time zone west of UTC, inserting and getting back out a JavaScript Date into a MySQL date column loses a day. Consider this very simple script:

connection.connect();

connection.query("USE nodetest");
connection.query("DROP TABLE test");
connection.query("CREATE TABLE IF NOT EXISTS test (id int, val date)");

var dString = '2012-05-12 00:00:00 Z';  // from the unit test
console.log(dString);
var d = new Date(dString);
console.log(d);

connection.query("INSERT INTO test(id, val) VALUES(?, ?)", [1, d]);

function compareWithOriginal(err, rows, fields) {
  var someDate = rows[0].val;
  if (someDate >= d && someDate <= d) {
    console.log("fine");
  } else {
    console.log("oops: " + someDate + " != " + d);
  }
}

connection.query("SELECT * FROM test", compareWithOriginal);

connection.end();

This outputs "fine" for every system time zone east of UTC (that I tested), but a message like "oops: Thu May 10 2012 21:00:00 GMT-0300 (ART) != Fri May 11 2012 21:00:00 GMT-0300 (ART)" for every one west of UTC (that I tested).

I will investigate this further, but also I don't understand why -- even with "negative" time zones -- my own tests do not raise the assertion error that you see.

Edit: My mistake; with any timezone west of UTC, my tests also fail - if I let them run long enough ;-)

@felixge
Copy link
Collaborator

felixge commented Nov 21, 2013

Fixed in dc23690.

@felixge felixge closed this as completed Nov 21, 2013
dveeden pushed a commit to dveeden/mysql that referenced this issue Jan 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants