Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
create months and days with associated english names, closes #37
azivnere9705640366e
diff --git a/src/routes/api/login.js b/src/routes/api/login.jsindex c632c5665e..befc3bba3e 100644--- a/src/routes/api/login.js+++ b/src/routes/api/login.js@@ -14,7 +14,7 @@ const wrap = require('express-promise-wrap').wrap;router.post('/sync', wrap(async (req, res, next) => {const timestampStr = req.body.timestamp;- const timestamp = utils.parseDate(timestampStr);+ const timestamp = utils.parseDateTime(timestampStr);const now = new Date();diff --git a/src/services/backup.js b/src/services/backup.jsindex f143d4764d..085aa10759 100644--- a/src/services/backup.js+++ b/src/services/backup.js@@ -10,7 +10,7 @@ const sync_mutex = require('./sync_mutex');async function regularBackup() {const now = new Date();- const lastBackupDate = utils.parseDate(await options.getOption('last_backup_date'));+ const lastBackupDate = utils.parseDateTime(await options.getOption('last_backup_date'));console.log(lastBackupDate);diff --git a/src/services/date_notes.js b/src/services/date_notes.jsindex 90cdd5e6a5..d93c868fdf 100644--- a/src/services/date_notes.js+++ b/src/services/date_notes.js@@ -3,12 +3,16 @@const sql = require('./sql');const notes = require('./notes');const attributes = require('./attributes');+const utils = require('./utils');const CALENDAR_ROOT_ATTRIBUTE = 'calendar_root';const YEAR_ATTRIBUTE = 'year_note';const MONTH_ATTRIBUTE = 'month_note';const DATE_ATTRIBUTE = 'date_note';+const DAYS = ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'];+const MONTHS = ['January','February','March','April','May','June','July','August','September','October','November','December'];+async function createNote(parentNoteId, noteTitle, noteText) {return (await notes.createNewNote(parentNoteId, {title: noteTitle,@@ -72,7 +76,11 @@ async function getMonthNoteId(dateTimeStr, rootNoteId) {monthNoteId = await getNoteStartingWith(yearNoteId, monthNumber);if (!monthNoteId) {- monthNoteId = await createNote(yearNoteId, monthNumber);+ const dateObj = utils.parseDate(dateTimeStr);++ const noteTitle = monthNumber + " - " + MONTHS[dateObj.getMonth()];++ monthNoteId = await createNote(yearNoteId, noteTitle);}await attributes.createAttribute(monthNoteId, MONTH_ATTRIBUTE, monthStr);@@ -97,7 +105,11 @@ async function getDateNoteId(dateTimeStr, rootNoteId = null) {dateNoteId = await getNoteStartingWith(monthNoteId, dayNumber);if (!dateNoteId) {- dateNoteId = await createNote(monthNoteId, dayNumber);+ const dateObj = utils.parseDate(dateTimeStr);++ const noteTitle = dayNumber + " - " + DAYS[dateObj.getDay()];++ dateNoteId = await createNote(monthNoteId, noteTitle);}await attributes.createAttribute(dateNoteId, DATE_ATTRIBUTE, dateStr);diff --git a/src/services/notes.js b/src/services/notes.jsindex c8e695dab4..efccf25605 100644--- a/src/services/notes.js+++ b/src/services/notes.js@@ -235,7 +235,7 @@ async function updateNote(noteId, newNote, dataKey, sourceId) {"SELECT noteRevisionId FROM note_revisions WHERE noteId = ? AND dateModifiedTo >= ?", [noteId, historyCutoff]);await sql.doInTransaction(async () => {- const msSinceDateCreated = now.getTime() - utils.parseDate(newNote.detail.dateCreated).getTime();+ const msSinceDateCreated = now.getTime() - utils.parseDateTime(newNote.detail.dateCreated).getTime();if (attributesMap.disable_versioning !== 'true'&& !existingnoteRevisionIddiff --git a/src/services/utils.js b/src/services/utils.jsindex 190dcd2c05..de73533acc 100644--- a/src/services/utils.js+++ b/src/services/utils.js@@ -47,7 +47,7 @@ function dateStr(date) {* @param str - needs to be in the ISO 8601 format "YYYY-MM-DDTHH:MM:SS.sssZ" format as outputted by dateStr().* also is assumed to be GMT time (as indicated by the "Z" at the end), *not* local time*/-function parseDate(str) {+function parseDateTime(str) {try {return new Date(Date.parse(str));}@@ -56,6 +56,12 @@ function parseDate(str) {}}+function parseDate(str) {+ const datePart = str.substr(0, 10);++ return parseDateTime(datePart + "T12:00:00.000Z");+}+function toBase64(plainText) {return Buffer.from(plainText).toString('base64');}@@ -117,6 +123,7 @@ module.exports = {nowDate,dateStr,parseDate,+ parseDateTime,newNoteId,newNoteTreeId,newnoteRevisionId,