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

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

Re: Checking parameters


From: Lennart Borgman (gmail)
Subject: Re: Checking parameters
Date: Sun, 17 Jun 2007 13:18:07 +0200
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.4) Gecko/20070604 Thunderbird/2.0.0.4 Mnenhy/0.7.5.666

Lennart Borgman (gmail) wrote:
You probably want to use the most simple way, something like

(defun get-hours(time)
  (interactive "sHH:MM: ")
  (let ((timelist (split-string time ":"))
        (errmsg "Time format error"))
    (unless (= (length (nth 1 timelist)) 2)
      (error errmsg))
    (+
      (string-to-number (nth 0 timelist))
      (/
        (string-to-number (nth 1 timelist))
        60.0))))

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))))





reply via email to

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