mirror of
https://github.com/zadam/trilium.git
synced 2025-11-15 09:45:52 +01:00
Fix enex import stores wrong format in database for dateCreated, dateModified (#7718)
This commit is contained in:
@@ -91,9 +91,12 @@ function validateUtcDateTime(str: string | undefined) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
LOCAL_DATETIME_FORMAT,
|
||||||
|
UTC_DATETIME_FORMAT,
|
||||||
utcNowDateTime,
|
utcNowDateTime,
|
||||||
localNowDateTime,
|
localNowDateTime,
|
||||||
localNowDate,
|
localNowDate,
|
||||||
|
|
||||||
utcDateStr,
|
utcDateStr,
|
||||||
utcDateTimeStr,
|
utcDateTimeStr,
|
||||||
parseDateTime,
|
parseDateTime,
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
|
import dayjs from "dayjs";
|
||||||
import sax from "sax";
|
import sax from "sax";
|
||||||
import stream from "stream";
|
import stream from "stream";
|
||||||
import { Throttle } from "stream-throttle";
|
import { Throttle } from "stream-throttle";
|
||||||
import log from "../log.js";
|
import log from "../log.js";
|
||||||
import { md5, escapeHtml, fromBase64 } from "../utils.js";
|
import { md5, escapeHtml, fromBase64 } from "../utils.js";
|
||||||
|
import date_utils from "../date_utils.js";
|
||||||
import sql from "../sql.js";
|
import sql from "../sql.js";
|
||||||
import noteService from "../notes.js";
|
import noteService from "../notes.js";
|
||||||
import imageService from "../image.js";
|
import imageService from "../image.js";
|
||||||
@@ -235,6 +237,8 @@ function importEnex(taskContext: TaskContext<"importNotes">, file: File, parentN
|
|||||||
|
|
||||||
function updateDates(note: BNote, utcDateCreated?: string, utcDateModified?: string) {
|
function updateDates(note: BNote, utcDateCreated?: string, utcDateModified?: string) {
|
||||||
// it's difficult to force custom dateCreated and dateModified to Note entity, so we do it post-creation with SQL
|
// it's difficult to force custom dateCreated and dateModified to Note entity, so we do it post-creation with SQL
|
||||||
|
const dateCreated = formatDateTimeToLocalDbFormat(utcDateCreated, false);
|
||||||
|
const dateModified = formatDateTimeToLocalDbFormat(utcDateModified, false);
|
||||||
sql.execute(
|
sql.execute(
|
||||||
`
|
`
|
||||||
UPDATE notes
|
UPDATE notes
|
||||||
@@ -243,7 +247,7 @@ function importEnex(taskContext: TaskContext<"importNotes">, file: File, parentN
|
|||||||
dateModified = ?,
|
dateModified = ?,
|
||||||
utcDateModified = ?
|
utcDateModified = ?
|
||||||
WHERE noteId = ?`,
|
WHERE noteId = ?`,
|
||||||
[utcDateCreated, utcDateCreated, utcDateModified, utcDateModified, note.noteId]
|
[dateCreated, utcDateCreated, dateModified, utcDateModified, note.noteId]
|
||||||
);
|
);
|
||||||
|
|
||||||
sql.execute(
|
sql.execute(
|
||||||
@@ -407,4 +411,21 @@ function importEnex(taskContext: TaskContext<"importNotes">, file: File, parentN
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function formatDateTimeToLocalDbFormat(
|
||||||
|
utcDateFromEnex: Date | string | null | undefined,
|
||||||
|
keepUtc: boolean
|
||||||
|
): string | undefined {
|
||||||
|
if (!utcDateFromEnex) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
const parsedDate = dayjs(utcDateFromEnex);
|
||||||
|
|
||||||
|
if (!parsedDate.isValid()) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (keepUtc ? parsedDate.utc() : parsedDate).format(date_utils.LOCAL_DATETIME_FORMAT);
|
||||||
|
}
|
||||||
|
|
||||||
export default { importEnex };
|
export default { importEnex };
|
||||||
|
|||||||
Reference in New Issue
Block a user