help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Checking parameters


From: don provan
Subject: Re: Checking parameters
Date: Mon, 18 Jun 2007 10:27:26 -0700
User-agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3 (windows-nt)

"Lennart Borgman (gmail)" <address@hidden> writes:

> And this is better:
>
> (defun get-hours(time)
>    (interactive "sHH:MM: ")
>    (let ((timelist (split-string time ":"))
>          (errmsg "Time format error"))
>      (save-match-data
>        (unless (string-match "\\`[0-9]+:[0-9]\\{2\\}\\'" time)
>          (error errmsg)))
>      (+
>       (string-to-number (nth 0 timelist))
>       (/
>        (string-to-number (nth 1 timelist))
>        60.0))))

Go all the way:

(defun get-hours(time)
   (interactive "sHH:MM: ")
   (save-match-data
     (unless (string-match "\\`\\([0-9]+\\):\\([0-9]\\{2\\}\\)\\'" time)
       (error "Time format error"))
     (+
      (string-to-number (match-string 1 time))
      (/
       (string-to-number (match-string 2 time))
       60.0))))

-don


reply via email to

[Prev in Thread] Current Thread [Next in Thread]