mirror of
https://github.com/Xevion/glance.git
synced 2025-12-16 14:12:05 -06:00
Simplify clock zone diff text and add title for more details
This commit is contained in:
@@ -513,13 +513,23 @@ function zoneDiffText(diffInMinutes) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const sign = diffInMinutes < 0 ? "-" : "+";
|
const sign = diffInMinutes < 0 ? "-" : "+";
|
||||||
|
const signText = diffInMinutes < 0 ? "behind" : "ahead";
|
||||||
|
|
||||||
diffInMinutes = Math.abs(diffInMinutes);
|
diffInMinutes = Math.abs(diffInMinutes);
|
||||||
|
|
||||||
const hours = `${Math.floor(diffInMinutes / 60)}`.padStart(2, '0');
|
const hours = Math.floor(diffInMinutes / 60);
|
||||||
const minutes = `${diffInMinutes % 60}`.padStart(2, '0');
|
const minutes = diffInMinutes % 60;
|
||||||
|
const hourSuffix = hours == 1 ? "" : "s";
|
||||||
|
|
||||||
return `${sign}${hours}:${minutes}`;
|
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() {
|
function setupClocks() {
|
||||||
@@ -564,7 +574,9 @@ function setupClocks() {
|
|||||||
updateCallbacks.push((now) => {
|
updateCallbacks.push((now) => {
|
||||||
const { time, diffInMinutes } = timeInZone(now, timeZoneContainer.dataset.timeInZone);
|
const { time, diffInMinutes } = timeInZone(now, timeZoneContainer.dataset.timeInZone);
|
||||||
setZoneTime(time);
|
setZoneTime(time);
|
||||||
diffElement.textContent = zoneDiffText(diffInMinutes);
|
const { text, title } = zoneDiffText(diffInMinutes);
|
||||||
|
diffElement.textContent = text;
|
||||||
|
diffElement.title = title;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user