mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-30 18:05:55 +01:00 
			
		
		
		
	create months and days with associated english names, closes #37
This commit is contained in:
		| @@ -14,7 +14,7 @@ const wrap = require('express-promise-wrap').wrap; | |||||||
| router.post('/sync', wrap(async (req, res, next) => { | router.post('/sync', wrap(async (req, res, next) => { | ||||||
|     const timestampStr = req.body.timestamp; |     const timestampStr = req.body.timestamp; | ||||||
|  |  | ||||||
|     const timestamp = utils.parseDate(timestampStr); |     const timestamp = utils.parseDateTime(timestampStr); | ||||||
|  |  | ||||||
|     const now = new Date(); |     const now = new Date(); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -10,7 +10,7 @@ const sync_mutex = require('./sync_mutex'); | |||||||
|  |  | ||||||
| async function regularBackup() { | async function regularBackup() { | ||||||
|     const now = new Date(); |     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); |     console.log(lastBackupDate); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -3,12 +3,16 @@ | |||||||
| const sql = require('./sql'); | const sql = require('./sql'); | ||||||
| const notes = require('./notes'); | const notes = require('./notes'); | ||||||
| const attributes = require('./attributes'); | const attributes = require('./attributes'); | ||||||
|  | const utils = require('./utils'); | ||||||
|  |  | ||||||
| const CALENDAR_ROOT_ATTRIBUTE = 'calendar_root'; | const CALENDAR_ROOT_ATTRIBUTE = 'calendar_root'; | ||||||
| const YEAR_ATTRIBUTE = 'year_note'; | const YEAR_ATTRIBUTE = 'year_note'; | ||||||
| const MONTH_ATTRIBUTE = 'month_note'; | const MONTH_ATTRIBUTE = 'month_note'; | ||||||
| const DATE_ATTRIBUTE = 'date_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) { | async function createNote(parentNoteId, noteTitle, noteText) { | ||||||
|     return (await notes.createNewNote(parentNoteId, { |     return (await notes.createNewNote(parentNoteId, { | ||||||
|         title: noteTitle, |         title: noteTitle, | ||||||
| @@ -72,7 +76,11 @@ async function getMonthNoteId(dateTimeStr, rootNoteId) { | |||||||
|         monthNoteId = await getNoteStartingWith(yearNoteId, monthNumber); |         monthNoteId = await getNoteStartingWith(yearNoteId, monthNumber); | ||||||
|  |  | ||||||
|         if (!monthNoteId) { |         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); |         await attributes.createAttribute(monthNoteId, MONTH_ATTRIBUTE, monthStr); | ||||||
| @@ -97,7 +105,11 @@ async function getDateNoteId(dateTimeStr, rootNoteId = null) { | |||||||
|         dateNoteId = await getNoteStartingWith(monthNoteId, dayNumber); |         dateNoteId = await getNoteStartingWith(monthNoteId, dayNumber); | ||||||
|  |  | ||||||
|         if (!dateNoteId) { |         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); |         await attributes.createAttribute(dateNoteId, DATE_ATTRIBUTE, dateStr); | ||||||
|   | |||||||
| @@ -235,7 +235,7 @@ async function updateNote(noteId, newNote, dataKey, sourceId) { | |||||||
|         "SELECT noteRevisionId FROM note_revisions WHERE noteId = ? AND dateModifiedTo >= ?", [noteId, historyCutoff]); |         "SELECT noteRevisionId FROM note_revisions WHERE noteId = ? AND dateModifiedTo >= ?", [noteId, historyCutoff]); | ||||||
|  |  | ||||||
|     await sql.doInTransaction(async () => { |     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' |         if (attributesMap.disable_versioning !== 'true' | ||||||
|             && !existingnoteRevisionId |             && !existingnoteRevisionId | ||||||
|   | |||||||
| @@ -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(). |  * @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 |  *              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 { |     try { | ||||||
|         return new Date(Date.parse(str)); |         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) { | function toBase64(plainText) { | ||||||
|     return Buffer.from(plainText).toString('base64'); |     return Buffer.from(plainText).toString('base64'); | ||||||
| } | } | ||||||
| @@ -117,6 +123,7 @@ module.exports = { | |||||||
|     nowDate, |     nowDate, | ||||||
|     dateStr, |     dateStr, | ||||||
|     parseDate, |     parseDate, | ||||||
|  |     parseDateTime, | ||||||
|     newNoteId, |     newNoteId, | ||||||
|     newNoteTreeId, |     newNoteTreeId, | ||||||
|     newnoteRevisionId, |     newnoteRevisionId, | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user