*: adding next and previous weeks

This commit is contained in:
Vincent Batts 2017-02-20 13:57:53 -05:00
parent a5c2d158a2
commit 1a7945b5fe
2 changed files with 59 additions and 7 deletions

View file

@ -25,6 +25,15 @@ function activate(context) {
});
}));
context.subscriptions.push(vscode.commands.registerTextEditorCommand('extension.nextNoteOpenPreviousWeek', function () {
try {
var basedir = getBasedir();
} catch(e) {
vscode.window.showErrorMessage("next-note: failed to make directory: "+basedir);
return;
}
openNote(basedir +"/"+ formatWeekFilename(previousWeek()));
}));
context.subscriptions.push(vscode.commands.registerTextEditorCommand('extension.nextNoteOpenCurrentWeek', function () {
try {
@ -33,10 +42,17 @@ function activate(context) {
vscode.window.showErrorMessage("next-note: failed to make directory: "+basedir);
return;
}
openNote(basedir +"/"+ formatWeekFilename(currentWeek()));
}));
var notepath = basedir +"/"+ currentWeekFilename();
openNote(notepath);
context.subscriptions.push(vscode.commands.registerTextEditorCommand('extension.nextNoteOpenNextWeek', function () {
try {
var basedir = getBasedir();
} catch(e) {
vscode.window.showErrorMessage("next-note: failed to make directory: "+basedir);
return;
}
openNote(basedir +"/"+ formatWeekFilename(nextWeek()));
}));
}
exports.activate = activate;
@ -110,10 +126,11 @@ function dateLine() {
/**
* get the base file name of the current week
*
* @param {String} output of a function like `currentWeek()`
* @returns {String} (i.e. "Tasks-20170219-20170225.md")
*/
function currentWeekFilename() {
return "Tasks-"+currentWeek()+".md";
function formatWeekFilename(week) {
return "Tasks-"+week+".md";
}
/**
@ -128,5 +145,30 @@ function currentWeek() {
d.setDate(beginDate.getDate()+6); // this is a week from that sunday
return dateFormat(beginDate, "yyyymmdd")+"-"+dateFormat(d,"yyyymmdd");
//return String(beginDate.getFullYear())+String(beginDate.getMonth())+String(beginDate.getDate()) +"-"+ String(d.getFullYear())+String(d.getMonth())+String(d.getDate());
}
/**
* the string of the previous week's date, sunday-saturday
*
* @return {String} (i.e. "20170219-20170225")
*/
function previousWeek() {
var d = new Date();
var beginDate = new Date();
beginDate.setDate(d.getDate()-d.getDay()-7); // This will be sunday of current previous week
d.setDate(beginDate.getDate()+6); // this is a week from that sunday
return dateFormat(beginDate, "yyyymmdd")+"-"+dateFormat(d,"yyyymmdd");
}
/**
* the string of the next week's date, sunday-saturday
*
* @return {String} (i.e. "20170219-20170225")
*/
function nextWeek() {
var d = new Date();
var beginDate = new Date();
beginDate.setDate(d.getDate()-d.getDay()+7); // This will be sunday of current next week
d.setDate(beginDate.getDate()+6); // this is a week from that sunday
return dateFormat(beginDate, "yyyymmdd")+"-"+dateFormat(d,"yyyymmdd");
}

View file

@ -16,15 +16,25 @@
],
"activationEvents": [
"onCommand:extension.nextNoteInsertDate",
"onCommand:extension.nextNoteOpenCurrentWeek"
"onCommand:extension.nextNoteOpenCurrentWeek",
"onCommand:extension.nextNoteOpenPreviousWeek",
"onCommand:extension.nextNoteOpenNextWeek"
],
"main": "./extension",
"contributes": {
"commands": [
{
"command": "extension.nextNoteOpenPreviousWeek",
"title": "NextNote: Open Current Week"
},
{
"command": "extension.nextNoteOpenCurrentWeek",
"title": "NextNote: Open Current Week"
},
{
"command": "extension.nextNoteOpenNextWeek",
"title": "NextNote: Open Current Week"
},
{
"command": "extension.nextNoteInsertDate",
"title": "NextNote: Date"