feat(dottime.el): Add arbitrary offsets & prefixes to dottime-format
This gives users from Elisp slightly more flexibility about the display of dottime.
This commit is contained in:
parent
5fd7de921b
commit
29e71053be
1 changed files with 15 additions and 9 deletions
|
@ -19,15 +19,16 @@
|
||||||
(require 'cl-lib)
|
(require 'cl-lib)
|
||||||
(require 'time)
|
(require 'time)
|
||||||
|
|
||||||
(defun dottime--format-string ()
|
(defun dottime--format-string (&optional offset prefix)
|
||||||
"Creates the dottime format string for `format-time-string'
|
"Creates the dottime format string for `format-time-string'
|
||||||
based on the local timezone."
|
based on the local timezone."
|
||||||
|
|
||||||
(let* ((offset-sec (car (current-time-zone)))
|
(let* ((offset-sec (or offset (car (current-time-zone))))
|
||||||
(offset-hours (/ offset-sec 60 60)))
|
(offset-hours (/ offset-sec 60 60))
|
||||||
|
(base (concat prefix "%m-%dT%H·%M")))
|
||||||
(if (/= offset-hours 0)
|
(if (/= offset-hours 0)
|
||||||
(concat "%m-%dT%H·%M" (format "%0+3d" offset-hours))
|
(concat base (format "%0+3d" offset-hours))
|
||||||
"%m-%dT%H·%M")))
|
base)))
|
||||||
|
|
||||||
(defun dottime--display-time-update-advice (orig)
|
(defun dottime--display-time-update-advice (orig)
|
||||||
"Function used as advice to `display-time-update' with a
|
"Function used as advice to `display-time-update' with a
|
||||||
|
@ -40,11 +41,16 @@
|
||||||
(funcall format-orig (dottime--format-string) nil t))))
|
(funcall format-orig (dottime--format-string) nil t))))
|
||||||
(funcall orig)))
|
(funcall orig)))
|
||||||
|
|
||||||
(defun dottime-format (&optional time)
|
(defun dottime-format (&optional time offset prefix)
|
||||||
"Format the given TIME in dottime. If TIME is nil, the current
|
"Format the given TIME in dottime at OFFSET. If TIME is nil,
|
||||||
time will be used."
|
the current time will be used. PREFIX is prefixed to the format
|
||||||
|
string verbatim.
|
||||||
|
|
||||||
(format-time-string (dottime--format-string) time t))
|
OFFSET can be an integer representing an offset in seconds, or
|
||||||
|
the argument can be elided in which case the system time zone
|
||||||
|
is used."
|
||||||
|
|
||||||
|
(format-time-string (dottime--format-string offset prefix) time t))
|
||||||
|
|
||||||
(defun dottime-display-mode (arg)
|
(defun dottime-display-mode (arg)
|
||||||
"Enable time display as dottime. Disables dottime if called
|
"Enable time display as dottime. Disables dottime if called
|
||||||
|
|
Loading…
Reference in a new issue