Skip to content

Commit

Permalink
support 12-hour with 'AM/PM' in note template
Browse files Browse the repository at this point in the history
  • Loading branch information
leenzhu committed Oct 7, 2023
1 parent ab271a3 commit c2b9251
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "joplin-plugin-journal",
"version": "1.1.1",
"version": "1.1.2",
"scripts": {
"dist": "export NODE_OPTIONS=--openssl-legacy-provider && webpack --joplin-plugin-config buildMain && webpack --joplin-plugin-config buildExtraScripts && webpack --joplin-plugin-config createArchive",
"prepare": "export NODE_OPTIONS=--openssl-legacy-provider && npm run dist",
Expand Down
21 changes: 18 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,20 @@ async function makeNoteName(d) {
}

console.log(`Jouranl tmpl: ${noteTmpl}, monthStyle:${monthStyle}, dayStyle:${dayStyle}, weekdayStyle:${weekdayStyle}`);
let data = { year: '', month: '', monthName: '', day: '', hour: '', min: '', sec: '', weekday: '', weekdayName: '', weekNum:'' };
let data = {
year: '',
month: '',
monthName: '',
day: '',
hour: '',
min: '',
sec: '',
weekday: '',
weekdayName: '',
weekNum:'',
ampm:'',
hour12:'',
};
data.year = '' + year; // convert number to string
switch (monthStyle) {
case 'pad_num':
Expand Down Expand Up @@ -123,7 +136,9 @@ async function makeNoteName(d) {
data.hour = padding(hour);
data.min = padding(min);
data.sec = padding(sec);

data.ampm = hour >= 12 ? "PM" : "AM";
const hour12 = hour % 12
data.hour12 = padding(hour12 ? hour12 : 12)
console.log(`Journal tmpl data: `, data);
const noteName = tplEngin(noteTmpl, data);

Expand Down Expand Up @@ -227,7 +242,7 @@ joplin.plugins.register({
section: 'Journal',
public: true,
label: 'Note Name Template',
description: `There are several variables: {{year}}, {{month}}, {{monthName}}, {{day}}, {{hour}}, {{min}}, {{weekday}}, {{weekdayName}}, {{weekNum}}, which will expand into the actual value when opening or creating notes. The '/' character will create a hierarchical folder. The default vaule is: '${defaultNoteName}'.`
description: `There are several variables: {{year}}, {{month}}, {{monthName}}, {{day}}, {{hour}}, {{hour12}}, {{ampm}}, {{min}}, {{weekday}}, {{weekdayName}}, {{weekNum}}, which will expand into the actual value when opening or creating notes. The '/' character will create a hierarchical folder. The default vaule is: '${defaultNoteName}'.`
},

'MonthStyle': {
Expand Down
2 changes: 1 addition & 1 deletion src/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"manifest_version": 1,
"id": "com.leenzhu.journal",
"app_min_version": "2.7",
"version": "1.1.1",
"version": "1.1.2",
"name": "Journal",
"description": "A simple journal. Create or open a note for today, or any selected date.",
"author": "Leen Zhu",
Expand Down

0 comments on commit c2b9251

Please sign in to comment.