insert-date.el (2485B)
1 ;;; insert-date.el --- Insert dates in various formats -*- lexical-binding: t; -*- 2 3 ;; Copyright (C) 2020 Jamie Beardslee 4 5 ;; Author: Jamie Beardslee <jdb@jamzattack.xyz> 6 ;; Version: 2020.09.14 7 ;; Keywords: calendar, abbrev 8 9 ;; This program is free software; you can redistribute it and/or modify 10 ;; it under the terms of the GNU General Public License as published by 11 ;; the Free Software Foundation, either version 3 of the License, or 12 ;; (at your option) any later version. 13 14 ;; This program is distributed in the hope that it will be useful, 15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 ;; GNU General Public License for more details. 18 19 ;; You should have received a copy of the GNU General Public License 20 ;; along with this program. If not, see <https://www.gnu.org/licenses/>. 21 22 ;;; Commentary: 23 24 ;; Just a tiny package to insert dates. I version all my elisp 25 ;; packages as "%Y.%m.%d" and wanted to quickly insert that in the 26 ;; magit tag prompt. 27 28 ;; Another similar package is `insert-time'[1] but I found it too 29 ;; limited, as it only supports inserting four (setq-able) formats. 30 31 ;; No customizations are supported, I don't find it necessary because 32 ;; I'm the only person using this package. 33 34 ;; [1] https://github.com/rmm5t/insert-time.el 35 36 ;;; Code: 37 38 (defun insert-date (format-string) 39 "Insert FORMAT-STRING, as parsed by `format-time-string'." 40 (insert (format-time-string format-string))) 41 42 (defun insert-date-version () 43 "Insert the date for use as a version. 44 1970.01.30" 45 (interactive "*") 46 (insert-date "%Y.%m.%d")) 47 48 (defun insert-date-only-date () 49 "Insert the date, separated by hyphens. 50 1970-01-30" 51 (interactive "*") 52 (insert-date "%Y-%m-%d")) 53 54 (defun insert-date-only-time (&optional 12-hour) 55 "Insert the current time. 56 With prefix arg, insert 12-HOUR format with AM/PM. 57 23:11 (24 hour) 58 11:11 PM (12 hour)" 59 (interactive "*P") 60 (insert-date (if 12-hour 61 "%I:%M %p" 62 "%H:%M"))) 63 64 (defun insert-date-both () 65 "Insert the date and time. 66 1970-01-30 23:11" 67 (interactive "*") 68 (insert-date "%Y-%m-%d %H:%M")) 69 70 (defun insert-date-locale () 71 "Insert the current date and time according to locale." 72 (interactive "*") 73 (insert-date "%c %Z")) 74 75 (defun insert-date-iso8601 () 76 "Insert the current date and time in full ISO 8601 format. 77 1970-01-01T23:11:00+1200" 78 (interactive "*") 79 (insert-date "%FT%T%z")) 80 81 (provide 'insert-date) 82 ;;; insert-date.el ends here