Skip to content

Commit b5c190f

Browse files
committed
Added reverse timezone order setting
1 parent 08eed63 commit b5c190f

File tree

5 files changed

+60
-15
lines changed

5 files changed

+60
-15
lines changed

main.ts

Lines changed: 48 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,19 +68,27 @@ class ClockView extends ItemView {
6868
return "clock";
6969
}
7070

71-
// Sort the timezone pairs based on the difference from the current offset
7271
private sortTimeZones(): TimezonePair[] {
7372
const currentOffset = DateTime.local().offset;
7473

75-
return this.plugin.settings.timeZonePairs.slice().sort((a, b) => {
76-
const offsetA = parseFloat(a.offset);
77-
const offsetB = parseFloat(b.offset);
74+
let sortedTimeZones = this.plugin.settings.timeZonePairs
75+
.slice()
76+
.sort((a, b) => {
77+
const offsetA = parseFloat(a.offset);
78+
const offsetB = parseFloat(b.offset);
7879

79-
const diffA = Math.abs(currentOffset - offsetA);
80-
const diffB = Math.abs(currentOffset - offsetB);
80+
const diffA = Math.abs(currentOffset - offsetA);
81+
const diffB = Math.abs(currentOffset - offsetB);
8182

82-
return diffB - diffA;
83-
});
83+
return diffB - diffA;
84+
});
85+
86+
// If reverseTimezoneOrder is false, reverse the sorted array
87+
if (!this.plugin.settings.reverseTimezoneOrder) {
88+
sortedTimeZones = sortedTimeZones.reverse();
89+
}
90+
91+
return sortedTimeZones;
8492
}
8593

8694
// Display the time, date, and timezone
@@ -241,6 +249,7 @@ interface ClockSettings {
241249
weekStart: "sunday" | "monday";
242250
fiscalYearStart: number;
243251
showWeekAndQuarter: boolean;
252+
reverseTimezoneOrder: boolean;
244253
}
245254

246255
// Default plugin settings
@@ -259,6 +268,7 @@ const DEFAULT_SETTINGS: ClockSettings = {
259268
weekStart: "sunday",
260269
fiscalYearStart: 1,
261270
showWeekAndQuarter: true,
271+
reverseTimezoneOrder: false,
262272
};
263273

264274
// Define the ClockPlugin class that extends Plugin
@@ -651,12 +661,37 @@ class ClockSettingTab extends PluginSettingTab {
651661
timezonePairsSetting.settingEl.style.display = value
652662
? ""
653663
: "none";
664+
// Show or hide the Reverse Timezone Order setting based on the show timezones toggle value
665+
reverseTimezoneOrderSetting.settingEl.style.display =
666+
value ? "" : "none";
654667
});
655668
});
656669

657670
// Style the settings
658671
showTimezonesSetting.settingEl.classList.add("show-timezones-settings");
659672

673+
const reverseTimezoneOrderSetting = new Setting(containerEl)
674+
.setName("Reverse Timezone Order")
675+
.setDesc("Reverse the order of displayed timezones.")
676+
.addToggle((toggle) => {
677+
toggle
678+
.setValue(this.plugin.settings.reverseTimezoneOrder)
679+
.onChange(async (value) => {
680+
this.plugin.settings.reverseTimezoneOrder = value;
681+
await this.plugin.saveSettings();
682+
683+
const clockView = this.app.workspace
684+
.getLeavesOfType("tokei")
685+
.find((leaf) => leaf.view instanceof ClockView);
686+
if (clockView) {
687+
// Update the clock immediately
688+
(clockView.view as ClockView).displayTime();
689+
}
690+
});
691+
});
692+
693+
reverseTimezoneOrderSetting.settingEl.classList.add("reverse-order-setting");
694+
660695
// Timezone Format Setting
661696
const timezoneFormatSetting = new Setting(containerEl)
662697
.setName("Timezone Format")
@@ -892,6 +927,11 @@ class ClockSettingTab extends PluginSettingTab {
892927
.showDate
893928
? ""
894929
: "none";
930+
931+
reverseTimezoneOrderSetting.settingEl.style.display = this.plugin
932+
.settings.showTimeZone
933+
? ""
934+
: "none";
895935
timeFormatInput.settingEl.style.display = this.plugin.settings.showDate
896936
? ""
897937
: "none";

manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"id": "tokei",
33
"name": "Tokei",
4-
"version": "0.6.5",
4+
"version": "0.7.0",
55
"minAppVersion": "0.16.3",
66
"description": "A simple clock.",
77
"author": "HiroMike",

package-lock.json

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "Tokei",
3-
"version": "0.6.5",
3+
"version": "0.7.0",
44
"description": "A simple clock.",
55
"main": "main.js",
66
"scripts": {

styles.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,11 @@ settings:
271271
border-bottom: none;
272272
}
273273

274+
.reverse-order-setting {
275+
border-top: none;
276+
margin-left: 20px;
277+
}
278+
274279
.timezone-format-settings {
275280
border-top: none;
276281
margin-left: 20px;

0 commit comments

Comments
 (0)