Reputation: 771
If an org table cell contains the HMS 1@ 11' 37"
is there an easy way to get the total (time)seconds?
(1*3600 + 11*60 + 37 = 4297)
Upvotes: 0
Views: 367
Reputation: 2350
Try this:
(defun hms-to-seconds (str)
(let* ((lst (split-string str "@ "))
(hour (car lst))
(lst2 (split-string (cadr lst) "' "))
(minute (car lst2))
(second (car (split-string (cadr lst2) "\""))))
(+ (* (string-to-number hour) 3600)
(* (string-to-number minute) 60)
(string-to-number second))))
Upd: As @Juancho noted there is more simple way with direct hms calculations:
| 1@ 11' 37" | 4297 | 4297 |
#+TBLFM: $2='(fmt-to-seconds $1)::$3=$1\ 0@ 0' 1"
Upvotes: 4