anonymity
2011-02-19 15:31:19
I had a few questions a while back. I wanted to expand them and make a funciton to allow for specific time of day calls to whatever function I wanted. They weren't related to this at the time, but thanks to people who helped answer a few questions when I had them concerning the time calls: JPHamlett, Wizzup?, Narcle, i luffs yeww, Daniel, drags111, Nava2, RsN & Ron
Troll Man helped out with a question on the CheckTime(void) function.
Most of these are already in SRL, I made minor changes to have them work for me. I included them just to help make sense to the function I wrote. The one that I am really presenting is the CheckTimeHM(:TIntArray):bool function at the bottom.
I dunno if this would be helpful or useful to add. Thoughts?
E: Not that this is any big breakthru.. I have just found it … useful and thought someone else might too.
Short version: Here.
Troll Man helped out with a question on the CheckTime(void) function.
Most of these are already in SRL, I made minor changes to have them work for me. I included them just to help make sense to the function I wrote. The one that I am really presenting is the CheckTimeHM(:TIntArray):bool function at the bottom.
I dunno if this would be helpful or useful to add. Thoughts?
Program TimeRelated;
{////////////////////////////////////////////////////////////
/ Function:_ ScriptRunTime(void): string;
////////////////////////////////////////////////////////////}
Function ScriptRunTime: string;
var
S, M, H, D : integer;
begin
if GetTimeRunning < (24*60*60*1000) then
begin
ConvertTime(GetTimeRunning, H, M, S);
Result := ('ran for ' + IntToStr(H) + ' hrs, ' + IntToStr(M) + ' min, ' + IntToStr(S) + ' sec');
end else
begin
ConvertTime(GetTimeRunning, H, M, S);
D := Floor(H/24);
H := H mod 24;//remainder
Result := ('ran for ' + IntToStr(D) + ' days, ' + IntToStr(H) + ' hours, ' +
IntToStr(M) + ' minutes, ' + IntToStr(S) + ' seconds');
end;
end;
{///////////////////////////////////////////////////////////////////////////
/ Function : DateOfYear(void): string
///////////////////////////////////////////////////////////////////////////}
Function DateOfYear: string;
var
y, m, d : Word;
months: TStringArray;
begin
months := ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'June', 'July', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
DecodeDate(date, y, m, d);
Result := (months[m-1]+'/' + inttostr(d) + '/' + inttostr(y));
end;
{///////////////////////////////////////////////////////////////////////////
/ Function : TimeOfDay(void): string
///////////////////////////////////////////////////////////////////////////}
Function TimeOfDay: string;
var
H, M, S, Ms: Word;
begin
DecodeTime(Now, H, M, S, Ms);
Result := (Padz(IntToStr(H), 2) + ':' + Padz(IntToStr(M), 2) + '.' + Padz(IntToStr(S), 2));
end;
{/////////////////////////////////////////////////////////////////
/ Function : CheckTime(void): boolean;
//////////////////////////////////////////////////////////////////}
Function CheckTime: boolean;
var
i, j : Integer;
H, M, S, Ms : Word;
CrtnHrs, CrtnMnts : TIntegerArray;
begin
CrtnHrs := [11, 20, 21, 22, 23];
CrtnMnts := [15, 59];
DecodeTime(Now, H, M, S, Ms);
Result := false;
for i:=0 to High(CrtnHrs) do
if H = CrtnHrs[i] then
for j:=0 to High(CrtnMnts) do
if M = CrtnMnts[j] then
begin
writeln(TimeOfDay + ' = True');
Result := true;
end;
end;
{//////////////////////////////////////////////////////////////////////////
/ Function : CheckTime(CrtnHrs, CrtnMnts : TIntegerArray): boolean;
///////////////////////////////////////////////////////////////////////////}
Function CheckTimeHM(CrtnHrs, CrtnMnts : TIntegerArray): boolean;
var
i, j : Integer;
H, M, S, Ms : Word;
begin
DecodeTime(Now, H, M, S, Ms);
Result := false;
for i:=0 to High(CrtnHrs) do
if H = CrtnHrs[i] then
for j:=0 to High(CrtnMnts) do
if M = CrtnMnts[j] then
Result := true;
end;
Begin
ClearDebug;
CheckTimeHM([11, 12, 13], [15, 45]);
// CheckTimeHM([{hours #s here separated by commas}], [{minutes #s here separated by commas}]);
End.E: Not that this is any big breakthru.. I have just found it … useful and thought someone else might too.
Short version: Here.
Function CheckTimeHM(CrtnHrs, CrtnMnts : TIntegerArray): boolean;
var
i, j : Integer;
H, M, S, Ms : Word;
begin
DecodeTime(Now, H, M, S, Ms);
Result := false;
for i:=0 to High(CrtnHrs) do
if H = CrtnHrs[i] then
for j:=0 to High(CrtnMnts) do
if M = CrtnMnts[j] then
Result := true;
end;