TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: civil.eng on May 25, 2023, 06:18:45 AM

Title: Adding time
Post by: civil.eng on May 25, 2023, 06:18:45 AM
Hello everyone,
I need a function to add two times together, For example I have current time with this format :

"13:20:59"

Now, I want to add a given time to current time like this : "00:11:12"

To put it simply, the function should add minutes and seconds to current time. the given time includes just minutes and seconds. With this example the result time is :

"13:32:11"

Title: Re: Adding time
Post by: ribarm on May 25, 2023, 02:35:37 PM
Not sure, perhaps this would work, but untested...

Code: [Select]
(defun c:addtime ( / add curr secs newt )
  (setq curr (getpoint "\nEnter current time in format hh,mm,ss : "))
  (setq add (getpoint "\nEnter additional time in format hh,mm,ss : "))
  (setq secs (+ (caddr add) (* 60 (cadr add)) (* 3600 (car add))))
  (setq newt (+ (caddr curr) (* 60 (cadr curr)) (* 3600 (car curr)) secs))
  (setq newt (list (rem (fix (/ newt 3600.0)) 24) (fix (/ (- newt (* 3600.0 (fix (/ newt 3600.0)))) 60.0)) (fix (- newt (+ (* 60.0 (fix (/ (- newt (* 3600.0 (fix (/ newt 3600.0)))) 60.0))) (* 3600.0 (fix (/ newt 3600.0))))))))
)

Code: [Select]
Enter current time in format hh,mm,ss : 13,20,59
Enter additional time in format hh,mm,ss : 00,11,12
(13 32 11)

HTH.
M.R.
Title: Re: Adding time
Post by: civil.eng on May 25, 2023, 03:46:33 PM
Why GetPoint ?
Title: Re: Adding time
Post by: It's Alive! on May 25, 2023, 04:32:49 PM
Why GetPoint ?
three real numbers at once?
Title: Re: Adding time
Post by: BIGAL on May 26, 2023, 09:59:18 PM
An oldy from the HP calculator days DDD.MMSS. this was for survey bearing its a number so easy to pull apart, HR.MMSS as number.

But I like Ribarm method.