How to round up time...

One more time: Hi experts !
Today I'm looking for a solution, to round time. I want to set a value for
minimum minutes and an other value for rounding the minutes.

An example:
There is an incoming phone-call and  I want to  press a button to set starting-time.
If the duration of the call is less than a minimum value, I want to set the
duration to this value after ending the call ( i.e. Call: 1 Minute  ==> Logged: 5 Minutes).
If the call is longer than my minimum value, it should be possible, to round the time to
individual minutes-values.  

I tried this:

var : Minimum, Runden : Integer;

procedure Tfrm.FormCreate(Sender: TObject);
begin
  Minimum := spinMini.IntValue;
  Runden :=   spinRunden.IntValue * 1440 ;
end;

function TakeCall(dTime: TDateTime): TDateTime;
begin
   result := round(dTime * Runden) / Runden;
end;


function EndCall(dTime: TDateTime): TDateTime;
var
  Hour, Min, Sec, MSec: Word;
begin
   DecodeTime(dTime, Hour, Min, Sec, MSec);
   if Min < Minimum then
   begin
    Min  := Minimum;
    Sec  := 0;
    MSec := 0;
    result := EncodeTime(Hour, Min, Sec, MSec);
    end else
    begin
    result := round(dTime * Rund) / Rund;
    end;
end;


 //...with ListView: NewItem := ListView.Items.Add ...
 
procedure Tfrm.btnTakeCallClick(Sender: TObject);
begin
     NewItem.SubItems.Add(TimeToStr(TakeCall(Now)));
end;

procedure Tfrm.btnEndCallClick(Sender: TObject);
begin
     NewItem.SubItems.Add(TimeToStr(EndCall(Now)));
end;


Where is my mistake ? Can U help ?
I know, the question isn't very difficult, but time makes it
a 500 points question.

Regards, Bwsd2












Brainwashed2Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mokuleCommented:
You could do it like this

// start button
procedure TForm1.Button1Click(Sender: TObject);
begin
  tp := Now;
end;

// stop button
procedure TForm1.Button2Click(Sender: TObject);
const
// i've done shortertimes to easier test
// You'd better do it with MinsPerDay constant
  MinValue = 5 / SecsPerDay;   // this gives 5 seconds minimum period
  GridValue = 2 / SecsPerDay;  // this gives 2 seconds rounding
begin
  if Now - tp < MinValue then
    memo1.Lines.Add(TimeToStr(MinValue))
  else
    memo1.Lines.Add(TimeToStr(Round((Now - tp) / GridValue) * GridValue));
end;

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Scay7Commented:
Lets see if i get this:

1. call shorter than 1min = 5min
2. call longer than 1min = Xmin(rounded to the nearest minute)  eg: 1:35min = 2min or 1:15 = 1min

or did i miss something ?

Peace Scay7
0
mokuleCommented:
If You don't want change Your code much.
It should be
    result := round(dTime / Rund) * Rund;
0
Scay7Commented:
Okay ive created something... tell me if this is what you want then ill paste the code here....

http://www.uo.co.za/phonecall.exe

has a input for min time min/sec
if below that shows as 5min
if higher than that shows actual time

Peace Scay7
0
Brainwashed2Author Commented:
Hi Mokule,

your hint 'result := round(dTime / Rund) * Rund;' i've found myself, but your
source is much butter ! Thank you.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.