aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYann Herklotz <git@yannherklotz.com>2022-07-12 18:50:17 +0100
committerYann Herklotz <git@yannherklotz.com>2022-07-12 18:50:17 +0100
commit315cf43bb39096f02cd36cbcde4c949c912e3f52 (patch)
tree4428ae31166277c3314011d3c2f1ec15cc169741
parent2769fdcbe0e35c6b49375f7a1d360ad488ccc202 (diff)
downloaddotfiles-315cf43bb39096f02cd36cbcde4c949c912e3f52.tar.gz
dotfiles-315cf43bb39096f02cd36cbcde4c949c912e3f52.zip
Add code converting BST to current timezone
-rw-r--r--doom/config.org57
1 files changed, 54 insertions, 3 deletions
diff --git a/doom/config.org b/doom/config.org
index 0bccc57..21d52d7 100644
--- a/doom/config.org
+++ b/doom/config.org
@@ -465,10 +465,10 @@
(setq diary-mail-days 2)
(setq diary-abbreviated-year-flag nil)
- (add-hook 'diary-sort-entries #'diary-list-entries-hook)
-
(add-hook 'calendar-today-visible-hook #'calendar-mark-today)
- (add-hook 'diary-list-entries-hook 'diary-sort-entries t)
+ (add-hook 'diary-list-entries-hook #'diary-fix-timezone t)
+ (add-hook 'diary-list-entries-hook #'diary-sort-entries t)
+
(add-hook 'diary-list-entries-hook 'diary-include-other-diary-files)
(add-hook 'diary-mark-entries-hook 'diary-mark-included-diary-files)
@@ -503,6 +503,57 @@
(not (calendar-check-holidays date)))
entry)))
+ (defun diary-fix-timezone ()
+ (let ((eqtimezone (string=
+ (replace-regexp-in-string
+ "\n" ""
+ (shell-command-to-string "date +%z"))
+ (replace-regexp-in-string
+ "\n" ""
+ (shell-command-to-string "TZ=\"Europe/London\" date +%z")))))
+ (setq diary-entries-list
+ (mapcar (lambda (entry)
+ (pcase entry
+ (`(,date ,time ,sdate . ,rest)
+ (let ((dt (diary-entry-time time))
+ (string-date (apply (lambda (a b c) (format "%d-%d-%d" c a b)) date)))
+ (if (or eqtimezone (= dt diary-unknown-time))
+ entry
+ (let* ((tr (org-tz-conv (concat string-date " " (number-to-string dt)) "Europe/London" "from"))
+ (split (split-string tr "[- ]"))
+ (year (car split))
+ (month (cadr split))
+ (day (caddr split))
+ (hour (cadddr split)))
+ (cons (mapcar #'string-to-number (list month day year))
+ (cons (concat hour (replace-regexp-in-string "^[^ ]+" "" time))
+ (cons (format "%s-%s-%s" year month day) rest)))))))))
+ diary-entries-list))))
+
+ (defun org-tz-conv (stamp tz way)
+ "Convert a STAMP to or from TZ depending on WAY.
+
+This function uses the date command line tool to do it."
+ (let* ((current-tz-offset (replace-regexp-in-string
+ "\n" ""
+ (shell-command-to-string "date +%z")))
+ (stamp1 (concat (replace-regexp-in-string "[<>]" "" stamp)))
+ (date-cmd-p0 "TZ=%s date -d \"%s\"")
+ (date-cmd-p1 "date --date=\"TZ=\\\"%s\\\" %s\"")
+ (date-cmd-p2 " +\"%F %H:%M\"")
+ (date-cmd-from (concat (format date-cmd-p1 tz stamp1) date-cmd-p2))
+ (date-cmd-to (concat (format date-cmd-p0 tz
+ (concat stamp1 " " current-tz-offset))
+ date-cmd-p2))
+
+ (shell-result-from (shell-command-to-string date-cmd-from))
+ (shell-result-to (shell-command-to-string date-cmd-to))
+
+ (result-from (replace-regexp-in-string "\n" "" shell-result-from))
+ (result-to (replace-regexp-in-string "\n" "" shell-result-to)))
+ (cond ((string-equal way "from") result-from)
+ ((string-equal way "to") result-to))))
+
(require 'ox-extra)
(ox-extras-activate '(ignore-headlines))