Time calculations

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
mahendra
Posts: 3
Joined: Mon Jun 22, 2015 7:45 pm

Time calculations

Post by mahendra » Mon Jun 22, 2015 7:53 pm

Hi I am trying to find a routine/solution to add minutes to time to create reservation slots. e.g..

Res start time of 07:00
Res end time of 21:00
Duration of res slot 40 minutes

So I want to add 40minutes to 07:00 and create reservation slots in 40 minute increments to 21:00

How can I do this?

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4172
Joined: Sun Jan 07, 2007 9:12 pm

Re: Time calculations

Post by bn » Mon Jun 22, 2015 8:23 pm

Hi Mahendra,

welcome to the forum

look at this piece of code and please look up the relevant keywords in the dictionary for an explanation

make 1 field and 1 button; the script of the button:

Code: Select all

on mouseUp
   put 21 - 7 into tHours
   put tHours * 60 into tMinutes
   put tMinutes div 40 into tIntervalNo -- the number of 40 minutes intervals that fit into the time from 7 to 21 hours
   
   set the twelveHourTime to false -- no "am" or "pm" but in 24 hour format
   
   put "7:00" into tStartTime
   convert  tStartTime from short english time to dateItems
   
   put tStartTime into tCurrTime -- copy the dateItems to new variable that will be turned into time
   convert tCurrTime to short time -- here dateItems in tCurrTime are converted to time
   put tCurrTime & cr after tCollect -- collect the times
   
   
   
   repeat tInterValNo
      add 40 to item 5 of tStartTime -- add to dateItems
      put tStartTime into tCurrTime -- again transfer to variable
      convert tCurrTime to short time -- that will be converted to the time
      put tCurrTime & cr after tCollect
   end repeat
   
   delete byte - 1 of tCollect -- delete last return
   
   put tCollect into field 1
   
end mouseUp
Kind regards

Bernd

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10331
Joined: Wed May 06, 2009 2:28 pm

Re: Time calculations

Post by dunbarx » Mon Jun 22, 2015 10:22 pm

Hi.

I prefer a standardized time gadget. Try both of these in a button. They will yield a time that is 40 minutes after you click the button. The starting time, and any number of intervals, can then be easily incorporated into the code:

Code: Select all

on mouseUp
   get the time
   convert it to dateItems
   add 40 to item 5 of it
   convert it to short time
   answer it
end mouseUp

on mouseUp
   get the time
   convert it to seconds
   add 2400 to it
   convert it to short time
   answer it
end mouseUp
Just to show that LC has a wealth of tools for this sort of thing. Which way you do it is a matter of personal style.

Craig Newman

mahendra
Posts: 3
Joined: Mon Jun 22, 2015 7:45 pm

Re: Time calculations

Post by mahendra » Tue Jun 23, 2015 11:30 am

Absolutely awesome :D Thank you for the swift replies.

Post Reply