{:::::::::::::::::::::::::::::::::::::::::
::      Sito:  www.byteman.it  OpenWeb  ::
::  Raccolta:  Particelle PAS+ASM       ::
::    Autore:  Salvo Rosta aka byteman  ::
::    Titolo:  CRONOT.INC               ::
:: Revisione:  31-07-1995               ::
:::::::::::::::::::::::::::::::::::::::::}


Function XGetTimeSt;
var
  Time: String;
  Ore,Min,Sec,Cen: Word;
Begin
  GetTime(Ore,Min,Sec,Cen);
  XTimeString(Integer(Ore),Integer(Min),Integer(Sec),Time);
  XGetTimeSt:=Time;
End;

Procedure XTimeString;
var
  StrOre,StrMin,StrSec: string[2];
Begin
  Str((Ore+23) mod 24+1, StrOre);  {converte le ore}
  if Length(StrOre)=1 then StrOre:='0'+StrOre;
  Str(Min,StrMin);             {converte i minuti}
  if Length(StrMin)=1 then StrMin:='0'+StrMin;
  Str(Sec,StrSec);             {converte i secondi}
  if Length(StrSec)=1 then StrSec:='0'+StrSec;
  StrTime:=StrOre+':'+StrMin+':'+StrSec;
End;

Procedure XStringTime;
Var
  ErrConv: Integer;
Begin
  Err:=False;
  Val(Copy(InTime,1,2),Ore,ErrConv);            { ore }
  if ErrConv <> 0 then Err:=True else
    begin
      Val(Copy (InTime,4,2),Min,ErrConv);     { minuti }
      if ErrConv <> 0 then Err:=True else
        begin
          Val(Copy (InTime,7,2),Sec,ErrConv); { secondi }
          if ErrConv <> 0 then Err:=True
        End;
    End;
End;

Function XTimeOK;
Var
  Ore,Min,Sec: Integer;
                    Err: boolean;
Begin
  XStringTime(InTime,Ore,Min,Sec,Err);
  if Err then XTimeOK:=False else begin
    if (Ore > 23) or (Ore < 0) then XTimeOK:=False
      else if (Min > 59) or (Min < 0) then XTimeOK:=False
      else if (Sec > 59) or (Sec < 0) then XTimeOK:=False
      else XTimeOK:=True;
  end;
End;

Procedure XStringSecMi;
var
  Ore,Min,Sec: Integer;
Begin
  SecMi:=0;
  XStringTime(InTime,Ore,Min,Sec,Err);
  if not Err then SecMi:=LongInt(Ore)*3600 + Min*60 + Sec;
End;

Procedure XSecMiString;
var
  Ore,Min,Sec: Integer;
Begin
  if SecMi > 86400 then Err:=True
    else begin
      Ore:=SecMi Div 3600;  SecMi:=SecMi - LongInt(Ore)*3600;
      Min:=SecMi Div 60;
      Sec:=SecMi Mod 60;
      XTimeString(Ore,Min,Sec,OutTime);
    End;
End;

Procedure XSecsBetween;
Var
  SecMi1,SecMi2: LongInt;
Begin
  XStringSecMi(Time1,SecMi1,Err);
  if not Err then begin
    XStringSecMi(Time2,SecMi2,Err);
    if not Err then begin
      if SecMi1 > SecMi2 then SecMi2:=SecMi2 + 86400;
      Secs:=SecMi2 - SecMi1;
    end;
  end;
end;

Procedure XOffsetTime;
var
    SecMi: LongInt;
Begin
  XStringSecMi(InTime,SecMi,Err);
  if not Err then begin
    SecMi:=SecMi + Offset;
    while SecMi > 86400 do SecMi:=SecMi - 86400;
    while SecMi < 0 do SecMi:=SecMi + 86400;
    XSecMiString(SecMi,OutTime,Err);
  end;
end;

Procedure XTestInTime;
Var
  SecMi,SecMi1,SecMi2: LongInt;
Begin
  XStringSecMi(InTime,SecMi,Err);
  if not Err then XStringSecMi(Time1,SecMi1,Err);
  if not Err then XStringSecMi(Time2,SecMi2,Err);
  if not Err then Intern:=(SecMi <= SecMi2) and (SecMi >= SecMi1)
                         or (SecMi >= SecMi2) and (SecMi <= SecMi1);
End;