*: adding next and previous weeks
This commit is contained in:
parent
a5c2d158a2
commit
1a7945b5fe
2 changed files with 59 additions and 7 deletions
54
extension.js
54
extension.js
|
@ -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 () {
|
context.subscriptions.push(vscode.commands.registerTextEditorCommand('extension.nextNoteOpenCurrentWeek', function () {
|
||||||
try {
|
try {
|
||||||
|
@ -33,10 +42,17 @@ function activate(context) {
|
||||||
vscode.window.showErrorMessage("next-note: failed to make directory: "+basedir);
|
vscode.window.showErrorMessage("next-note: failed to make directory: "+basedir);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
openNote(basedir +"/"+ formatWeekFilename(currentWeek()));
|
||||||
|
}));
|
||||||
|
|
||||||
var notepath = basedir +"/"+ currentWeekFilename();
|
context.subscriptions.push(vscode.commands.registerTextEditorCommand('extension.nextNoteOpenNextWeek', function () {
|
||||||
|
try {
|
||||||
openNote(notepath);
|
var basedir = getBasedir();
|
||||||
|
} catch(e) {
|
||||||
|
vscode.window.showErrorMessage("next-note: failed to make directory: "+basedir);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
openNote(basedir +"/"+ formatWeekFilename(nextWeek()));
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
exports.activate = activate;
|
exports.activate = activate;
|
||||||
|
@ -110,10 +126,11 @@ function dateLine() {
|
||||||
/**
|
/**
|
||||||
* get the base file name of the current week
|
* 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")
|
* @returns {String} (i.e. "Tasks-20170219-20170225.md")
|
||||||
*/
|
*/
|
||||||
function currentWeekFilename() {
|
function formatWeekFilename(week) {
|
||||||
return "Tasks-"+currentWeek()+".md";
|
return "Tasks-"+week+".md";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -128,5 +145,30 @@ function currentWeek() {
|
||||||
d.setDate(beginDate.getDate()+6); // this is a week from that sunday
|
d.setDate(beginDate.getDate()+6); // this is a week from that sunday
|
||||||
|
|
||||||
return dateFormat(beginDate, "yyyymmdd")+"-"+dateFormat(d,"yyyymmdd");
|
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");
|
||||||
}
|
}
|
12
package.json
12
package.json
|
@ -16,15 +16,25 @@
|
||||||
],
|
],
|
||||||
"activationEvents": [
|
"activationEvents": [
|
||||||
"onCommand:extension.nextNoteInsertDate",
|
"onCommand:extension.nextNoteInsertDate",
|
||||||
"onCommand:extension.nextNoteOpenCurrentWeek"
|
"onCommand:extension.nextNoteOpenCurrentWeek",
|
||||||
|
"onCommand:extension.nextNoteOpenPreviousWeek",
|
||||||
|
"onCommand:extension.nextNoteOpenNextWeek"
|
||||||
],
|
],
|
||||||
"main": "./extension",
|
"main": "./extension",
|
||||||
"contributes": {
|
"contributes": {
|
||||||
"commands": [
|
"commands": [
|
||||||
|
{
|
||||||
|
"command": "extension.nextNoteOpenPreviousWeek",
|
||||||
|
"title": "NextNote: Open Current Week"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"command": "extension.nextNoteOpenCurrentWeek",
|
"command": "extension.nextNoteOpenCurrentWeek",
|
||||||
"title": "NextNote: Open Current Week"
|
"title": "NextNote: Open Current Week"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"command": "extension.nextNoteOpenNextWeek",
|
||||||
|
"title": "NextNote: Open Current Week"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"command": "extension.nextNoteInsertDate",
|
"command": "extension.nextNoteInsertDate",
|
||||||
"title": "NextNote: Date"
|
"title": "NextNote: Date"
|
||||||
|
|
Loading…
Reference in a new issue