Skip to content

Instantly share code, notes, and snippets.

@kickingvegas
Created November 30, 2022 19:50
Show Gist options
  • Save kickingvegas/ecaeb36864c119a3ab85fa5a914b313f to your computer and use it in GitHub Desktop.
Save kickingvegas/ecaeb36864c119a3ab85fa5a914b313f to your computer and use it in GitHub Desktop.
Posix / Human Timestamp Elisp (quick and dirty)
(defun cc/posix-timestamp-to-human (start end)
(interactive "r")
(if (use-region-p)
(let ((regionp (buffer-substring start end)))
(set 'inputTime (time-convert (string-to-number regionp)))
(set 'inputBuf (number-to-string (string-to-number regionp)))
(set 'rfcBuf (format-time-string "%a, %e %b %Y %H:%M:%S %z" inputTime))
(set 'isoBuf (format-time-string "%Y-%m-%dT%H:%M:%S%z" inputTime))
(with-output-to-temp-buffer "*timestamps*"
(princ (concat "| POSIX | " inputBuf " |\n"))
(princ (concat "| RFC 822 | " rfcBuf " |\n"))
(princ (concat "| ISO 8601 | " isoBuf " |\n"))
))))
(defun cc/human-timestamp-to-posix (start end)
(interactive "r")
(if (use-region-p)
(let ((regionp (buffer-substring start end)))
(set 'result (number-to-string (time-to-seconds (date-to-time regionp))))
(kill-new result)
(with-output-to-temp-buffer "*timestamps*"
(princ result)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment