mirror of
https://github.com/zadam/trilium.git
synced 2025-11-14 17:25:52 +01:00
fix enex import saves local dates in wrong format (with Z, like UTC fields)
the proper format for dateCreated, dateModified is: +0000
This commit is contained in:
@@ -27,6 +27,19 @@ function localNowDate() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function formatDateTimeToLocalISO(date: Date | string | null | undefined) {
|
||||||
|
if (!date) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
const d = dayjs(date);
|
||||||
|
if (!d.isValid()) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
return d.format(LOCAL_DATETIME_FORMAT);
|
||||||
|
}
|
||||||
|
|
||||||
function pad(num: number) {
|
function pad(num: number) {
|
||||||
return num <= 9 ? `0${num}` : `${num}`;
|
return num <= 9 ? `0${num}` : `${num}`;
|
||||||
}
|
}
|
||||||
@@ -94,6 +107,7 @@ export default {
|
|||||||
utcNowDateTime,
|
utcNowDateTime,
|
||||||
localNowDateTime,
|
localNowDateTime,
|
||||||
localNowDate,
|
localNowDate,
|
||||||
|
formatDateTimeToLocalISO,
|
||||||
utcDateStr,
|
utcDateStr,
|
||||||
utcDateTimeStr,
|
utcDateTimeStr,
|
||||||
parseDateTime,
|
parseDateTime,
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ 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 +236,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 = date_utils.formatDateTimeToLocalISO(utcDateCreated);
|
||||||
|
const dateModified = date_utils.formatDateTimeToLocalISO(utcDateModified);
|
||||||
sql.execute(
|
sql.execute(
|
||||||
`
|
`
|
||||||
UPDATE notes
|
UPDATE notes
|
||||||
@@ -243,7 +246,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(
|
||||||
|
|||||||
Reference in New Issue
Block a user