0
|
1 ;;; time-stamp.el --- Maintain last change time stamps in files edited by Emacs
|
|
2
|
4
|
3 ;; Copyright 1989, 1993, 1994, 1995 Free Software Foundation, Inc.
|
|
4
|
|
5 ;; Maintainer's Time-stamp: <95/12/28 19:48:49 gildea>
|
0
|
6 ;; Maintainer: Stephen Gildea <gildea@lcs.mit.edu>
|
|
7 ;; Keywords: tools
|
|
8
|
4
|
9 ;; XEmacs is free software; you can redistribute it and/or modify it
|
|
10 ;; under the terms of the GNU General Public License as published by
|
0
|
11 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
12 ;; any later version.
|
|
13
|
4
|
14 ;; XEmacs is distributed in the hope that it will be useful, but
|
|
15 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
17 ;; General Public License for more details.
|
0
|
18
|
|
19 ;; You should have received a copy of the GNU General Public License
|
4
|
20 ;; along with XEmacs; see the file COPYING. If not, write to the Free
|
|
21 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
|
22 ;; 02111-1307, USA.
|
0
|
23
|
4
|
24 ;;; Synched up with: 19.34.
|
0
|
25
|
|
26 ;;; Commentary:
|
|
27
|
4
|
28 ;; If you put a time stamp template anywhere in the first 8 lines of a file,
|
|
29 ;; it can be updated every time you save the file. See the top of
|
|
30 ;; time-stamp.el for a sample. The template looks like one of the following:
|
|
31 ;; Time-stamp: <>
|
|
32 ;; Time-stamp: " "
|
|
33 ;; The time stamp is written between the brackets or quotes, resulting in
|
|
34 ;; Time-stamp: <95/01/18 10:20:51 gildea>
|
|
35 ;; Here is an example that puts the file name and time stamp in the binary:
|
|
36 ;; static char *time_stamp = "sdmain.c Time-stamp: <>";
|
0
|
37
|
4
|
38 ;; To activate automatic time stamping in GNU Emacs 19, add this code
|
|
39 ;; to your .emacs file:
|
|
40 ;; (add-hook 'write-file-hooks 'time-stamp)
|
|
41 ;;
|
|
42 ;; In Emacs 18 you will need to do this instead:
|
|
43 ;; (if (not (memq 'time-stamp write-file-hooks))
|
|
44 ;; (setq write-file-hooks
|
|
45 ;; (cons 'time-stamp write-file-hooks)))
|
|
46 ;; (autoload 'time-stamp "time-stamp" "Update the time stamp in a buffer." t)
|
|
47
|
|
48 ;; See the documentation for the function `time-stamp' for more details.
|
0
|
49
|
|
50 ;;; Change Log:
|
|
51
|
4
|
52 ;; Originally based on the 19 Dec 88 version of
|
|
53 ;; date.el by John Sturdy <mcvax!harlqn.co.uk!jcgs@uunet.uu.net>
|
|
54 ;; version 2, January 1995: replaced functions with %-escapes
|
|
55 ;; $Id: time-stamp.el,v 1.1.1.2 1996/12/18 03:53:21 steve Exp $
|
0
|
56
|
|
57 ;;; Code:
|
|
58
|
|
59 (defvar time-stamp-active t
|
4
|
60 "*Non-nil to enable time-stamping of buffers by \\[time-stamp].
|
|
61 Can be toggled by \\[time-stamp-toggle-active].
|
|
62 See also the variable time-stamp-warn-inactive.")
|
|
63
|
|
64 (defvar time-stamp-warn-inactive t
|
|
65 "*Non-nil to have \\[time-stamp] warn if a buffer did not get time-stamped.
|
|
66 A warning is printed if time-stamp-active is nil and the buffer contains
|
|
67 a time stamp template that would otherwise have been updated.")
|
|
68
|
|
69 (defvar time-stamp-format "%02y/%02m/%02d %02H:%02M:%02S %u"
|
|
70 "*Template for the string inserted by \\[time-stamp].
|
|
71 Value may be a string or a list. (Lists are supported only for
|
|
72 backward compatibility.) A string is used verbatim except
|
|
73 for character sequences beginning with %:
|
0
|
74
|
4
|
75 %a weekday name: `Monday'. %A gives uppercase: `MONDAY'
|
|
76 %b month name: `January'. %B gives uppercase: `JANUARY'
|
|
77 %d day of month
|
|
78 %H 24-hour clock hour
|
|
79 %I 12-hour clock hour
|
|
80 %m month number
|
|
81 %M minute
|
|
82 %p `am' or `pm'. %P gives uppercase: `AM' or `PM'
|
|
83 %S seconds
|
|
84 %w day number of week, Sunday is 0
|
|
85 %y year: `1995'
|
|
86 %z time zone name: `est'. %Z gives uppercase: `EST'
|
|
87
|
|
88 Non-date items:
|
|
89 %% a literal percent character: `%'
|
|
90 %f file name without directory %F gives absolute pathname
|
|
91 %s system name
|
|
92 %u user's login name
|
|
93 %h mail host name
|
|
94
|
|
95 Decimal digits between the % and the type character specify the
|
|
96 field width. Strings are truncated on the right; numbers on the left.
|
|
97 A leading zero causes numbers to be zero-filled.
|
|
98
|
|
99 For example, to get the format used by the `date' command,
|
|
100 use \"%3a %3b %2d %02H:%02M:%02S %Z %y\"")
|
|
101
|
0
|
102
|
|
103 ;;; Do not change time-stamp-line-limit, time-stamp-start, or
|
|
104 ;;; time-stamp-end in your .emacs or you will be incompatible
|
|
105 ;;; with other people's files! If you must change them,
|
|
106 ;;; do so only in the local variables section of the file itself.
|
|
107
|
4
|
108 (defvar time-stamp-line-limit 8 ;Do not change!
|
|
109 "Lines of a file searched; positive counts from start, negative from end.
|
|
110 The patterns `time-stamp-start' and `time-stamp-end' must be found on one
|
|
111 of the first (last) `time-stamp-line-limit' lines of the file for the
|
|
112 file to be time-stamped by \\[time-stamp].
|
0
|
113
|
4
|
114 Do not change `time-stamp-line-limit', `time-stamp-start', or
|
|
115 `time-stamp-end' for yourself or you will be incompatible
|
0
|
116 with other people's files! If you must change them for some application,
|
|
117 do so in the local variables section of the time-stamped file itself.")
|
|
118
|
|
119
|
4
|
120 (defvar time-stamp-start "Time-stamp:[ \t]+\\\\?[\"<]+" ;Do not change!
|
|
121 "Regexp after which the time stamp is written by \\[time-stamp].
|
|
122 See also the variables `time-stamp-end' and `time-stamp-line-limit'.
|
|
123
|
|
124 Do not change `time-stamp-line-limit', `time-stamp-start', or
|
|
125 `time-stamp-end' for yourself or you will be incompatible
|
|
126 with other people's files! If you must change them for some application,
|
|
127 do so in the local variables section of the time-stamped file itself.")
|
|
128
|
|
129
|
|
130 (defvar time-stamp-end "\\\\?[\">]" ;Do not change!
|
0
|
131 "Regexp marking the text after the time stamp.
|
4
|
132 \\[time-stamp] deletes the text between the first match of `time-stamp-start'
|
|
133 and the following match of `time-stamp-end' on the same line,
|
|
134 then writes the time stamp specified by `time-stamp-format' between them.
|
|
135
|
|
136 Do not change `time-stamp-line-limit', `time-stamp-start', or
|
|
137 `time-stamp-end' for yourself or you will be incompatible
|
|
138 with other people's files! If you must change them for some application,
|
|
139 do so in the local variables section of the time-stamped file itself.")
|
|
140
|
0
|
141
|
|
142 ;;;###autoload
|
|
143 (defun time-stamp ()
|
|
144 "Update the time stamp string in the buffer.
|
4
|
145 If you put a time stamp template anywhere in the first 8 lines of a file,
|
|
146 it can be updated every time you save the file. See the top of
|
|
147 `time-stamp.el' for a sample. The template looks like one of the following:
|
|
148 Time-stamp: <>
|
|
149 Time-stamp: \" \"
|
|
150 The time stamp is written between the brackets or quotes, resulting in
|
|
151 Time-stamp: <95/01/18 10:20:51 gildea>
|
0
|
152 Only does its thing if the variable time-stamp-active is non-nil.
|
|
153 Typically used on write-file-hooks for automatic time-stamping.
|
4
|
154 The format of the time stamp is determined by the variable time-stamp-format.
|
|
155 The variables time-stamp-line-limit, time-stamp-start, and time-stamp-end
|
|
156 control finding the template."
|
0
|
157 (interactive)
|
4
|
158 (let ((case-fold-search nil)
|
|
159 (need-to-warn nil)
|
|
160 start search-end)
|
|
161 (if (and (stringp time-stamp-start)
|
|
162 (stringp time-stamp-end))
|
|
163 (save-excursion
|
|
164 (save-restriction
|
|
165 (widen)
|
|
166 (if (> time-stamp-line-limit 0)
|
|
167 (progn
|
|
168 (goto-char (setq start (point-min)))
|
|
169 (forward-line time-stamp-line-limit)
|
|
170 (setq search-end (point)))
|
|
171 (goto-char (setq search-end (point-max)))
|
|
172 (forward-line time-stamp-line-limit)
|
|
173 (setq start (point)))
|
|
174 (goto-char start)
|
|
175 (while
|
|
176 (and (< (point) search-end)
|
|
177 (re-search-forward time-stamp-start search-end 'move))
|
|
178 (setq start (point))
|
|
179 (end-of-line)
|
|
180 (let ((line-end (point)))
|
|
181 (goto-char start)
|
|
182 (if (re-search-forward time-stamp-end line-end 'move)
|
|
183 (progn
|
|
184 (if time-stamp-active
|
|
185 (let ((end (match-beginning 0)))
|
|
186 (delete-region start end)
|
|
187 (goto-char start)
|
|
188 (insert (time-stamp-string))
|
|
189 (setq end (point))
|
|
190 ;; remove any tabs used to format time stamp
|
|
191 (goto-char start)
|
|
192 (if (search-forward "\t" end t)
|
|
193 (untabify start end)))
|
|
194 (if time-stamp-warn-inactive
|
|
195 ;; do warning outside save-excursion
|
|
196 (setq need-to-warn t)))
|
|
197 (setq search-end (point))))))))
|
|
198 ;; don't signal an error in a write-file-hook
|
|
199 (message "time-stamp-start or time-stamp-end is not a string")
|
|
200 (sit-for 1))
|
|
201 (if need-to-warn
|
|
202 (progn
|
|
203 (message "Warning: time-stamp-active is off; did not time-stamp buffer.")
|
|
204 (sit-for 1))))
|
0
|
205 ;; be sure to return nil so can be used on write-file-hooks
|
|
206 nil)
|
|
207
|
4
|
208 ;;;###autoload
|
|
209 (defun time-stamp-toggle-active (&optional arg)
|
|
210 "Toggle time-stamp-active, setting whether \\[time-stamp] updates a buffer.
|
|
211 With arg, turn time stamping on if and only if arg is positive."
|
|
212 (interactive "P")
|
|
213 (setq time-stamp-active
|
|
214 (if (null arg)
|
|
215 (not time-stamp-active)
|
|
216 (> (prefix-numeric-value arg) 0)))
|
|
217 (message "time-stamp is now %s." (if time-stamp-active "active" "off")))
|
|
218
|
|
219
|
0
|
220 (defun time-stamp-string ()
|
|
221 "Generate the new string to be inserted by \\[time-stamp]."
|
4
|
222 (if (stringp time-stamp-format)
|
|
223 (time-stamp-strftime time-stamp-format)
|
|
224 (time-stamp-fconcat time-stamp-format " "))) ;version 1 compatibility
|
|
225
|
|
226 (defconst time-stamp-month-numbers
|
|
227 '(("Jan" . 1) ("Feb" . 2) ("Mar" . 3) ("Apr" . 4) ("May" . 5) ("Jun" . 6)
|
|
228 ("Jul" . 7) ("Aug" . 8) ("Sep" . 9) ("Oct" . 10) ("Nov" . 11) ("Dec" . 12))
|
|
229 "Alist of months and their number.")
|
|
230
|
|
231 (defconst time-stamp-month-full-names
|
|
232 ["(zero)" "January" "February" "March" "April" "May" "June"
|
|
233 "July" "August" "September" "October" "November" "December"])
|
|
234
|
|
235 (defconst time-stamp-weekday-numbers
|
|
236 '(("Sun" . 0) ("Mon" . 1) ("Tue" . 2) ("Wed" . 3)
|
|
237 ("Thu" . 4) ("Fri" . 5) ("Sat" . 6))
|
|
238 "Alist of weekdays and their number.")
|
|
239
|
|
240 (defconst time-stamp-weekday-full-names
|
|
241 ["Sunday" "Monday" "Tuesday" "Wednesday" "Thursday" "Friday" "Saturday"])
|
|
242
|
|
243 (defconst time-stamp-am-pm '("am" "pm")
|
|
244 "List of strings used to denote morning and afternoon.")
|
|
245
|
|
246 (defconst time-stamp-no-file "(no file)"
|
|
247 "String to use when the buffer is not associated with a file.")
|
|
248
|
|
249 (defun time-stamp-strftime (format &optional time)
|
|
250 "Uses a FORMAT to format date, time, file, and user information.
|
|
251 Optional second argument TIME will be used instead of the current time.
|
|
252 See the description of the variable `time-stamp-format' for a description
|
|
253 of the format string."
|
|
254 (let ((time-string (cond ((stringp time)
|
|
255 time)
|
|
256 (time
|
|
257 (current-time-string time))
|
|
258 (t
|
|
259 (current-time-string))))
|
|
260 (fmt-len (length format))
|
|
261 (ind 0)
|
|
262 cur-char
|
|
263 (prev-char nil)
|
|
264 (result "")
|
|
265 field-index
|
|
266 field-width
|
|
267 field-result
|
|
268 (paren-level 0))
|
|
269 (while (< ind fmt-len)
|
|
270 (setq cur-char (aref format ind))
|
|
271 (setq
|
|
272 result
|
|
273 (concat result
|
|
274 (cond
|
|
275 ((eq cur-char ?%)
|
|
276 (setq field-index (1+ ind))
|
|
277 (while (progn
|
|
278 (setq ind (1+ ind))
|
|
279 (setq cur-char (if (< ind fmt-len)
|
|
280 (aref format ind)
|
|
281 ?\0))
|
|
282 (and (<= ?0 cur-char) (>= ?9 cur-char))))
|
|
283 (setq field-width (substring format field-index ind))
|
|
284 ;; eat any additional args to allow for future expansion
|
|
285 (while (or (and (<= ?0 cur-char) (>= ?9 cur-char)) (eq ?. cur-char)
|
|
286 (eq ?, cur-char) (eq ?: cur-char) (eq ?@ cur-char)
|
|
287 (eq ?- cur-char) (eq ?+ cur-char)
|
|
288 (eq ?\ cur-char) (eq ?# cur-char)
|
|
289 (and (eq ?\( cur-char)
|
|
290 (not (eq prev-char ?\\))
|
|
291 (setq paren-level (1+ paren-level)))
|
|
292 (if (and (eq ?\) cur-char)
|
|
293 (not (eq prev-char ?\\))
|
|
294 (> paren-level 0))
|
|
295 (setq paren-level (1- paren-level))
|
|
296 (and (> paren-level 0)
|
|
297 (< ind fmt-len))))
|
|
298 (setq ind (1+ ind))
|
|
299 (setq prev-char cur-char)
|
|
300 (setq cur-char (if (< ind fmt-len)
|
|
301 (aref format ind)
|
|
302 ?\0)))
|
|
303 (setq field-result
|
|
304 (cond
|
|
305 ((eq cur-char ?%)
|
|
306 "%")
|
|
307 ((or (eq cur-char ?a) ;weekday name
|
|
308 (eq cur-char ?A))
|
|
309 (let ((name
|
|
310 (aref time-stamp-weekday-full-names
|
|
311 (cdr (assoc (substring time-string 0 3)
|
|
312 time-stamp-weekday-numbers)))))
|
|
313 (if (eq cur-char ?a)
|
|
314 name
|
|
315 (upcase name))))
|
|
316 ((or (eq cur-char ?b) ;month name
|
|
317 (eq cur-char ?B))
|
|
318 (let ((name
|
|
319 (aref time-stamp-month-full-names
|
|
320 (cdr (assoc (substring time-string 4 7)
|
|
321 time-stamp-month-numbers)))))
|
|
322 (if (eq cur-char ?b)
|
|
323 name
|
|
324 (upcase name))))
|
|
325 ((eq cur-char ?d) ;day of month, 1-31
|
|
326 (string-to-int (substring time-string 8 10)))
|
|
327 ((eq cur-char ?H) ;hour, 0-23
|
|
328 (string-to-int (substring time-string 11 13)))
|
|
329 ((eq cur-char ?I) ;hour, 1-12
|
|
330 (let ((hour (string-to-int (substring time-string 11 13))))
|
|
331 (cond ((< hour 1)
|
|
332 (+ hour 12))
|
|
333 ((> hour 12)
|
|
334 (- hour 12))
|
|
335 (t
|
|
336 hour))))
|
|
337 ((eq cur-char ?m) ;month number, 1-12
|
|
338 (cdr (assoc (substring time-string 4 7)
|
|
339 time-stamp-month-numbers)))
|
|
340 ((eq cur-char ?M) ;minute, 0-59
|
|
341 (string-to-int (substring time-string 14 16)))
|
|
342 ((or (eq cur-char ?p) ;am or pm
|
|
343 (eq cur-char ?P))
|
|
344 (let ((name
|
|
345 (if (> 12 (string-to-int (substring time-string 11 13)))
|
|
346 (car time-stamp-am-pm)
|
|
347 (car (cdr time-stamp-am-pm)))))
|
|
348 (if (eq cur-char ?p)
|
|
349 name
|
|
350 (upcase name))))
|
|
351 ((eq cur-char ?S) ;seconds, 00-60
|
|
352 (string-to-int (substring time-string 17 19)))
|
|
353 ((eq cur-char ?w) ;weekday number, Sunday is 0
|
|
354 (cdr (assoc (substring time-string 0 3) time-stamp-weekday-numbers)))
|
|
355 ((eq cur-char ?y) ;year
|
|
356 (string-to-int (substring time-string -4)))
|
|
357 ((or (eq cur-char ?z) ;time zone
|
|
358 (eq cur-char ?Z))
|
|
359 (let ((name
|
|
360 (if (fboundp 'current-time-zone)
|
|
361 (car (cdr (current-time-zone time))))))
|
|
362 (or name (setq name ""))
|
|
363 (if (eq cur-char ?z)
|
|
364 (downcase name)
|
|
365 (upcase name))))
|
|
366 ((eq cur-char ?f) ;buffer-file-name, base name only
|
|
367 (if buffer-file-name
|
|
368 (file-name-nondirectory buffer-file-name)
|
|
369 time-stamp-no-file))
|
|
370 ((eq cur-char ?F) ;buffer-file-name, full path
|
|
371 (or buffer-file-name
|
|
372 time-stamp-no-file))
|
|
373 ((eq cur-char ?s) ;system name
|
|
374 (system-name))
|
|
375 ((eq cur-char ?u) ;user name
|
|
376 (user-login-name))
|
|
377 ((eq cur-char ?h) ;mail host name
|
|
378 (time-stamp-mail-host-name))
|
|
379 ))
|
|
380 (if (string-equal field-width "")
|
|
381 field-result
|
|
382 (let ((padded-result
|
|
383 (format (format "%%%s%c"
|
|
384 field-width
|
|
385 (if (numberp field-result) ?d ?s))
|
|
386 (or field-result ""))))
|
|
387 (let ((initial-length (length padded-result))
|
|
388 (desired-length (string-to-int field-width)))
|
|
389 (if (> initial-length desired-length)
|
|
390 ;; truncate strings on right, numbers on left
|
|
391 (if (stringp field-result)
|
|
392 (substring padded-result 0 desired-length)
|
|
393 (substring padded-result (- desired-length)))
|
|
394 padded-result)))))
|
|
395 (t
|
|
396 (char-to-string cur-char)))))
|
|
397 (setq ind (1+ ind)))
|
|
398 result))
|
|
399
|
|
400 (defun time-stamp-mail-host-name ()
|
|
401 "Return the name of the host where the user receives mail.
|
|
402 This is the value of `mail-host-address' if bound and a string,
|
|
403 otherwise the value of `time-stamp-mail-host' (for versions of Emacs
|
|
404 before 19.29) otherwise the value of the function system-name."
|
|
405 (or (and (boundp 'mail-host-address)
|
|
406 (stringp mail-host-address)
|
|
407 mail-host-address)
|
|
408 (and (boundp 'time-stamp-mail-host) ;for backward compatibility
|
|
409 (stringp time-stamp-mail-host)
|
|
410 time-stamp-mail-host)
|
|
411 (system-name)))
|
|
412
|
|
413 ;;; the rest of this file is for version 1 compatibility
|
0
|
414
|
|
415 (defun time-stamp-fconcat (list sep)
|
4
|
416 "Similar to (mapconcat 'funcall LIST SEP) but LIST allows literals.
|
0
|
417 If an element of LIST is a symbol, it is funcalled to get the string to use;
|
|
418 the separator SEP is used between two strings obtained by funcalling a
|
|
419 symbol. Otherwise the element itself is inserted; no separator is used
|
|
420 around literals."
|
|
421 (let ((return-string "")
|
|
422 (insert-sep-p nil))
|
|
423 (while list
|
|
424 (cond ((symbolp (car list))
|
|
425 (if insert-sep-p
|
|
426 (setq return-string (concat return-string sep)))
|
|
427 (setq return-string (concat return-string (funcall (car list))))
|
|
428 (setq insert-sep-p t))
|
|
429 (t
|
|
430 (setq return-string (concat return-string (car list)))
|
|
431 (setq insert-sep-p nil)))
|
|
432 (setq list (cdr list)))
|
|
433 return-string))
|
|
434
|
|
435
|
|
436 ;;; Some useful functions to use in time-stamp-format
|
|
437
|
|
438 ;;; Could generate most of a message-id with
|
4
|
439 ;;; '(time-stamp-yymmdd "" time-stamp-hhmm "@" time-stamp-mail-host-name)
|
0
|
440
|
|
441 ;;; pretty form, suitable for a title page
|
|
442
|
|
443 (defun time-stamp-month-dd-yyyy ()
|
4
|
444 "Return the current date as a string in \"Month DD, YYYY\" form."
|
0
|
445 (let ((date (current-time-string)))
|
4
|
446 (format "%s %d, %s"
|
0
|
447 (aref time-stamp-month-full-names
|
|
448 (cdr (assoc (substring date 4 7) time-stamp-month-numbers)))
|
|
449 (string-to-int (substring date 8 10))
|
|
450 (substring date -4))))
|
|
451
|
|
452 ;;; same as __DATE__ in ANSI C
|
|
453
|
|
454 (defun time-stamp-mon-dd-yyyy ()
|
4
|
455 "Return the current date as a string in \"Mon DD YYYY\" form.
|
|
456 The first character of DD is space if the value is less than 10."
|
0
|
457 (let ((date (current-time-string)))
|
|
458 (format "%s %2d %s"
|
|
459 (substring date 4 7)
|
|
460 (string-to-int (substring date 8 10))
|
|
461 (substring date -4))))
|
|
462
|
|
463 ;;; RFC 822 date
|
|
464
|
|
465 (defun time-stamp-dd-mon-yy ()
|
4
|
466 "Return the current date as a string in \"DD Mon YY\" form."
|
0
|
467 (let ((date (current-time-string)))
|
|
468 (format "%02d %s %s"
|
|
469 (string-to-int (substring date 8 10))
|
|
470 (substring date 4 7)
|
|
471 (substring date -2))))
|
|
472
|
|
473 ;;; RCS 3 date
|
|
474
|
|
475 (defun time-stamp-yy/mm/dd ()
|
4
|
476 "Return the current date as a string in \"YY/MM/DD\" form."
|
0
|
477 (let ((date (current-time-string)))
|
|
478 (format "%s/%02d/%02d"
|
|
479 (substring date -2)
|
|
480 (cdr (assoc (substring date 4 7) time-stamp-month-numbers))
|
|
481 (string-to-int (substring date 8 10)))))
|
|
482
|
|
483 ;;; RCS 5 date
|
|
484
|
|
485 (defun time-stamp-yyyy/mm/dd ()
|
4
|
486 "Return the current date as a string in \"YYYY/MM/DD\" form."
|
0
|
487 (let ((date (current-time-string)))
|
|
488 (format "%s/%02d/%02d"
|
|
489 (substring date -4)
|
|
490 (cdr (assoc (substring date 4 7) time-stamp-month-numbers))
|
|
491 (string-to-int (substring date 8 10)))))
|
|
492
|
4
|
493 ;;; ISO 8601 date
|
|
494
|
|
495 (defun time-stamp-yyyy-mm-dd ()
|
|
496 "Return the current date as a string in \"YYYY-MM-DD\" form."
|
|
497 (let ((date (current-time-string)))
|
|
498 (format "%s-%02d-%02d"
|
|
499 (substring date -4)
|
|
500 (cdr (assoc (substring date 4 7) time-stamp-month-numbers))
|
|
501 (string-to-int (substring date 8 10)))))
|
|
502
|
0
|
503 (defun time-stamp-yymmdd ()
|
4
|
504 "Return the current date as a string in \"YYMMDD\" form."
|
0
|
505 (let ((date (current-time-string)))
|
|
506 (format "%s%02d%02d"
|
|
507 (substring date -2)
|
|
508 (cdr (assoc (substring date 4 7) time-stamp-month-numbers))
|
|
509 (string-to-int (substring date 8 10)))))
|
|
510
|
|
511 (defun time-stamp-hh:mm:ss ()
|
4
|
512 "Return the current time as a string in \"HH:MM:SS\" form."
|
0
|
513 (substring (current-time-string) 11 19))
|
|
514
|
|
515 (defun time-stamp-hhmm ()
|
4
|
516 "Return the current time as a string in \"HHMM\" form."
|
0
|
517 (let ((date (current-time-string)))
|
|
518 (concat (substring date 11 13)
|
|
519 (substring date 14 16))))
|
|
520
|
|
521 (provide 'time-stamp)
|
|
522
|
|
523 ;;; time-stamp.el ends here
|