Author Topic: Adding time  (Read 917 times)

0 Members and 1 Guest are viewing this topic.

civil.eng

  • Newt
  • Posts: 66
Adding time
« 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"


ribarm

  • Gator
  • Posts: 3225
  • Marko Ribar, architect
Re: Adding time
« Reply #1 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.
« Last Edit: May 25, 2023, 04:40:30 PM by ribarm »
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

civil.eng

  • Newt
  • Posts: 66
Re: Adding time
« Reply #2 on: May 25, 2023, 03:46:33 PM »
Why GetPoint ?

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8659
  • AKA Daniel
Re: Adding time
« Reply #3 on: May 25, 2023, 04:32:49 PM »
Why GetPoint ?
three real numbers at once?

BIGAL

  • Swamp Rat
  • Posts: 1396
  • 40 + years of using Autocad
Re: Adding time
« Reply #4 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.

« Last Edit: May 26, 2023, 10:14:32 PM by BIGAL »
A man who never made a mistake never made anything