-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextension.js
60 lines (47 loc) · 1.93 KB
/
extension.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
const vscode = require('vscode');
function addZero(i) { return i < 10 ? "0"+i.toString() : i; }
function activate(context) {
const config = vscode.workspace.getConfiguration('timeinserter');
let disposable1 = vscode.commands.registerCommand('timeinserter.insertTime', function () {
let editor = vscode.window.activeTextEditor;
if (!editor) {
return;
}
var date = new Date();
var hour = date.getHours();
var min = date.getMinutes();
var sec = date.getSeconds();
var formatStr = '';
if(!config.format) {
formatStr = hour>12 ? ' pm' : ' am';
hour = hour>12 ? hour-12 : hour;
}
var dateText = `${config.pre}${addZero(hour).toString()}:${addZero(min).toString()}${formatStr}${config.post}`;
const position = editor.selection.active;
// vscode.window.showInformationMessage(dateText);
// vscode.window.showInformationMessage(JSON.stringify(position, null, 4));
editor.edit(function (editor) {
editor.insert(position, dateText);
});
});
let disposable2 = vscode.commands.registerCommand('timeinserter.insertDate', function () {
let editor = vscode.window.activeTextEditor;
if (!editor) {
return;
}
var date = new Date();
var day = date.getDate();
var month = date.getMonth()+1;
var year = date.getFullYear();
var dateText = `${config.pre}${addZero(day).toString()}${config.dateSeparator}${addZero(month).toString()}${config.dateSeparator}${year.toString()}${config.post}`;
const position = editor.selection.active;
editor.edit(function (editor) {
editor.insert(position, dateText);
});
});
context.subscriptions.push([disposable1, disposable2]);
}
exports.activate = activate;
function deactivate() {
}
exports.deactivate = deactivate;