Putting and then getting dates in a document are altered by u1db

Bug #1482504 reported by Didier Roche-Tolomelli
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
U1DB Qt/ QML
New
Undecided
Cris Dywan
u1db-qt (Ubuntu)
New
Undecided
Unassigned

Bug Description

When putting and getting a QML date in the u1db database, the resulting strings are stored differently, even if you don't do any type conversion.

The result is that the resulting date is shifted by the current timezone, rendering an incorrect date.

Small example:

qml: date object to save: "Fri Aug 7 08:15:36 2015 GMT+0200" (value chosen by the user in a datetime picker: 08:15)

This value is jsonified in var current = {"title":"First element","date":"2015-08-07T06:15:36.573Z"}
(so, it offsetted correctly in UTC)

console.log("Before save: " + JSON.stringify(tosave));
db.putDoc(tosave, current.billId);
var after = db.getDoc(current.billId.toString())
console.log("After save: " + JSON.stringify(afterSave));

log is:
qml: Before save: {"title":"First element","date":"2015-08-07T06:15:36.573Z"}
qml: After save: {"date":"2015-08-07T08:15:36","title":"First element"}
-> Looking at the sqlite database, indeed, putDoc() saved "2015-08-07T08:15:36" and not "2015-08-07T06:15:36.573Z". And then, assigning that to a Date variable will reapply again the timezone offest, thinking the string is in UTC, and resulting in 10:15 instead of 08.15.

-> Note that the date element has been altered and isn't returned in the same format The date should be returned unalterned. Then it's up to the user to save the timezone independently if they want.

Tags: devexp

Related branches

tags: added: devexp
description: updated
description: updated
Revision history for this message
Didier Roche-Tolomelli (didrocks) wrote :

current workaround is to cheat on the saved date in database, meaning, removing again the timezone to the date object to shift it to UTC (it will print as "<time in UTC> + (timezone)" which is untrue, so only do that for the database object)

Example, just before putDoc:
tosave["date"] = new Date(tosave["date"].getTime() + tosave["date"].getTimezoneOffset() * 60000)

Cris Dywan (kalikiana)
Changed in u1db-qt:
assignee: nobody → Christian Dywan (kalikiana)
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.