3030; ; time-zone to a list of favourite time-zones.
3131; ;
3232; ; A list of favourite time zones could be set using like following
33- ; ; (setq tzc-favourite-time-zones '("Asia/Kolkata" "America/New_York" "Europe/Berlin"))
33+ ; ; (setq tzc-favourite-time-zones-alist '(( "Asia/Kolkata" "Kolkata") (" America/New_York" "New York") (" Europe/Berlin" "Berlin") ))
3434
3535; ;; Code:
3636(require 'timezone )
3737
38- (defcustom tzc-favourite-time-zones '(" UTC+0000"
39- " Asia/Kolkata"
40- " America/New_York"
41- " UK/London"
42- " Europe/Berlin"
43- " Asia/Shanghai"
44- " Asia/Tokyo" )
45- " List of favourite time zones."
46- :type 'list
38+
39+ (defcustom tzc-favourite-time-zones-alist '((" UTC+0000" " UTC" )
40+ (" Asia/Kolkata" " Kolkata" )
41+ (" America/New_York" " New York" )
42+ (" UK/London" " London" )
43+ (" Europe/Berlin" " Berlin" )
44+ (" Asia/Shanghai" " Shanghai" )
45+ (" Asia/Tokyo" " Tokyo" ))
46+ " Alist for favourite time zones containing timezone and label."
47+ :type '(repeat (list string string))
4748 :group 'tzc )
4849
50+ (defun tzc--favourite-time-zones ()
51+ " Get the list of favourite time zones."
52+ (mapcar #'car tzc-favourite-time-zones-alist))
53+
54+ (defun tzc--get-time-zone-label (time-zone )
55+ " Get the label for the TIME-ZONE."
56+ (if (member time-zone (tzc--favourite-time-zones))
57+ (nth 1 (assoc time-zone tzc-favourite-time-zones-alist))
58+ time-zone))
59+
4960(defcustom tzc-main-dir (cond ((string-equal system-type " darwin" ) " /usr/share/zoneinfo.default/" )
5061 ((string-equal system-type " gnu/linux" ) " /usr/share/zoneinfo/" ))
5162 " Main directory to look for the zoneinfo data on your system"
6475 (setq zones (append zones (mapcar (lambda (zone ) (concat area " /" zone)) (directory-files (concat tzc-main-dir area) nil directory-files-no-dot-files-regexp)))))
6576 zones))
6677
67- (defcustom tzc-time-zones (delete-dups (append tzc-favourite-time-zones (tzc--get-time-zones)))
78+ (defcustom tzc-time-zones (delete-dups (append ( tzc-- favourite-time-zones) (tzc--get-time-zones)))
6879 " List of time zones."
6980 :type 'list
7081 :group 'tzc )
@@ -145,7 +156,7 @@ erroneous calculation. Please use correct format for time!"))
145156 (to-day-string))
146157 (unless (string-equal day " +0d" )
147158 (setq to-day-string (format " %s " day)))
148- (concat to-time-string to-day-string " " to-zone )))
159+ (concat to-time-string to-day-string)))
149160
150161(defun tzc--time-list (time-zone )
151162 " A list of times to display for completion based on TIME-ZONE."
@@ -164,36 +175,35 @@ erroneous calculation. Please use correct format for time!"))
164175 (to-zone (completing-read (format " Convert time from %s to: " from-zone) tzc-time-zones))
165176 (time-string (completing-read (format " Enter time to covert from %s to %s : " from-zone to-zone) (tzc--time-list from-zone))))
166177 (list time-string from-zone to-zone)))
167- (message (concat time-string " " from-zone " = " (tzc--get-converted-time-string time-string from-zone to-zone))))
178+ (message (concat time-string " " (tzc--get-time-zone-label from-zone) " = " (tzc--get-converted-time-string time-string from-zone to-zone) " " (tzc--get-time-zone-label to-zone))))
168179
169180(defun tzc-convert-current-time (to-zone )
170181 " Convert current local time to TO-ZONE."
171182 (interactive (list (completing-read " Enter To Zone: " tzc-time-zones)))
172183 (let ((time-now (format-time-string " %H:%M" )))
173- (message (concat " Local Time " time-now " = " (tzc--get-converted-time-string time-now nil to-zone)))))
184+ (message (concat " Local Time " time-now " = " (tzc--get-converted-time-string time-now nil to-zone) " " (tzc--get-time-zone-label to-zone) ))))
174185
175186(defun tzc-convert-time-to-favourite-time-zones (time-string from-zone )
176- " Convert time in TIME-STRING from FROM-ZONE to `tzc-favourite-time-zones`."
187+ " Convert time in TIME-STRING from FROM-ZONE to `( tzc-- favourite-time-zones) `."
177188 (interactive
178189 (let* ((from-zone (completing-read " Enter From Zone: " tzc-time-zones))
179190 (time-string (completing-read " Enter time to covert: " (tzc--time-list from-zone))))
180191 (list time-string from-zone)))
181192 (with-current-buffer (generate-new-buffer " *tzc-times*" )
182- (insert time-string " " from-zone)
183- (dolist (to-zone tzc-favourite-time-zones)
193+ (insert time-string " " (tzc--get-time-zone-label from-zone) )
194+ (dolist (to-zone ( tzc-- favourite-time-zones) )
184195 (unless (string-equal to-zone from-zone)
185- (insert " = " (tzc--get-converted-time-string time-string from-zone to-zone) " \n " )))
196+ (insert " = " (tzc--get-converted-time-string time-string from-zone to-zone) " " (tzc--get-time-zone-label to-zone) " \n " )))
186197 (align-regexp (point-min ) (point-max ) " \\ (\\ s-*\\ )=" )
187198 (switch-to-buffer-other-window " *tzc-times*" )))
188199
189200(defun tzc-convert-current-time-to-favourite-time-zones ()
190- " Convert current local time to `tzc-favourite-time-zones`."
201+ " Convert current local time to `( tzc-- favourite-time-zones) `."
191202 (interactive )
192203 (with-current-buffer (generate-new-buffer " *tzc-times*" )
193- (insert " Local Time " (format-time-string " %H:%M" ))
194- (dolist (to-zone tzc-favourite-time-zones)
204+ (dolist (to-zone (tzc--favourite-time-zones))
195205 (unless (string-equal to-zone nil )
196- (insert " = " (tzc--get-converted-time-string (format-time-string " %H:%M" ) nil to-zone) " \n " )))
206+ (insert (tzc--get-converted-time-string (format-time-string " %H:%M" ) nil to-zone) " " (tzc--get-time-zone-label to-zone) " \n " )))
197207 (align-regexp (point-min ) (point-max ) " \\ (\\ s-*\\ )=" )
198208 (switch-to-buffer-other-window " *tzc-times*" )))
199209
0 commit comments