create months and days with associated english names, closes #37

This commit is contained in:
azivner 2018-02-10 13:53:35 -05:00
parent b3038487f8
commit e970564036
5 changed files with 25 additions and 6 deletions

View file

@ -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();

View file

@ -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);

View file

@ -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);

View file

@ -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

View file

@ -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,