不要怂,就是干,撸起袖子干!

Commit 33727829 by Jan Aagaard Meier

Merge pull request #2067 from jthele/dst

dst fix
2 parents 530c1952 ebb0076c
...@@ -153,23 +153,14 @@ SqlString.formatNamedParameters = function(sql, values, timeZone, dialect) { ...@@ -153,23 +153,14 @@ SqlString.formatNamedParameters = function(sql, values, timeZone, dialect) {
} }
SqlString.dateToString = function(date, timeZone, dialect) { SqlString.dateToString = function(date, timeZone, dialect) {
var dt = new Date(date) date = moment(date).zone(timeZone);
// TODO: Ideally all dialects would work a bit more like this if (dialect === 'mysql' || dialect === 'mariadb') {
if (dialect === "postgres") { return date.format('YYYY-MM-DD HH:mm:ss');
return moment(dt).zone('+00:00').format("YYYY-MM-DD HH:mm:ss.SSS Z") } else {
} // ZZ here means current timezone, _not_ UTC
return date.format('YYYY-MM-DD HH:mm:ss.SSS Z');
if (timeZone !== 'local') {
var tz = convertTimezone(timeZone)
dt.setTime(dt.getTime() + (dt.getTimezoneOffset() * 60000))
if (tz !== false) {
dt.setTime(dt.getTime() + (tz * 60000))
}
} }
return moment(dt).format("YYYY-MM-DD HH:mm:ss")
} }
SqlString.bufferToString = function(buffer, dialect) { SqlString.bufferToString = function(buffer, dialect) {
...@@ -208,15 +199,3 @@ SqlString.objectToValues = function(object, timeZone) { ...@@ -208,15 +199,3 @@ SqlString.objectToValues = function(object, timeZone) {
function zeroPad(number) { function zeroPad(number) {
return (number < 10) ? '0' + number : number return (number < 10) ? '0' + number : number
} }
function convertTimezone(tz) {
if (tz == "Z") {
return 0
}
var m = tz.match(/([\+\-\s])(\d\d):?(\d\d)?/)
if (m) {
return (m[1] == '-' ? -1 : 1) * (parseInt(m[2], 10) + ((m[3] ? parseInt(m[3], 10) : 0) / 60)) * 60
}
return false
}
...@@ -182,7 +182,7 @@ if (dialect === 'sqlite') { ...@@ -182,7 +182,7 @@ if (dialect === 'sqlite') {
] ]
} }
}], }],
expectation: "SELECT * FROM `myTable` ORDER BY f1(`myTable`.`id`) DESC, f2(12, 'lalala', '2011-03-27 10:01:55') ASC;", expectation: "SELECT * FROM `myTable` ORDER BY f1(`myTable`.`id`) DESC, f2(12, 'lalala', '2011-03-27 10:01:55.000 +00:00') ASC;",
context: QueryGenerator, context: QueryGenerator,
needsSequelize: true needsSequelize: true
}, { }, {
...@@ -315,7 +315,7 @@ if (dialect === 'sqlite') { ...@@ -315,7 +315,7 @@ if (dialect === 'sqlite') {
expectation: "INSERT INTO `myTable` (`name`,`value`) VALUES ('bar',NULL);" expectation: "INSERT INTO `myTable` (`name`,`value`) VALUES ('bar',NULL);"
}, { }, {
arguments: ['myTable', {name: 'foo', birthday: moment("2011-03-27 10:01:55 +0000", "YYYY-MM-DD HH:mm:ss Z").toDate()}], arguments: ['myTable', {name: 'foo', birthday: moment("2011-03-27 10:01:55 +0000", "YYYY-MM-DD HH:mm:ss Z").toDate()}],
expectation: "INSERT INTO `myTable` (`name`,`birthday`) VALUES ('foo','2011-03-27 10:01:55');" expectation: "INSERT INTO `myTable` (`name`,`birthday`) VALUES ('foo','2011-03-27 10:01:55.000 +00:00');"
}, { }, {
arguments: ['myTable', { name: "foo", value: true }], arguments: ['myTable', { name: "foo", value: true }],
expectation: "INSERT INTO `myTable` (`name`,`value`) VALUES ('foo',1);" expectation: "INSERT INTO `myTable` (`name`,`value`) VALUES ('foo',1);"
...@@ -357,7 +357,7 @@ if (dialect === 'sqlite') { ...@@ -357,7 +357,7 @@ if (dialect === 'sqlite') {
expectation: "INSERT INTO `myTable` (`name`) VALUES ('''bar'''),('foo');" expectation: "INSERT INTO `myTable` (`name`) VALUES ('''bar'''),('foo');"
}, { }, {
arguments: ['myTable', [{name: 'foo', birthday: moment("2011-03-27 10:01:55 +0000", "YYYY-MM-DD HH:mm:ss Z").toDate()}, {name: 'bar', birthday: moment("2012-03-27 10:01:55 +0000", "YYYY-MM-DD HH:mm:ss Z").toDate()}]], arguments: ['myTable', [{name: 'foo', birthday: moment("2011-03-27 10:01:55 +0000", "YYYY-MM-DD HH:mm:ss Z").toDate()}, {name: 'bar', birthday: moment("2012-03-27 10:01:55 +0000", "YYYY-MM-DD HH:mm:ss Z").toDate()}]],
expectation: "INSERT INTO `myTable` (`name`,`birthday`) VALUES ('foo','2011-03-27 10:01:55'),('bar','2012-03-27 10:01:55');" expectation: "INSERT INTO `myTable` (`name`,`birthday`) VALUES ('foo','2011-03-27 10:01:55.000 +00:00'),('bar','2012-03-27 10:01:55.000 +00:00');"
}, { }, {
arguments: ['myTable', [{name: "bar", value: null}, {name: 'foo', value: 1}]], arguments: ['myTable', [{name: "bar", value: null}, {name: 'foo', value: 1}]],
expectation: "INSERT INTO `myTable` (`name`,`value`) VALUES ('bar',NULL),('foo',1);" expectation: "INSERT INTO `myTable` (`name`,`value`) VALUES ('bar',NULL),('foo',1);"
...@@ -394,10 +394,10 @@ if (dialect === 'sqlite') { ...@@ -394,10 +394,10 @@ if (dialect === 'sqlite') {
updateQuery: [ updateQuery: [
{ {
arguments: ['myTable', {name: 'foo', birthday: moment("2011-03-27 10:01:55 +0000", "YYYY-MM-DD HH:mm:ss Z").toDate()}, {id: 2}], arguments: ['myTable', {name: 'foo', birthday: moment("2011-03-27 10:01:55 +0000", "YYYY-MM-DD HH:mm:ss Z").toDate()}, {id: 2}],
expectation: "UPDATE `myTable` SET `name`='foo',`birthday`='2011-03-27 10:01:55' WHERE `id`=2" expectation: "UPDATE `myTable` SET `name`='foo',`birthday`='2011-03-27 10:01:55.000 +00:00' WHERE `id`=2"
}, { }, {
arguments: ['myTable', {name: 'foo', birthday: moment("2011-03-27 10:01:55 +0000", "YYYY-MM-DD HH:mm:ss Z").toDate()}, 2], arguments: ['myTable', {name: 'foo', birthday: moment("2011-03-27 10:01:55 +0000", "YYYY-MM-DD HH:mm:ss Z").toDate()}, 2],
expectation: "UPDATE `myTable` SET `name`='foo',`birthday`='2011-03-27 10:01:55' WHERE `id`=2" expectation: "UPDATE `myTable` SET `name`='foo',`birthday`='2011-03-27 10:01:55.000 +00:00' WHERE `id`=2"
}, { }, {
arguments: ['myTable', { name: 'foo' }, { id: 2 }], arguments: ['myTable', { name: 'foo' }, { id: 2 }],
expectation: "UPDATE `myTable` SET `name`='foo' WHERE `id`=2" expectation: "UPDATE `myTable` SET `name`='foo' WHERE `id`=2"
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!