Anyone want to suggest what this code is doing and how I can rewrite it to
not use MaxIntValue and MinIntValue etc?
(this code is GPL btw)
function SqlDateToDateTime(Value: string): TDateTime;
var
Year, Month, Day, Hour, Min, Sec: Word;
Temp: string;
begin
Temp := Value;
Result := 0;
if Length(Temp) >= 10 then
begin
Year := StrToIntDef(Copy(Temp, 1, 4), 1);
Year := Max(Year, 1);
Month := StrToIntDef(Copy(Temp, 6, 2), 1);
Month := MinIntValue([MaxIntValue([Month, 1]), 12]);
Day := StrToIntDef(Copy(Temp, 9, 2), 1);
Day := MinIntValue([MaxIntValue([Day, 1]), LastDay(Month, Year)]);
Result := EncodeDate(Year, Month, Day);
Temp := Copy(Temp, 12, 8);
end;
if Length(Temp) >= 8 then
begin
Hour := StrToIntDef(Copy(Temp, 1, 2), 0);
Hour := MinIntValue([MaxIntValue([Hour, 0]), 23]);
Min := StrToIntDef(Copy(Temp, 4, 2), 0);
Min := MinIntValue([MaxIntValue([Min, 0]), 59]);
Sec := StrToIntDef(Copy(Temp, 7, 2), 0);
Sec := MinIntValue([MaxIntValue([Sec, 0]), 59]);
Result := Result + EncodeTime(Hour, Min, Sec, 0);
end;
end;
{ Convert SQL Date to TDateTime with constant date part }
function SqlDateToDateTimeEx(Value: string): TDateTime;
var
Year, Month, Day, Hour, Min, Sec: Word;
Temp: string;
begin
Temp := Value;
Year := StrToIntDef(Copy(Temp, 1, 4), 1);
Year := MaxIntValue([Year, 1]);
Month := StrToIntDef(Copy(Temp, 6, 2), 1);
Month := MinIntValue([MaxIntValue([Month, 1]), 12]);
Day := StrToIntDef(Copy(Temp, 9, 2), 1);
Day := MinIntValue([MaxIntValue([Day, 1]), LastDay(Month, Year)]);
Result := EncodeDate(Year, Month, Day);
if Length(Temp) > 11 then
begin
Temp := Copy(Temp, 12, 8);
Hour := StrToIntDef(Copy(Temp, 1, 2), 0);
Hour := MinIntValue([MaxIntValue([Hour, 0]), 23]);
Min := StrToIntDef(Copy(Temp, 4, 2), 0);
Min := MinIntValue([MaxIntValue([Min, 0]), 59]);
Sec := StrToIntDef(Copy(Temp, 7, 2), 0);
Sec := MinIntValue([MaxIntValue([Sec, 0]), 59]);
Result := Result + EncodeTime(Hour, Min, Sec, 0);
end;
end;
=======================================================================
Patrick Dunford, Christchurch, NZ - http://pdunford.godzone.net.nz/
Therefore, since we are receiving a kingdom that cannot be
shaken, let us be thankful, and so worship God acceptably with
reverence and awe, for our "God is a consuming fire."
-- Hebrews 12:28-29
http://www.heartlight.org/cgi-shl/todaysverse.cgi?day=20001228
=======================================================================
Created by Mail2Sig - http://pdunford.godzone.net.nz/software/mail2sig/
---------------------------------------------------------------------------
New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
Website: http://www.delphi.org.nz
To UnSub, send email to: [EMAIL PROTECTED]
with body of "unsubscribe delphi"