Revised suffix formatting in getDate function

master
stweedo 2024-09-11 23:38:00 -05:00 committed by GitHub
parent bb92699e88
commit 624cf0f510
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 25 additions and 13 deletions

View File

@ -13,3 +13,4 @@
- [+] Fixed drag handler by adding E.stopEventPropagation() - [+] Fixed drag handler by adding E.stopEventPropagation()
- [+] General code optimization and cleanup - [+] General code optimization and cleanup
0.09: Revised event handler code 0.09: Revised event handler code
0.10: Revised suffix formatting in getDate function

View File

@ -208,12 +208,23 @@
// 7. String forming helper functions // 7. String forming helper functions
let getDate = function(short, shortMonth, disableSuffix) { let getDate = function(short, shortMonth, disableSuffix) {
const date = new Date(); const date = new Date();
const dayOfMonth = date.getDate(); const day = date.getDate();
const month = shortMonth ? locale.month(date, 1) : locale.month(date, 0); const month = shortMonth ? locale.month(date, 1) : locale.month(date, 0);
const year = date.getFullYear(); const year = date.getFullYear();
let suffix = ["st", "nd", "rd"][(dayOfMonth - 1) % 10] || "th";
let dayOfMonthStr = disableSuffix ? dayOfMonth : `${dayOfMonth}${suffix}`; const getSuffix = (day) => {
return `${month} ${dayOfMonthStr}${short ? '' : `, ${year}`}`; if (day >= 11 && day <= 13) return 'th';
const lastDigit = day % 10;
switch (lastDigit) {
case 1: return 'st';
case 2: return 'nd';
case 3: return 'rd';
default: return 'th';
}
};
const dayStr = disableSuffix ? day : `${day}${getSuffix(day)}`;
return `${month} ${dayStr}${short ? '' : `, ${year}`}`; // not including year for short version
}; };
let getDayOfWeek = function(date, short) { let getDayOfWeek = function(date, short) {

View File

@ -11,14 +11,14 @@
"xOffset": 3, "xOffset": 3,
"yOffset": 0, "yOffset": 0,
"boxPos": { "boxPos": {
"x": "0.494", "x": "0.5",
"y": "0.739" "y": "0.739"
} }
}, },
"dow": { "dow": {
"font": "6x8", "font": "6x8",
"fontSize": 3, "fontSize": 3,
"outline": 1, "outline": 2,
"color": "bgH", "color": "bgH",
"outlineColor": "fg", "outlineColor": "fg",
"border": "#f0f", "border": "#f0f",
@ -27,7 +27,7 @@
"xOffset": 2, "xOffset": 2,
"yOffset": 0, "yOffset": 0,
"boxPos": { "boxPos": {
"x": "0.421", "x": "0.5",
"y": "0.201" "y": "0.201"
}, },
"short": false "short": false
@ -35,7 +35,7 @@
"date": { "date": {
"font": "6x8", "font": "6x8",
"fontSize": 2, "fontSize": 2,
"outline": 1, "outline": 2,
"color": "bgH", "color": "bgH",
"outlineColor": "fg", "outlineColor": "fg",
"border": "#f0f", "border": "#f0f",
@ -44,7 +44,7 @@
"xOffset": 1, "xOffset": 1,
"yOffset": 0, "yOffset": 0,
"boxPos": { "boxPos": {
"x": "0.454", "x": "0.5",
"y": "0.074" "y": "0.074"
}, },
"shortMonth": false, "shortMonth": false,
@ -62,7 +62,7 @@
"xOffset": 2, "xOffset": 2,
"yOffset": 1, "yOffset": 1,
"boxPos": { "boxPos": {
"x": "0.494", "x": "0.5",
"y": "0.926" "y": "0.926"
}, },
"prefix": "Steps: " "prefix": "Steps: "
@ -79,7 +79,7 @@
"xOffset": 2, "xOffset": 2,
"yOffset": 2, "yOffset": 2,
"boxPos": { "boxPos": {
"x": "0.805", "x": "0.8",
"y": "0.427" "y": "0.427"
}, },
"suffix": "%" "suffix": "%"

View File

@ -1,7 +1,7 @@
{ {
"id": "boxclk", "id": "boxclk",
"name": "Box Clock", "name": "Box Clock",
"version": "0.09", "version": "0.10",
"description": "A customizable clock with configurable text boxes that can be positioned to show your favorite background", "description": "A customizable clock with configurable text boxes that can be positioned to show your favorite background",
"icon": "app.png", "icon": "app.png",
"dependencies" : { "clockbg":"module" }, "dependencies" : { "clockbg":"module" },