-
Notifications
You must be signed in to change notification settings - Fork 0
/
date.ts
31 lines (25 loc) · 994 Bytes
/
date.ts
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
import { workspace } from 'vscode';
import { setSelectionString } from './utils';
export function theDate() {
let formatStr: string | undefined = workspace.getConfiguration().get('text-utils.theDate.format');
if (formatStr === undefined) {
console.error('no formatStr!');
return;
}
const myDate = new Date();
const year = myDate.getFullYear();
const month = myDate.getMonth() + 1;
const dayOfMonth = myDate.getDate();
let resultString = formatStr.split(':')[0];
if (resultString.indexOf('mm') === -1) {
resultString = resultString.replace('yyyy', year.toString());
resultString = resultString.replace('m', month.toString());
resultString = resultString.replace('d', dayOfMonth.toString());
}
else {
resultString = resultString.replace('yyyy', year.toString());
resultString = resultString.replace('mm', month.toString().padStart(2, '0'));
resultString = resultString.replace('dd', dayOfMonth.toString().padStart(2, '0'));
}
setSelectionString(resultString);
}