@@ -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" ;
0 commit comments