{"action":"created","issue":{"url":"https://api.github.com/repos/sequelize/sequelize/issues/3000","labels_url":"https://api.github.com/repos/sequelize/sequelize/issues/3000/labels{/name}","comments_url":"https://api.github.com/repos/sequelize/sequelize/issues/3000/comments","events_url":"https://api.github.com/repos/sequelize/sequelize/issues/3000/events","html_url":"https://github.com/sequelize/sequelize/issues/3000","id":55410511,"number":3000,"title":"Sequelize not handling datetimes correctly when backed by TIMESTAMP WITHOUT TIME ZONE","user":{"login":"chris-33","id":7235795,"avatar_url":"https://avatars.githubusercontent.com/u/7235795?v=3","gravatar_id":"","url":"https://api.github.com/users/chris-33","html_url":"https://github.com/chris-33","followers_url":"https://api.github.com/users/chris-33/followers","following_url":"https://api.github.com/users/chris-33/following{/other_user}","gists_url":"https://api.github.com/users/chris-33/gists{/gist_id}","starred_url":"https://api.github.com/users/chris-33/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chris-33/subscriptions","organizations_url":"https://api.github.com/users/chris-33/orgs","repos_url":"https://api.github.com/users/chris-33/repos","events_url":"https://api.github.com/users/chris-33/events{/privacy}","received_events_url":"https://api.github.com/users/chris-33/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/sequelize/sequelize/labels/bug","name":"bug","color":"d7e102"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2015-01-25T11:06:18Z","updated_at":"2015-08-23T10:29:35Z","closed_at":null,"body":"**The issue**\r\n\r\nGiven the following\r\n\r\n        var Entry = sequelize.define(\"Entry\", {\r\n             _id: {\r\n                type: DataTypes.INTEGER,\r\n                primaryKey: true\r\n            },\r\n            datetime: {\r\n                type: DataTypes.DATE,\r\n                allowNull: false\r\n            } ...\r\n\r\nthe following test fails:\r\n\r\n    it('should not mess with the time', function() {\r\n        var datetime = new Date(Date.now());\r\n        datetime.setMilliseconds(0);\r\n\r\n        var entry = {\r\n            _id: 0,\r\n            datetime: datetime\r\n        };\r\n\r\n        return expect(Entry\r\n                .create(entry)\r\n                .then(function(entry) { return Entry.find(entry._id); })\r\n                .then(function(entry) { return entry.datetime.getTime(); }))\r\n                .to.eventually.equal(entry.datetime.getTime());\r\n    });\r\n\r\nThe values differ by an hour (I'm on CET).\r\n\r\nIn the database, the values are stored as TIMESTAMP(0) WITHOUT TIME ZONE, which I can't change for legacy reasons. \r\n\r\n**The workaround**\r\n\r\nFor the time being, I'm working around it by adding\r\n\r\n    require('pg').types.setTypeParser(1114, function(stringValue) {\r\n        return new Date(stringValue.substring(0, 10) + 'T' + stringValue.substring(11) + '.000Z');\r\n    });\r\n\r\n**Why I'm posting**\r\n\r\nSo having found a workaround, why am I posting this? For two reasons, mainly:\r\n\r\n1. I've spent hours trying to find out what was going wrong and how to fix it, and had a hard time finding help through google. I'm hoping it'll help somebody down the road\r\n2. It would be nice to see Sequelize support this without requiring ugly hacks. Because other than this, it's pretty awesome, y'know. :)\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/sequelize/sequelize/issues/comments/133813604","html_url":"https://github.com/sequelize/sequelize/issues/3000#issuecomment-133813604","issue_url":"https://api.github.com/repos/sequelize/sequelize/issues/3000","id":133813604,"user":{"login":"mickhansen","id":699049,"avatar_url":"https://avatars.githubusercontent.com/u/699049?v=3","gravatar_id":"","url":"https://api.github.com/users/mickhansen","html_url":"https://github.com/mickhansen","followers_url":"https://api.github.com/users/mickhansen/followers","following_url":"https://api.github.com/users/mickhansen/following{/other_user}","gists_url":"https://api.github.com/users/mickhansen/gists{/gist_id}","starred_url":"https://api.github.com/users/mickhansen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mickhansen/subscriptions","organizations_url":"https://api.github.com/users/mickhansen/orgs","repos_url":"https://api.github.com/users/mickhansen/repos","events_url":"https://api.github.com/users/mickhansen/events{/privacy}","received_events_url":"https://api.github.com/users/mickhansen/received_events","type":"User","site_admin":false},"created_at":"2015-08-23T10:29:35Z","updated_at":"2015-08-23T10:29:35Z","body":"@zaptree Most users probably use timezones or save it in UTC since postgres uses UTC internally. Otherwise you have to set your connection timezone to whatever timezone you're storing data from."}}