Skip to content

Commit 1297e52

Browse files
authored
Merge pull request #262 from LockeBirdsey/handleShortDays
add 3 character days to dateformatter
2 parents 76f3191 + 3a2ebd1 commit 1297e52

File tree

4 files changed

+14
-4
lines changed

4 files changed

+14
-4
lines changed

journal-entry/info.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"identifier": "journal-entry",
44
"script": "journal-entry.qml",
55
"resources": ["calendar-window.qml"],
6-
"version": "1.7.0",
6+
"version": "1.8.0",
77
"minAppVersion": "20.4.16",
88
"authors": ["@pbek", "@sanderboom", "@kantrol", "@nico2sh"],
99
"description": "This script creates menu items and buttons to create or jump to the current date's (or tomorrow's date) journal entry. And formats the title based on a date placeholder. It also allows to open a calendar to choose the date."

journal-entry/journal-entry.qml

+5-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import com.qownnotes.noteapi 1.0
77
*/
88
QtObject {
99
id: journalEntry
10+
readonly property variant _SHORT_DAYS_EN: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]
11+
1012

1113
property string defaultFolder
1214
property string defaultTags
@@ -31,7 +33,7 @@ QtObject {
3133
{
3234
"identifier": "noteTitleFormat",
3335
"name": "Title Format",
34-
"description": "How the journal title should be formatted, use date format placeholders inside curly braces. YYYY: year, MM: month, DD: day, WW: week, HH: hours, mm: minutes, ss: seconds. For example \"Journal {YYYYMMDD}\" will return \"Journal 20240928\". You can have monthly or weekly journals instead of daily by formatting the date to the week or monthly level, or one journal file per entry by including the hour, minutes and seconds.",
36+
"description": "How the journal title should be formatted, use date format placeholders inside curly braces. YYYY: year, MM: month, DD: day, WW: week, HH: hours, mm: minutes, ss: seconds, ddd: short day of the week e.g. 'Mon'. For example \"Journal {YYYYMMDD}\" will return \"Journal 20240928\". You can have monthly or weekly journals instead of daily by formatting the date to the week or monthly level, or one journal file per entry by including the hour, minutes and seconds.",
3537
"type": "string",
3638
"default": "Journal {YYYYMMDD}"
3739
},
@@ -137,6 +139,7 @@ QtObject {
137139
}
138140
function formatDate(date, format) {
139141
let day = date.getDate();
142+
let dayOfWeek = _SHORT_DAYS_EN[date.getDay()];
140143
let month = date.getMonth() + 1; //getMonth() returns 0-11 so we must add 1
141144
let week = getWeekNumber(date);
142145
let year = date.getFullYear();
@@ -156,6 +159,7 @@ QtObject {
156159
format = format.replace('WW', week);
157160
format = format.replace('MM', month);
158161
format = format.replace('DD', day);
162+
format = format.replace('ddd', dayOfWeek);
159163
format = format.replace('YYYY', year);
160164
format = format.replace('HH', hours);
161165
format = format.replace('mm', minutes);

quick-commands/info.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"script": "quick-commands.qml",
55
"authors": ["@LockeBirdsey"],
66
"platforms": ["linux", "macos", "windows"],
7-
"version": "0.0.1",
7+
"version": "0.1.0",
88
"minAppVersion": "25.4.1",
99
"description": "Short commands to help with repetive and/or annoying things to write frequently such as timestamps.\n\nEach command starts with a backslash (\\) and a single word for the command. Select the autocomplete option you desire and the command text will be replace.\n\nDefault commands are: today, tomorrow, yesterday, now, week.\n\nCustom commands can also be specified but are limited to simple text replacement."
1010
}

quick-commands/quick-commands.qml

+7-1
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,13 @@ Script {
1414
readonly property int _MILLI_DAY: 86400000
1515
readonly property string _WEEKWWYYYY: "wWW-YYYY"
1616
readonly property string _WWYYYY: "WW-YYYY"
17-
// DateFormats
1817
readonly property string _YYYYMMDD: "YYYY-MM-DD"
18+
readonly property string _DDDDMY: "ddd (DD-MM-YYYY)"
19+
readonly property variant _SHORT_DAYS_EN: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]
20+
1921
property var commands
2022
property string customCommands
23+
2124
property variant settingsVariables: [
2225
{
2326
"identifier": "customCommands",
@@ -52,13 +55,15 @@ Script {
5255
timeList.push(formatDate(date, _DDMM));
5356
timeList.push(formatDate(date, _YYYYMMDD));
5457
timeList.push(formatDate(date, _DDMMYYYY));
58+
timeList.push(formatDate(date, _DDDDMY));
5559
timeList.push(formatDate(date, _FULL));
5660
return timeList;
5761
}
5862

5963
// Taken from https://github.com/qownnotes/scripts/blob/master/journal-entry/journal-entry.qml
6064
function formatDate(date, format) {
6165
let day = date.getDate();
66+
let dayOfWeek = _SHORT_DAYS_EN[date.getDay()];
6267
let month = date.getMonth() + 1; //getMonth() returns 0-11 so we must add 1
6368
let week = getWeekNumber(date);
6469
let year = date.getFullYear();
@@ -78,6 +83,7 @@ Script {
7883
format = format.replace('WW', week);
7984
format = format.replace('MM', month);
8085
format = format.replace('DD', day);
86+
format = format.replace('ddd', dayOfWeek);
8187
format = format.replace('YYYY', year);
8288
format = format.replace('HH', hours);
8389
format = format.replace('mm', minutes);

0 commit comments

Comments
 (0)