Skip to content

Commit a3bd15e

Browse files
committed
move date conversion function to enex directly
to protect from future potential refactoring
1 parent f728b2b commit a3bd15e

File tree

2 files changed

+19
-16
lines changed

2 files changed

+19
-16
lines changed

apps/server/src/services/date_utils.ts

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,6 @@ function localNowDate() {
2727
}
2828
}
2929

30-
function formatDateTimeToLocalISO(date: Date | string | null | undefined) {
31-
if (!date) {
32-
return undefined;
33-
}
34-
35-
const d = dayjs(date);
36-
if (!d.isValid()) {
37-
return undefined;
38-
}
39-
40-
return d.format(LOCAL_DATETIME_FORMAT);
41-
}
42-
4330
function pad(num: number) {
4431
return num <= 9 ? `0${num}` : `${num}`;
4532
}
@@ -104,10 +91,12 @@ function validateUtcDateTime(str: string | undefined) {
10491
}
10592

10693
export default {
94+
LOCAL_DATETIME_FORMAT,
95+
UTC_DATETIME_FORMAT,
10796
utcNowDateTime,
10897
localNowDateTime,
10998
localNowDate,
110-
formatDateTimeToLocalISO,
99+
111100
utcDateStr,
112101
utcDateTimeStr,
113102
parseDateTime,

apps/server/src/services/import/enex.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import dayjs from "dayjs";
12
import sax from "sax";
23
import stream from "stream";
34
import { Throttle } from "stream-throttle";
@@ -236,8 +237,8 @@ function importEnex(taskContext: TaskContext<"importNotes">, file: File, parentN
236237

237238
function updateDates(note: BNote, utcDateCreated?: string, utcDateModified?: string) {
238239
// it's difficult to force custom dateCreated and dateModified to Note entity, so we do it post-creation with SQL
239-
const dateCreated = date_utils.formatDateTimeToLocalISO(utcDateCreated);
240-
const dateModified = date_utils.formatDateTimeToLocalISO(utcDateModified);
240+
const dateCreated = formatDateTimeToLocalDbFormat(utcDateCreated);
241+
const dateModified = formatDateTimeToLocalDbFormat(utcDateModified);
241242
sql.execute(
242243
`
243244
UPDATE notes
@@ -410,4 +411,17 @@ function importEnex(taskContext: TaskContext<"importNotes">, file: File, parentN
410411
});
411412
}
412413

414+
function formatDateTimeToLocalDbFormat(date: Date | string | null | undefined) {
415+
if (!date) {
416+
return undefined;
417+
}
418+
419+
const d = dayjs(date);
420+
if (!d.isValid()) {
421+
return undefined;
422+
}
423+
424+
return d.format(date_utils.LOCAL_DATETIME_FORMAT);
425+
}
426+
413427
export default { importEnex };

0 commit comments

Comments
 (0)