Skip to content

Commit b264b83

Browse files
committed
Handle django string formatted sqlite datetime
1 parent 5447c68 commit b264b83

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

lib/Drivers/DML/sqlite.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,13 @@ Driver.prototype.valueToProperty = function (value, property) {
207207
return null;
208208
}
209209
break;
210+
case "date":
211+
if (typeof value === 'string') {
212+
if (value.indexOf('Z', value.length - 1) === -1) {
213+
return new Date(value + 'Z');
214+
}
215+
}
216+
return new Date(value);
210217
default:
211218
return value;
212219
}
@@ -218,6 +225,48 @@ Driver.prototype.propertyToValue = function (value, property) {
218225
return (value) ? 1 : 0;
219226
case "object":
220227
return JSON.stringify(value);
228+
case "date":
229+
if (this.config.query.strdates) {
230+
if (value instanceof Date) {
231+
var year = value.getUTCFullYear();
232+
var month = value.getUTCMonth() + 1;
233+
if (month < 10) {
234+
month = '0' + month;
235+
}
236+
var date = value.getUTCDate();
237+
if (date < 10) {
238+
date = '0' + date;
239+
}
240+
var strdate = year + '-' + month + '-' + date;
241+
if (property.time === false) {
242+
return strdate;
243+
}
244+
245+
var hours = value.getUTCHours();
246+
if (hours < 10) {
247+
hours = '0' + hours;
248+
}
249+
var minutes = value.getUTCMinutes();
250+
if (minutes < 10) {
251+
minutes = '0' + minutes;
252+
}
253+
var seconds = value.getUTCSeconds();
254+
if (seconds < 10) {
255+
seconds = '0' + seconds;
256+
}
257+
var millis = value.getUTCMilliseconds();
258+
if (millis < 10) {
259+
millis = '0' + millis;
260+
}
261+
if (millis < 100) {
262+
millis = '0' + millis;
263+
}
264+
strdate += ' ' + hours + ':' + minutes + ':' + seconds + '.' + millis + '000';
265+
return strdate;
266+
}
267+
268+
}
269+
return value;
221270
default:
222271
return value;
223272
}

0 commit comments

Comments
 (0)