Skip to content

Commit c5ee2ea

Browse files
committed
Store all dates as UTC for SQLite
Dates are stored in SQLite as Unix timestamps. Dates are represented in JavaScript as Unix timestamps. Thus, there need not be any sort of conversions. Client-side timezones are irrelevant; they should only affect the client-side display of dates. The existing code is incorrect because it's storing timezone-offset dates _as UTC dates_ (with the "Z" suffix). This change simplifies the type conversion; a Date is stored as an ISO-8601 date string, which is understood by both JavaScript's `Date` constructor and SQLite.
1 parent 117ced2 commit c5ee2ea

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
*.sublime-*
22
*.njsproj
3+
.idea
34
.DS_Store
45
node_modules
56
test.js

lib/Helpers.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ module.exports.escapeQuery = function (Dialect, query, args) {
1818
module.exports.dateToString = function (date, timeZone, opts) {
1919
var dt = new Date(date);
2020

21+
if (opts.dialect === 'sqlite') {
22+
return dt.toISOString();
23+
}
24+
2125
if (timeZone != 'local') {
2226
var tz = convertTimezone(timeZone);
2327

test/integration/test-dialect-sqlite.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ assert.equal(
7171

7272
assert.equal(
7373
dialect.escapeVal(new Date(d.getTime() + tzOffsetMillis)),
74-
"'2013-09-04T19:15:11.133Z'"
74+
"'2013-09-05T02:15:11.133Z'"
7575
);
7676

7777
assert.equal(
@@ -86,7 +86,7 @@ assert.equal(
8686

8787
assert.equal(
8888
dialect.escapeVal(new Date(d.getTime()), '-0400'),
89-
"'2013-09-04T15:15:11.133Z'"
89+
"'2013-09-04T19:15:11.133Z'"
9090
);
9191

9292
assert.equal(

0 commit comments

Comments
 (0)