Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

time check

Status
Not open for further replies.

filipe26

Programmer
Mar 17, 2003
152
0
0
PT
hi i have the following code to check if the system time is equal to a time that i define on a timer event:

TDateTime tempocurrente = Time();
TDateTime tempo = StrToTime("10:52");
if (tempo==tempocurrente) do something;
But when the time is 10:52 the trigger doesnt seems to work.
 
Have you written out as decimal the two values?

I would believe that you should use "10:52:00" as time reference, "10:52" could very easily be interpeded as "00:10:52" and that's quite a difference.

Totte
Keep making it perfect and it will end up broken.
 
Is the times converted to floats? I know that comparing floats "for equal" you should really compare if they are within som margin, i.e.
int Diff;
Diff = Time1 > Time2 ? Time1 - 2Time : Time2 - Time1;
if(Diff < xxx) // Where xxx is the allowable diff
{
}

It could be that the times differs in the ms.

But a simpler way is:
if (tempo>=tempocurrente) do something;
This way you says: equal OR greater, whatever applies

Totte
Keep making it perfect and it will end up broken.
 
how are you checking for the current time

A TTimer object comes in handy here.

I have used
Code:
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
   struct  time t;  
   gettime(&t); 
       //t.ti_hour,t.ti_min,t.ti_sec,t.ti_hund

   if ((t.ti_hour == 10) && (t.ti_min == 52))
      do_somthing ();
}
tomcruz.net
 
also since computers make very bad clocks
(try coding a digital display and watch the seconds)
if yu are not careful you can periodically miss the
minute or the second if you dont set your timer properly.

I would not set the timer to more than .5 minutes.

setting the timer interval to 995 will miss a second
every 15 or 20 seconds. or thats is on my pc.

setting the interval to 10000 or suposedly once a minute
will regularly miss a minute here and there.

this became an issue when I made a PCClock with a
digital display. it has alarms and snooze.

tomcruz.net
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top