mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
create months and days with associated english names, closes #37
This commit is contained in:
parent
b3038487f8
commit
e970564036
@ -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();
|
||||
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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'
|
||||
&& !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().
|
||||
* 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,
|
||||
|
Loading…
x
Reference in New Issue
Block a user