Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
language: node_js
node_js:
- '0.8'
- '0.10'
- '0.12'
- 'iojs-v1.5.1'
before_script:
- mysql -e 'create database orm_test;'
- psql -c 'create database orm_test;' -U postgres
Expand Down
5 changes: 3 additions & 2 deletions lib/Drivers/DML/postgres.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,11 +264,12 @@ Driver.prototype.valueToProperty = function (value, property) {
}
break;
case "date":
if (this.config.timezone && this.config.timezone != 'local') {
if (_.isDate(value) && this.config.timezone && this.config.timezone != 'local') {
var tz = convertTimezone(this.config.timezone);

// shift local to UTC
value.setTime(value.getTime() - (value.getTimezoneOffset() * 60000));

if (tz !== false) {
// shift UTC to timezone
value.setTime(value.getTime() - (tz * 60000));
Expand Down Expand Up @@ -320,7 +321,7 @@ Driver.prototype.propertyToValue = function (value, property) {
}
break;
case "date":
if (this.config.timezone && this.config.timezone != 'local') {
if (_.isDate(value) && this.config.timezone && this.config.timezone != 'local') {
var tz = convertTimezone(this.config.timezone);

// shift local to UTC
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@
"lodash" : "2.4.1"
},
"devDependencies": {
"mysql" : "2.0.0-alpha9",
"pg" : "2.6.2",
"sqlite3" : "2.1.7",
"mysql" : "2.5.5",
"pg" : "4.3.0",
"sqlite3" : "3.0.5",
"async" : "0.9.0",
"mocha" : "1.13.0",
"should" : "1.2.2",
Expand Down
2 changes: 1 addition & 1 deletion test/integration/association-hasmany.js
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,7 @@ describe("hasMany", function () {
should.equal(data[0].name, 'account_id');
should.equal(data[0].pk, 1);
should.equal(data[1].name, 'emails_text');
should.equal(data[1].pk, 1);
should.equal(data[1].pk, 2);

done();
});
Expand Down
50 changes: 47 additions & 3 deletions test/integration/drivers/postgres_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe("Postgres driver", function() {
describe("#valueToProperty", function () {
var driver = null;

before(function () {
beforeEach(function () {
driver = new Driver({}, {}, {});
});

Expand Down Expand Up @@ -72,6 +72,35 @@ describe("Postgres driver", function() {
should.strictEqual(valueToProperty('1.200 '), 1);
});
});

describe("dates with non local timezone", function () {
beforeEach(function () {
driver = new Driver({ timezone: 'Z' }, {}, {});
});

function valueToProperty (value) {
return driver.valueToProperty(value, { type: 'date' });
}

it("should accept null", function () {
should.strictEqual(valueToProperty(null), null);
});

it("should work", function () {
should.strictEqual(_.isDate(valueToProperty(new Date())), true);
});

describe("calculations", function () {
it("should offset time, relative to timezone", function () {
d = new Date();

expected = d.getTime() - d.getTimezoneOffset() * 60000;
converted = valueToProperty(d).getTime();

should.equal(converted, expected);
});
});
});
});
});

Expand Down Expand Up @@ -116,9 +145,24 @@ describe("Postgres driver", function() {
should.equal(inputStr, out.toString());
});

it("should offset time by specified timezone amount for + timezones");
it("should work with null dates", function () {
should.strictEqual(evaluate(null, { config: { timezone: 'Z' }}), null);
});

it("should work with date objects", function () {
should.strictEqual(_.isDate(evaluate(new Date(), { config: { timezone: 'Z' }})), true);
});

describe("calculations", function () {
it("should offset time, relative to timezone", function () {
d = new Date();

expected = d.getTime() + d.getTimezoneOffset() * 60000;
converted = evaluate(d, { config: { timezone: 'Z' }}).getTime();

it("should offset time by specified timezone amount for + timezones");
should.equal(converted, expected);
});
});
});

describe("type point", function () {
Expand Down
13 changes: 6 additions & 7 deletions test/integration/validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -421,12 +421,12 @@ describe("Validations", function() {
should(Array.isArray(err));
should.equal(err.length, 2);

should.deepEqual(err[0], _.extend(new Error(),{
property: 'name', value: 'n', msg: 'out-of-range-length'
should.deepEqual(err[0], _.extend(new Error('out-of-range-length'), {
property: 'name', value: 'n', msg: 'out-of-range-length', type: 'validation'
}));

should.deepEqual(err[1], _.extend(new Error(),{
property: 'height', value: '4', msg: 'out-of-range-number'
property: 'height', value: '4', msg: 'out-of-range-number', type: 'validation'
}));

should.equal(john.id, null);
Expand All @@ -447,17 +447,16 @@ describe("Validations", function() {
should(Array.isArray(err));
should.equal(err.length, 3);

// `type` is a non enumerable undocumented property of `Error` in V8.
should.deepEqual(err[0], _.extend(new Error(),{
property: 'name', value: null, msg: 'required'
property: 'name', value: null, msg: 'required', type: 'validation'
}));

should.deepEqual(err[1], _.extend(new Error(),{
property: 'name', value: null, msg: 'undefined'
property: 'name', value: null, msg: 'undefined', type: 'validation'
}));

should.deepEqual(err[2], _.extend(new Error(),{
property: 'height', value: '4', msg: 'out-of-range-number'
property: 'height', value: '4', msg: 'out-of-range-number', type: 'validation'
}));

should.equal(john.id, null);
Expand Down