30
30
; ; time-zone to a list of favourite time-zones.
31
31
; ;
32
32
; ; 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") ))
34
34
35
35
; ;; Code:
36
36
(require 'timezone )
37
37
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))
47
48
:group 'tzc )
48
49
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
+
49
60
(defcustom tzc-main-dir (cond ((string-equal system-type " darwin" ) " /usr/share/zoneinfo.default/" )
50
61
((string-equal system-type " gnu/linux" ) " /usr/share/zoneinfo/" ))
51
62
" Main directory to look for the zoneinfo data on your system"
64
75
(setq zones (append zones (mapcar (lambda (zone ) (concat area " /" zone)) (directory-files (concat tzc-main-dir area) nil directory-files-no-dot-files-regexp)))))
65
76
zones))
66
77
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)))
68
79
" List of time zones."
69
80
:type 'list
70
81
:group 'tzc )
@@ -145,7 +156,7 @@ erroneous calculation. Please use correct format for time!"))
145
156
(to-day-string))
146
157
(unless (string-equal day " +0d" )
147
158
(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)))
149
160
150
161
(defun tzc--time-list (time-zone )
151
162
" A list of times to display for completion based on TIME-ZONE."
@@ -164,36 +175,35 @@ erroneous calculation. Please use correct format for time!"))
164
175
(to-zone (completing-read (format " Convert time from %s to: " from-zone) tzc-time-zones))
165
176
(time-string (completing-read (format " Enter time to covert from %s to %s : " from-zone to-zone) (tzc--time-list from-zone))))
166
177
(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))))
168
179
169
180
(defun tzc-convert-current-time (to-zone )
170
181
" Convert current local time to TO-ZONE."
171
182
(interactive (list (completing-read " Enter To Zone: " tzc-time-zones)))
172
183
(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) ))))
174
185
175
186
(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) `."
177
188
(interactive
178
189
(let* ((from-zone (completing-read " Enter From Zone: " tzc-time-zones))
179
190
(time-string (completing-read " Enter time to covert: " (tzc--time-list from-zone))))
180
191
(list time-string from-zone)))
181
192
(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) )
184
195
(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 " )))
186
197
(align-regexp (point-min ) (point-max ) " \\ (\\ s-*\\ )=" )
187
198
(switch-to-buffer-other-window " *tzc-times*" )))
188
199
189
200
(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) `."
191
202
(interactive )
192
203
(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))
195
205
(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 " )))
197
207
(align-regexp (point-min ) (point-max ) " \\ (\\ s-*\\ )=" )
198
208
(switch-to-buffer-other-window " *tzc-times*" )))
199
209
0 commit comments