mirror of
https://github.com/zadam/trilium.git
synced 2025-11-14 18:39:01 +01:00
move date conversion function to enex directly
to protect from future potential refactoring
This commit is contained in:
parent
f728b2b0e7
commit
a3bd15e102
@ -27,19 +27,6 @@ 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) {
|
||||
return num <= 9 ? `0${num}` : `${num}`;
|
||||
}
|
||||
@ -104,10 +91,12 @@ function validateUtcDateTime(str: string | undefined) {
|
||||
}
|
||||
|
||||
export default {
|
||||
LOCAL_DATETIME_FORMAT,
|
||||
UTC_DATETIME_FORMAT,
|
||||
utcNowDateTime,
|
||||
localNowDateTime,
|
||||
localNowDate,
|
||||
formatDateTimeToLocalISO,
|
||||
|
||||
utcDateStr,
|
||||
utcDateTimeStr,
|
||||
parseDateTime,
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
import dayjs from "dayjs";
|
||||
import sax from "sax";
|
||||
import stream from "stream";
|
||||
import { Throttle } from "stream-throttle";
|
||||
@ -236,8 +237,8 @@ function importEnex(taskContext: TaskContext<"importNotes">, file: File, parentN
|
||||
|
||||
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
|
||||
const dateCreated = date_utils.formatDateTimeToLocalISO(utcDateCreated);
|
||||
const dateModified = date_utils.formatDateTimeToLocalISO(utcDateModified);
|
||||
const dateCreated = formatDateTimeToLocalDbFormat(utcDateCreated);
|
||||
const dateModified = formatDateTimeToLocalDbFormat(utcDateModified);
|
||||
sql.execute(
|
||||
`
|
||||
UPDATE notes
|
||||
@ -410,4 +411,17 @@ function importEnex(taskContext: TaskContext<"importNotes">, file: File, parentN
|
||||
});
|
||||
}
|
||||
|
||||
function formatDateTimeToLocalDbFormat(date: Date | string | null | undefined) {
|
||||
if (!date) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const d = dayjs(date);
|
||||
if (!d.isValid()) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return d.format(date_utils.LOCAL_DATETIME_FORMAT);
|
||||
}
|
||||
|
||||
export default { importEnex };
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user