Skip to content

A self-hosted dashboard that puts all your feeds in one place

Simplify clock zone diff text and add title for more details

Svilen Markovde2db71e54b1
diff --git a/internal/assets/static/js/main.js b/internal/assets/static/js/main.js
index 13c9e40..0c2a4d4 100644
--- a/internal/assets/static/js/main.js
+++ b/internal/assets/static/js/main.js
@@ -513,13 +513,23 @@ function zoneDiffText(diffInMinutes) {
}
const sign = diffInMinutes < 0 ? "-" : "+";
+ const signText = diffInMinutes < 0 ? "behind" : "ahead";
diffInMinutes = Math.abs(diffInMinutes);
-
- const hours = `${Math.floor(diffInMinutes / 60)}`.padStart(2, '0');
- const minutes = `${diffInMinutes % 60}`.padStart(2, '0');
- return `${sign}${hours}:${minutes}`;
+ const hours = Math.floor(diffInMinutes / 60);
+ const minutes = diffInMinutes % 60;
+ const hourSuffix = hours == 1 ? "" : "s";
+
+ if (minutes == 0) {
+ return { text: `${sign}${hours}h`, title: `${hours} hour${hourSuffix} ${signText}` };
+ }
+
+ if (hours == 0) {
+ return { text: `${sign}${minutes}m`, title: `${minutes} minutes ${signText}` };
+ }
+
+ return { text: `${sign}${hours}h~`, title: `${hours} hour${hourSuffix} and ${minutes} minutes ${signText}` };
}
function setupClocks() {
@@ -564,7 +574,9 @@ function setupClocks() {
updateCallbacks.push((now) => {
const { time, diffInMinutes } = timeInZone(now, timeZoneContainer.dataset.timeInZone);
setZoneTime(time);
- diffElement.textContent = zoneDiffText(diffInMinutes);
+ const { text, title } = zoneDiffText(diffInMinutes);
+ diffElement.textContent = text;
+ diffElement.title = title;
});
}
}