On Nov 24, 2008, at 9:31 PM, Alan E. Davis wrote:
Well write a function searching for the strings and change them... :-)
Something like this (untested) might do it. These functions
(defun my-change-times-in-region (beg end delta)
"Change all h:mm:ss time in region by a DELTA."
(interactive "r\nsEnter time difference like \"-1:08:26\" or \"0:00:25\": ")
(let ((re "[-+]?[0-9]+:[0-9]\\{2\\}:[0-9]\\{2\\}")
(delta (my-hms-to-secs delta))
old new p)
(when (= delta 0) (error "No change"))
(save-excursion
(goto-char end)
(while (re-search-backward re beg t)
(setq p (point))
(replace-match
(save-match-data
(my-secs-to-hms (+ (my-hms-to-secs (match-string 0)) delta)))
t t)
(goto-char p)))))
(defun my-hms-to-secs (hms)
"Convert h:mm:ss string to an integer time.
If the string starts with a minus sign, the integer will be negative."
(if (not (string-match
"\\([-+]?[0-9]+\\):\\([0-9]\\{2\\}\\):\\([0-9]\\{2\\}\\)"
hms))
0
(let* ((h (string-to-int (match-string 1 hms)))
(m (string-to-int (match-string 2 hms)))
(s (string-to-int (match-string 3 hms)))
(sign (equal (substring (match-string 1 hms) 0 1) "-")))
(setq h (abs h))
(* (if sign -1 1) (+ s (* 60 (+ m (* 60 h))))))))
(defun my-secs-to-hms (s)
"Convert integer S into h:mm:ss.
If the integer is negative, the strig will start with \"-\"."
(let (sign m h)
(setq sign (if (< s 0) "-" "")
s (abs s)
m (/ s 60) s (- s (* 60 m))
h (/ m 60) m (- m (* 60 h)))
(format "%s%d:%02d:%02d" sign h m s)))
I can add something linke this to Org....