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
5 changes: 3 additions & 2 deletions lib/Drivers/DML/sqlite.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,12 +273,13 @@ Driver.prototype.valueToProperty = function (value, property) {
if (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));
}
}else {
// shift local to UTC
value.setTime(value.getTime() + (value.getTimezoneOffset() * 60000));
}
}
break;
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions test/integration/drivers/sqlite_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,40 @@ describe("Sqlite driver", function() {
should.strictEqual(valueToProperty('1.200 '), 1);
});
});

describe("date", function () {
var timezone = /GMT([+/-]\d{4})/.exec(new Date().toString())[1];

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

it("should return origin object when given non-string", function () {
var now = new Date();
should.strictEqual(valueToProperty(now), now);
var array = [];
should.strictEqual(valueToProperty(array), array);
var obj = {};
should.strictEqual(valueToProperty(obj), obj);
})

it("should pass on normal time", function () {
var normal = '2017-12-07 00:00:00';
should.strictEqual(valueToProperty(normal).toString(), new Date(normal).toString());
})

it("should pass on utc time by orm saved with local config", function () {
var utc = '2017-12-07T00:00:00';
should.strictEqual(valueToProperty(utc+'Z').toString(), new Date(utc+timezone).toString());
})

it("should pass on utc time by orm saved with timezone config", function () {
var utc = '2017-12-07T00:00:00';
driver.config.timezone = timezone;
should.strictEqual(valueToProperty(utc+'Z').toString(), new Date(utc+timezone).toString());
driver.config.timezone = '';
})
});
});
});

Expand Down