mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-24 10:27:10 +02:00
All: Fix format of note timestamps (#2672)
* Correct format of timestamps during unserialization. * Add tests.
This commit is contained in:
parent
7fb061ea76
commit
a17e01793e
@ -57,4 +57,16 @@ describe('models_BaseItem', function() {
|
||||
expect(unserialized2.title).toBe(folder2.title);
|
||||
}));
|
||||
|
||||
it('should correctly unserialize note timestamps', asyncTest(async () => {
|
||||
let folder = await Folder.save({ title: 'folder' });
|
||||
let note = await Note.save({ title: 'note', parent_id: folder.id });
|
||||
|
||||
let serialized = await Note.serialize(note);
|
||||
let unserialized = await Note.unserialize(serialized);
|
||||
|
||||
expect(unserialized.created_time).toEqual(note.created_time);
|
||||
expect(unserialized.updated_time).toEqual(note.updated_time);
|
||||
expect(unserialized.user_created_time).toEqual(note.user_created_time);
|
||||
expect(unserialized.user_updated_time).toEqual(note.user_updated_time);
|
||||
}));
|
||||
});
|
||||
|
@ -254,13 +254,13 @@ class BaseItem extends BaseModel {
|
||||
|
||||
const ItemClass = this.itemClass(type);
|
||||
|
||||
if (['created_time', 'updated_time', 'user_created_time', 'user_updated_time'].indexOf(propName) >= 0) {
|
||||
if (!propValue) return 0;
|
||||
propValue = moment(propValue, 'YYYY-MM-DDTHH:mm:ss.SSSZ').format('x');
|
||||
} else if (['title_diff', 'body_diff'].indexOf(propName) >= 0) {
|
||||
if (['title_diff', 'body_diff'].indexOf(propName) >= 0) {
|
||||
if (!propValue) return '';
|
||||
propValue = JSON.parse(propValue);
|
||||
} else {
|
||||
if (['created_time', 'updated_time', 'user_created_time', 'user_updated_time'].indexOf(propName) >= 0) {
|
||||
propValue = (!propValue) ? '0' : moment(propValue, 'YYYY-MM-DDTHH:mm:ss.SSSZ').format('x');
|
||||
}
|
||||
propValue = Database.formatValue(ItemClass.fieldType(propName), propValue);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user