[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
Solved

# How to round up time...

Posted on 2006-04-17
Medium Priority
409 Views
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
end;

procedure Tfrm.btnEndCallClick(Sender: TObject);
begin
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

0
Question by:Brainwashed2
• 2
• 2

LVL 17

Accepted Solution

mokule earned 1500 total points
ID: 16471244
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
else
memo1.Lines.Add(TimeToStr(Round((Now - tp) / GridValue) * GridValue));
end;

0

LVL 5

Expert Comment

ID: 16471319
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

LVL 17

Expert Comment

ID: 16471446
If You don't want change Your code much.
It should be
result := round(dTime / Rund) * Rund;
0

LVL 5

Expert Comment

ID: 16471747
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

Author Comment

ID: 16479404
Hi Mokule,

your hint 'result := round(dTime / Rund) * Rund;' i've found myself, but your
source is much butter ! Thank you.
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
###### Suggested Courses
Course of the Month20 days, 4 hours left to enroll