|
@@ -326,8 +326,16 @@ end ;
|
|
if S does not represent a valid date value
|
|
if S does not represent a valid date value
|
|
an EConvertError will be raised }
|
|
an EConvertError will be raised }
|
|
|
|
|
|
-function StrToDate(const S: string): TDateTime;
|
|
|
|
|
|
+function IntStrToDate(Out ErrorMsg : AnsiString; const S: PChar; Len : integer; const useformat : string; const defs:TFormatSettings; separator : char = #0): TDateTime;
|
|
|
|
+
|
|
const SInvalidDateFormat = '"%s" is not a valid date format';
|
|
const SInvalidDateFormat = '"%s" is not a valid date format';
|
|
|
|
+
|
|
|
|
+procedure FixErrorMsg(const errm :ansistring;const errmarg : ansistring);
|
|
|
|
+
|
|
|
|
+begin
|
|
|
|
+ errormsg:=format(errm,[errmarg]);
|
|
|
|
+end;
|
|
|
|
+
|
|
var
|
|
var
|
|
df:string;
|
|
df:string;
|
|
d,m,y,ly:word;
|
|
d,m,y,ly:word;
|
|
@@ -339,11 +347,16 @@ var
|
|
LocalTime:tsystemtime;
|
|
LocalTime:tsystemtime;
|
|
YearMoreThenTwoDigits : boolean;
|
|
YearMoreThenTwoDigits : boolean;
|
|
begin
|
|
begin
|
|
- if s = '' then
|
|
|
|
- Raise EConvertError.CreateFmt(SInvalidDateFormat,[s]);
|
|
|
|
-
|
|
|
|
|
|
+ ErrorMsg:=''; Result:=0;
|
|
|
|
+ if (Len=0) then
|
|
|
|
+ begin
|
|
|
|
+ FixErrorMsg(SInvalidDateFormat,'');
|
|
|
|
+ exit;
|
|
|
|
+ end;
|
|
YearMoreThenTwoDigits := False;
|
|
YearMoreThenTwoDigits := False;
|
|
- df := UpperCase(ShortDateFormat);
|
|
|
|
|
|
+ if separator = #0 then
|
|
|
|
+ separator := defs.DateSeparator;
|
|
|
|
+ df := UpperCase(useFormat);
|
|
{ Determine order of D,M,Y }
|
|
{ Determine order of D,M,Y }
|
|
yp:=0;
|
|
yp:=0;
|
|
mp:=0;
|
|
mp:=0;
|
|
@@ -375,13 +388,17 @@ begin
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
if Which<>3 then
|
|
if Which<>3 then
|
|
- Raise EConvertError.Create('Illegal format string');
|
|
|
|
|
|
+ begin
|
|
|
|
+ FixErrorMsg(SErrIllegalDateFormatString,useformat);
|
|
|
|
+ Exit;
|
|
|
|
+ end;
|
|
{ Get actual values }
|
|
{ Get actual values }
|
|
for i := 1 to 3 do
|
|
for i := 1 to 3 do
|
|
values[i] := 0;
|
|
values[i] := 0;
|
|
s1 := '';
|
|
s1 := '';
|
|
n := 0;
|
|
n := 0;
|
|
- for i := 1 to length(s) do
|
|
|
|
|
|
+ dec(len);
|
|
|
|
+ for i := 0 to len do
|
|
begin
|
|
begin
|
|
if s[i] in ['0'..'9'] then
|
|
if s[i] in ['0'..'9'] then
|
|
s1 := s1 + s[i];
|
|
s1 := s1 + s[i];
|
|
@@ -389,23 +406,32 @@ begin
|
|
{ space can be part of the shortdateformat, and is defaultly in slovak
|
|
{ space can be part of the shortdateformat, and is defaultly in slovak
|
|
windows, therefor it shouldn't be taken as separator (unless so specified)
|
|
windows, therefor it shouldn't be taken as separator (unless so specified)
|
|
and ignored }
|
|
and ignored }
|
|
- if (DateSeparator <> ' ') and (s[i] = ' ') then
|
|
|
|
|
|
+ if (Separator <> ' ') and (s[i] = ' ') then
|
|
Continue;
|
|
Continue;
|
|
|
|
|
|
- if (s[i] = dateseparator) or ((i = length(s)) and (s[i] in ['0'..'9'])) then
|
|
|
|
|
|
+ if (s[i] = separator) or ((i = len) and (s[i] in ['0'..'9'])) then
|
|
begin
|
|
begin
|
|
inc(n);
|
|
inc(n);
|
|
if n>3 then
|
|
if n>3 then
|
|
- Raise EConvertError.CreateFmt(SInvalidDateFormat,[s]);
|
|
|
|
|
|
+ begin
|
|
|
|
+ FixErrorMsg(SInvalidDateFormat,s);
|
|
|
|
+ exit;
|
|
|
|
+ end;
|
|
// Check if the year has more then two digits (if n=yp, then we are evaluating the year.)
|
|
// Check if the year has more then two digits (if n=yp, then we are evaluating the year.)
|
|
if (n=yp) and (length(s1)>2) then YearMoreThenTwoDigits := True;
|
|
if (n=yp) and (length(s1)>2) then YearMoreThenTwoDigits := True;
|
|
val(s1, values[n], c);
|
|
val(s1, values[n], c);
|
|
if c<>0 then
|
|
if c<>0 then
|
|
- Raise EConvertError.CreateFmt(SInvalidDateFormat,[s]);
|
|
|
|
|
|
+ begin
|
|
|
|
+ FixErrorMsg(SInvalidDateFormat,s);
|
|
|
|
+ Exit;
|
|
|
|
+ end;
|
|
s1 := '';
|
|
s1 := '';
|
|
end
|
|
end
|
|
else if not (s[i] in ['0'..'9']) then
|
|
else if not (s[i] in ['0'..'9']) then
|
|
- Raise EConvertError.CreateFmt(SInvalidDateFormat,[s]);
|
|
|
|
|
|
+ begin
|
|
|
|
+ FixErrorMsg(SInvalidDateFormat,s);
|
|
|
|
+ Exit;
|
|
|
|
+ end;
|
|
end ;
|
|
end ;
|
|
// Fill in values.
|
|
// Fill in values.
|
|
getLocalTime(LocalTime);
|
|
getLocalTime(LocalTime);
|
|
@@ -438,52 +464,104 @@ begin
|
|
end;
|
|
end;
|
|
if (y >= 0) and (y < 100) and not YearMoreThenTwoDigits then
|
|
if (y >= 0) and (y < 100) and not YearMoreThenTwoDigits then
|
|
begin
|
|
begin
|
|
- ly := ly - TwoDigitYearCenturyWindow;
|
|
|
|
|
|
+ ly := ly - defs.TwoDigitYearCenturyWindow;
|
|
Inc(Y, ly div 100 * 100);
|
|
Inc(Y, ly div 100 * 100);
|
|
- if (TwoDigitYearCenturyWindow > 0) and (Y < ly) then
|
|
|
|
|
|
+ if (defs.TwoDigitYearCenturyWindow > 0) and (Y < ly) then
|
|
Inc(Y, 100);
|
|
Inc(Y, 100);
|
|
end;
|
|
end;
|
|
Result := EncodeDate(y, m, d);
|
|
Result := EncodeDate(y, m, d);
|
|
-end ;
|
|
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+function StrToDate(const S: PChar; Len : integer; const useformat : string; separator : char = #0): TDateTime;
|
|
|
|
+
|
|
|
|
+Var
|
|
|
|
+ MSg : AnsiString;
|
|
|
|
+
|
|
|
|
+begin
|
|
|
|
+ Result:=IntStrToDate(Msg,S,Len,useFormat,DefaultFormatSettings,Separator);
|
|
|
|
+ If (Msg<>'') then
|
|
|
|
+ Raise EConvertError.Create(Msg);
|
|
|
|
+end;
|
|
|
|
|
|
|
|
+function StrToDate(const S: ShortString; const useformat : string; separator : char = #0): TDateTime;
|
|
|
|
+begin
|
|
|
|
+ result := StrToDate(@S[1],Length(s),UseFormat,separator);
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+function StrToDate(const S: AnsiString; const useformat : string; separator : char = #0): TDateTime;
|
|
|
|
+begin
|
|
|
|
+ result := StrToDate(@S[1],Length(s),UseFormat,separator);
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+function StrToDate(const S: ShortString; separator : char): TDateTime;
|
|
|
|
+begin
|
|
|
|
+ result := StrToDate(@S[1],Length(s),ShortDateFormat,separator)
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+function StrToDate(const S: ShortString): TDateTime;
|
|
|
|
+begin
|
|
|
|
+ result := StrToDate(@S[1],Length(s),ShortDateFormat,#0);
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+function StrToDate(const S: AnsiString; separator : char): TDateTime;
|
|
|
|
+begin
|
|
|
|
+ result := StrToDate(@S[1],Length(s),ShortDateFormat,separator)
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+function StrToDate(const S: AnsiString): TDateTime;
|
|
|
|
+begin
|
|
|
|
+ result := StrToDate(@S[1],Length(s),ShortDateFormat,#0);
|
|
|
|
+end;
|
|
|
|
|
|
{ StrToTime converts the string S to a TDateTime value
|
|
{ StrToTime converts the string S to a TDateTime value
|
|
if S does not represent a valid time value an
|
|
if S does not represent a valid time value an
|
|
EConvertError will be raised }
|
|
EConvertError will be raised }
|
|
|
|
|
|
-function StrToTime(const s: string): TDateTime;
|
|
|
|
|
|
+function IntStrToTime(Out ErrorMsg : AnsiString; const S: PChar; Len : integer;const defs:TFormatSettings; separator : char = #0): TDateTime;
|
|
var
|
|
var
|
|
- Len, Current: integer; PM: integer;
|
|
|
|
|
|
+ Current: integer; PM: integer;
|
|
|
|
+
|
|
|
|
+ function StrPas(Src : PChar; len: integer = 0) : ShortString;
|
|
|
|
+ var
|
|
|
|
+ tmp : integer;
|
|
|
|
+ begin
|
|
|
|
+ {tmp := IndexChar(Src[0], len, #0);
|
|
|
|
+ len :=ifthen(tmp >= 0, tmp, len);
|
|
|
|
+ len :=ifthen(len > 255, 255, len);}
|
|
|
|
+ SetLength(Result, len);
|
|
|
|
+ move(src[0],result[1],len);
|
|
|
|
+ end;
|
|
|
|
|
|
function GetElement: integer;
|
|
function GetElement: integer;
|
|
var
|
|
var
|
|
j, c: integer;
|
|
j, c: integer;
|
|
|
|
+ CurrentChar : Char;
|
|
begin
|
|
begin
|
|
result := -1;
|
|
result := -1;
|
|
- Inc(Current);
|
|
|
|
- while (result = -1) and (Current <= Len) do
|
|
|
|
|
|
+ while (result = -1) and (Current < Len) do
|
|
begin
|
|
begin
|
|
- if S[Current] in ['0'..'9'] then
|
|
|
|
|
|
+ CurrentChar := S[Current];
|
|
|
|
+ if CurrentChar in ['0'..'9'] then
|
|
begin
|
|
begin
|
|
j := Current;
|
|
j := Current;
|
|
- while (Current < Len) and (s[Current + 1] in ['0'..'9']) do
|
|
|
|
|
|
+ while (Current+1 < Len) and (s[Current + 1] in ['0'..'9']) do
|
|
Inc(Current);
|
|
Inc(Current);
|
|
- val(copy(S, j, 1 + Current - j), result, c);
|
|
|
|
|
|
+ val(StrPas(S+j, 1 + current - j), result, c);
|
|
end
|
|
end
|
|
- else if ((TimeAMString<>'') and (S[Current] = TimeAMString[1])) or (S[Current] in ['a', 'A']) then
|
|
|
|
|
|
+ else if ((defs.TimeAMString<>'') and (CurrentChar = defs.TimeAMString[1])) or (S[Current] in ['a', 'A']) then
|
|
begin
|
|
begin
|
|
pm:=1;
|
|
pm:=1;
|
|
Current := 1 + Len;
|
|
Current := 1 + Len;
|
|
end
|
|
end
|
|
- else if ((TimePMString<>'') and (S[Current] = TimePMString[1])) or (S[Current] in ['p', 'P']) then
|
|
|
|
|
|
+ else if ((defs.TimePMString<>'') and (CurrentChar = defs.TimePMString[1])) or (S[Current] in ['p', 'P']) then
|
|
begin
|
|
begin
|
|
Current := 1 + Len;
|
|
Current := 1 + Len;
|
|
PM := 2;
|
|
PM := 2;
|
|
end
|
|
end
|
|
- else if (S[Current] = TimeSeparator) or (S[Current] = ' ') then
|
|
|
|
|
|
+ else if (CurrentChar = Separator) or (CurrentChar = ' ') then
|
|
Inc(Current)
|
|
Inc(Current)
|
|
else
|
|
else
|
|
- raise EConvertError.Create('Invalid Time format');
|
|
|
|
|
|
+ ErrorMsg:=Format(SErrInvalidTimeFormat,[StrPas(S)]);
|
|
end ;
|
|
end ;
|
|
end ;
|
|
end ;
|
|
|
|
|
|
@@ -492,17 +570,23 @@ var
|
|
TimeValues: array[0..4] of integer;
|
|
TimeValues: array[0..4] of integer;
|
|
|
|
|
|
begin
|
|
begin
|
|
|
|
+ if separator = #0 then
|
|
|
|
+ separator := defs.TimeSeparator;
|
|
Current := 0;
|
|
Current := 0;
|
|
- Len := length(s);
|
|
|
|
PM := 0;
|
|
PM := 0;
|
|
for i:=0 to 4 do
|
|
for i:=0 to 4 do
|
|
timevalues[i]:=0;
|
|
timevalues[i]:=0;
|
|
i := 0;
|
|
i := 0;
|
|
TimeValues[i] := GetElement;
|
|
TimeValues[i] := GetElement;
|
|
|
|
+ If ErrorMsg<>'' then
|
|
|
|
+ Exit;
|
|
while (i < 5) and (TimeValues[i] <> -1) do
|
|
while (i < 5) and (TimeValues[i] <> -1) do
|
|
begin
|
|
begin
|
|
i := i + 1;
|
|
i := i + 1;
|
|
|
|
+ Inc(Current);
|
|
TimeValues[i] := GetElement;
|
|
TimeValues[i] := GetElement;
|
|
|
|
+ If ErrorMsg<>'' then
|
|
|
|
+ Exit;
|
|
end ;
|
|
end ;
|
|
If (i<5) and (TimeValues[I]=-1) then
|
|
If (i<5) and (TimeValues[I]=-1) then
|
|
TimeValues[I]:=0;
|
|
TimeValues[I]:=0;
|
|
@@ -519,39 +603,96 @@ begin
|
|
result := EncodeTime(TimeValues[0], TimeValues[1], TimeValues[2], TimeValues[3]);
|
|
result := EncodeTime(TimeValues[0], TimeValues[1], TimeValues[2], TimeValues[3]);
|
|
end ;
|
|
end ;
|
|
|
|
|
|
|
|
+function StrToTime(const S: PChar; Len : integer; separator : char = #0): TDateTime;
|
|
|
|
+
|
|
|
|
+Var
|
|
|
|
+ Msg : AnsiString;
|
|
|
|
+
|
|
|
|
+begin
|
|
|
|
+ Result:=IntStrToTime(Msg,S,Len,DefaultFormatSettings,Separator);
|
|
|
|
+ If (Msg<>'') then
|
|
|
|
+ Raise EConvertError.Create(Msg);
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+function StrToTime(const s: ShortString; separator : char): TDateTime;
|
|
|
|
+begin
|
|
|
|
+ result := StrToTime(@s[1], length(s), separator);
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+function StrToTime(const s: AnsiString; separator : char): TDateTime;
|
|
|
|
+begin
|
|
|
|
+ result := StrToTime(@s[1], length(s), separator);
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+function StrToTime(const s: ShortString): TDateTime;
|
|
|
|
+begin
|
|
|
|
+ result := StrToTime(@s[1], length(s), #0);
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+function StrToTime(const s: AnsiString): TDateTime;
|
|
|
|
+begin
|
|
|
|
+ result := StrToTime(@s[1], length(s), #0);
|
|
|
|
+end;
|
|
|
|
+
|
|
{ StrToDateTime converts the string S to a TDateTime value
|
|
{ StrToDateTime converts the string S to a TDateTime value
|
|
if S does not represent a valid date and/or time value
|
|
if S does not represent a valid date and/or time value
|
|
an EConvertError will be raised }
|
|
an EConvertError will be raised }
|
|
|
|
|
|
function StrToDateTime(const s: string): TDateTime;
|
|
function StrToDateTime(const s: string): TDateTime;
|
|
var
|
|
var
|
|
- i, j, k, l: integer;
|
|
|
|
- sd, st: string;
|
|
|
|
-begin
|
|
|
|
- l := Length(s);
|
|
|
|
- i := 1;
|
|
|
|
- while (i <= l) and (s[i] = ' ') do
|
|
|
|
- Inc(i);
|
|
|
|
- j := i;
|
|
|
|
- while (j <= l) and (s[j] <> ' ') do
|
|
|
|
- Inc(j);
|
|
|
|
- k := j;
|
|
|
|
- while (k <= l) and (s[k] = ' ') do
|
|
|
|
- Inc(k);
|
|
|
|
- sd := Copy(s, i, j - i);
|
|
|
|
- st := Copy(s, k, l);
|
|
|
|
- if (st = '') and (Pos(TimeSeparator, sd) > 0) then
|
|
|
|
- begin
|
|
|
|
- st := sd;
|
|
|
|
- sd := '';
|
|
|
|
- end;
|
|
|
|
- if (sd <> '') and (st <> '') then
|
|
|
|
- Result := ComposeDateTime(StrToDate(sd), StrToTime(st))
|
|
|
|
- else if st = '' then
|
|
|
|
- Result := StrToDate(sd)
|
|
|
|
|
|
+ I: integer;
|
|
|
|
+begin
|
|
|
|
+ I:=Pos(TimeSeparator,S);
|
|
|
|
+ If (I>0) then
|
|
|
|
+ begin
|
|
|
|
+ While (I>0) and (S[I]<>' ') do
|
|
|
|
+ Dec(I);
|
|
|
|
+ If I>0 then
|
|
|
|
+ result:=ComposeDateTime(StrToDate(Copy(S,1,I-1)),StrToTime(Copy(S,i+1, Length(S)-i)))
|
|
|
|
+ else
|
|
|
|
+ result:=StrToTime(S)
|
|
|
|
+ end
|
|
else
|
|
else
|
|
- Result := StrToTime(st);
|
|
|
|
-end ;
|
|
|
|
|
|
+ Result:=StrToDate(S);
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+function StrToDateTime(const s: AnsiString; const UseFormat : TFormatSettings): TDateTime;
|
|
|
|
+var
|
|
|
|
+ I: integer;
|
|
|
|
+begin
|
|
|
|
+ I:=Pos(TimeSeparator,S);
|
|
|
|
+ If (I>0) then
|
|
|
|
+ begin
|
|
|
|
+ While (I>0) and (S[I]<>' ') do
|
|
|
|
+ Dec(I);
|
|
|
|
+ If I>0 then
|
|
|
|
+ result:=ComposeDateTime(StrToDate(Copy(S,1,I-1),UseFormat.ShortDateFormat,UseFormat.DateSeparator),
|
|
|
|
+ StrToTime(Copy(S,i+1, Length(S)-i),UseFormat.TimeSeparator))
|
|
|
|
+ else
|
|
|
|
+ result:=StrToTime(S,UseFormat.TimeSeparator)
|
|
|
|
+ end
|
|
|
|
+ else
|
|
|
|
+ Result:=StrToDate(S,UseFormat.ShortDateFormat,UseFormat.DateSeparator);
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+function StrToDateTime(const s: ShortString; const UseFormat : TFormatSettings): TDateTime;
|
|
|
|
+var
|
|
|
|
+ I: integer;
|
|
|
|
+begin
|
|
|
|
+ I:=Pos(TimeSeparator,S);
|
|
|
|
+ If (I>0) then
|
|
|
|
+ begin
|
|
|
|
+ While (I>0) and (S[I]<>' ') do
|
|
|
|
+ Dec(I);
|
|
|
|
+ If I>0 then
|
|
|
|
+ result:=ComposeDateTime(StrToDate(Copy(S,1,I-1),UseFormat.ShortDateFormat,UseFormat.DateSeparator),
|
|
|
|
+ StrToTime(Copy(S,i+1, Length(S)-i),UseFormat.TimeSeparator))
|
|
|
|
+ else
|
|
|
|
+ result:=StrToTime(S,UseFormat.TimeSeparator)
|
|
|
|
+ end
|
|
|
|
+ else
|
|
|
|
+ Result:=StrToDate(S,UseFormat.ShortDateFormat,UseFormat.DateSeparator);
|
|
|
|
+end;
|
|
|
|
|
|
{ FormatDateTime formats DateTime to the given format string FormatStr }
|
|
{ FormatDateTime formats DateTime to the given format string FormatStr }
|
|
|
|
|
|
@@ -818,38 +959,121 @@ begin
|
|
end;
|
|
end;
|
|
{$endif unix}
|
|
{$endif unix}
|
|
|
|
|
|
-// ieuw. These should be written to work without exceptions?
|
|
|
|
-function TryStrToDate(const S: string; out Value: TDateTime): Boolean;
|
|
|
|
- begin
|
|
|
|
- result:=true;
|
|
|
|
- try
|
|
|
|
- value:=StrToDate(s);
|
|
|
|
- except
|
|
|
|
- on EConvertError do
|
|
|
|
- result:=false
|
|
|
|
|
|
+function TryStrToDate(const S: ShortString; out Value: TDateTime): Boolean;
|
|
|
|
+begin
|
|
|
|
+ result := TryStrToDate(S, Value, #0);
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+function TryStrToDate(const S: ShortString; out Value: TDateTime;
|
|
|
|
+ const useformat : string; separator : char = #0): Boolean;
|
|
|
|
+
|
|
|
|
+Var
|
|
|
|
+ Msg : Ansistring;
|
|
|
|
+
|
|
|
|
+begin
|
|
|
|
+ Value:=IntStrToDate(Msg,@S[1],Length(S),useformat,defaultformatsettings,separator);
|
|
|
|
+ Result:=(Msg='');
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+function TryStrToDate(const S: AnsiString; out Value: TDateTime;
|
|
|
|
+ const useformat : string; separator : char = #0): Boolean;
|
|
|
|
+
|
|
|
|
+Var
|
|
|
|
+ Msg : Ansistring;
|
|
|
|
+
|
|
|
|
+begin
|
|
|
|
+ Result:=Length(S)<>0;
|
|
|
|
+ If Result then
|
|
|
|
+ begin
|
|
|
|
+ Value:=IntStrToDate(Msg,@S[1],Length(S),useformat,DefaultFormatSettings,Separator);
|
|
|
|
+ Result:=(Msg='');
|
|
end;
|
|
end;
|
|
- end;
|
|
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+function TryStrToDate(const S: ShortString; out Value: TDateTime; separator : char): Boolean;
|
|
|
|
+begin
|
|
|
|
+ Result:=TryStrToDate(S,Value,ShortDateFormat,Separator);
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+function TryStrToDate(const S: AnsiString; out Value: TDateTime): Boolean;
|
|
|
|
+begin
|
|
|
|
+ Result:=TryStrToDate(S,Value,ShortDateFormat,#0);
|
|
|
|
+end;
|
|
|
|
|
|
|
|
+function TryStrToDate(const S: AnsiString; out Value: TDateTime; separator : char): Boolean;
|
|
|
|
+
|
|
|
|
+begin
|
|
|
|
+ Result:=TryStrToDate(S,Value,ShortDateFormat,Separator);
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+function TryStrToDate(const S: string; out Value: TDateTime; const FormatSettings: TFormatSettings): Boolean;
|
|
|
|
+Var
|
|
|
|
+ Msg : Ansistring;
|
|
|
|
+
|
|
|
|
+begin
|
|
|
|
+ Result:=Length(S)<>0;
|
|
|
|
+ If Result then
|
|
|
|
+ begin
|
|
|
|
+ Value:=IntStrToDate(Msg,@S[1],Length(S),FormatSettings.ShortDateFormat,FormatSettings,#0);
|
|
|
|
+ Result:=(Msg='');
|
|
|
|
+ end;
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+function TryStrToTime(const S: ShortString; out Value: TDateTime; separator : char): Boolean;
|
|
|
|
+
|
|
|
|
+Var
|
|
|
|
+ Msg : AnsiString;
|
|
|
|
+begin
|
|
|
|
+ Value:=IntStrToTime(Msg,@S[1],Length(S),DefaultFormatSettings,Separator);
|
|
|
|
+ result:=(Msg='');
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+function TryStrToTime(const S: ShortString; out Value: TDateTime): Boolean;
|
|
|
|
+begin
|
|
|
|
+ Result := TryStrToTime(S,Value,#0);
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+function TryStrToTime(const S: AnsiString; out Value: TDateTime; separator : char): Boolean;
|
|
|
|
+Var
|
|
|
|
+ Msg : AnsiString;
|
|
|
|
+begin
|
|
|
|
+ Result:=Length(S)<>0;
|
|
|
|
+ If Result then
|
|
|
|
+ begin
|
|
|
|
+ Value:=IntStrToTime(Msg,@S[1],Length(S),DefaultFormatSettings,Separator);
|
|
|
|
+ Result:=(Msg='');
|
|
|
|
+ end;
|
|
|
|
+end;
|
|
|
|
|
|
-// function TryStrToDate(const S: string; out Value: TDateTime; const FormatSettings: TFormatSettings): Boolean;
|
|
|
|
|
|
+function TryStrToTime(const S: AnsiString; out Value: TDateTime): Boolean;
|
|
|
|
+begin
|
|
|
|
+ result := TryStrToTime(S,Value,#0);
|
|
|
|
+end;
|
|
|
|
|
|
|
|
+function TryStrToTime(const S: string; out Value: TDateTime; const FormatSettings: TFormatSettings): Boolean;
|
|
|
|
+Var msg : AnsiString;
|
|
|
|
+begin
|
|
|
|
+ Result:=Length(S)<>0;
|
|
|
|
+ If Result then
|
|
|
|
+ begin
|
|
|
|
+ Value:=IntStrToTime(Msg,@S[1],Length(S),FormatSettings,#0);
|
|
|
|
+ Result:=(Msg='');
|
|
|
|
+ end;
|
|
|
|
+end;
|
|
|
|
|
|
-function TryStrToTime(const S: string; out Value: TDateTime): Boolean;
|
|
|
|
|
|
+function TryStrToDateTime(const S: ShortString; out Value: TDateTime): Boolean;
|
|
begin
|
|
begin
|
|
result:=true;
|
|
result:=true;
|
|
try
|
|
try
|
|
- value:=StrToTime(s);
|
|
|
|
|
|
+ value:=StrToDateTime(s);
|
|
except
|
|
except
|
|
on EConvertError do
|
|
on EConvertError do
|
|
result:=false
|
|
result:=false
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
|
|
-
|
|
|
|
-// function TryStrToTime(const S: string; out Value: TDateTime; const FormatSettings: TFormatSettings): Boolean;
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-function TryStrToDateTime(const S: string; out Value: TDateTime): Boolean;
|
|
|
|
|
|
+function TryStrToDateTime(const S: AnsiString; out Value: TDateTime): Boolean;
|
|
begin
|
|
begin
|
|
result:=true;
|
|
result:=true;
|
|
try
|
|
try
|
|
@@ -860,28 +1084,88 @@ function TryStrToDateTime(const S: string; out Value: TDateTime): Boolean;
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
+function TryStrToDateTime(const S: string; out Value: TDateTime; const FormatSettings: TFormatSettings): Boolean;
|
|
|
|
+var
|
|
|
|
+ I: integer;
|
|
|
|
+ dtdate, dttime :TDateTime;
|
|
|
|
+begin
|
|
|
|
+ result:=true;
|
|
|
|
+ I:=Pos(FormatSettings.TimeSeparator,S);
|
|
|
|
+ If (I>0) then
|
|
|
|
+ begin
|
|
|
|
+ While (I>0) and (S[I]<>' ') do
|
|
|
|
+ Dec(I);
|
|
|
|
+ If I>0 then
|
|
|
|
+ begin
|
|
|
|
+ if not TryStrToDate(Copy(S,1,I-1),dtdate,Formatsettings) then
|
|
|
|
+ exit;
|
|
|
|
+ if not TryStrToTime(Copy(S,i+1, Length(S)-i),dttime,Formatsettings) then
|
|
|
|
+ exit;
|
|
|
|
+ Value:=ComposeDateTime(dtdate,dttime);
|
|
|
|
+ end
|
|
|
|
+ else
|
|
|
|
+ result:=TryStrToTime(s,Value,Formatsettings);
|
|
|
|
+ end
|
|
|
|
+ else
|
|
|
|
+ result:=TryStrToDate(s,Value,Formatsettings);
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+function StrToDateDef(const S: ShortString; const Defvalue : TDateTime): TDateTime;
|
|
|
|
+begin
|
|
|
|
+ result := StrToDateDef(S,DefValue,#0);
|
|
|
|
+end;
|
|
|
|
|
|
-// function TryStrToDateTime(const S: string; out Value: TDateTime; const FormatSettings: TFormatSettings): Boolean;
|
|
|
|
|
|
+function StrToTimeDef(const S: ShortString; const Defvalue : TDateTime): TDateTime;
|
|
|
|
+begin
|
|
|
|
+ result := StrToTimeDef(S,DefValue,#0);
|
|
|
|
+end;
|
|
|
|
|
|
|
|
+function StrToDateTimeDef(const S: ShortString; const Defvalue : TDateTime): TDateTime;
|
|
|
|
+begin
|
|
|
|
+ if not TryStrToDateTime(s,Result) Then
|
|
|
|
+ result:=defvalue;
|
|
|
|
+end;
|
|
|
|
|
|
-function StrToDateDef(const S: string; const Defvalue : TDateTime): TDateTime;
|
|
|
|
|
|
+function StrToDateDef(const S: ShortString; const Defvalue : TDateTime; separator : char): TDateTime;
|
|
begin
|
|
begin
|
|
- if not TryStrToDate(s,Result) Then
|
|
|
|
|
|
+ if not TryStrToDate(s,Result, separator) Then
|
|
result:=defvalue;
|
|
result:=defvalue;
|
|
end;
|
|
end;
|
|
|
|
|
|
-function StrToTimeDef(const S: string; const Defvalue : TDateTime): TDateTime;
|
|
|
|
|
|
+function StrToTimeDef(const S: ShortString; const Defvalue : TDateTime; separator : char): TDateTime;
|
|
begin
|
|
begin
|
|
- if not TryStrToTime(s,Result) Then
|
|
|
|
|
|
+ if not TryStrToTime(s,Result, separator) Then
|
|
result:=defvalue;
|
|
result:=defvalue;
|
|
end;
|
|
end;
|
|
|
|
|
|
-function StrToDateTimeDef(const S: string; const Defvalue : TDateTime): TDateTime;
|
|
|
|
|
|
+function StrToDateDef(const S: AnsiString; const Defvalue : TDateTime): TDateTime;
|
|
|
|
+begin
|
|
|
|
+ result := StrToDateDef(S,DefValue,#0);
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+function StrToTimeDef(const S: AnsiString; const Defvalue : TDateTime): TDateTime;
|
|
|
|
+begin
|
|
|
|
+ result := StrToTimeDef(S,DefValue,#0);
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+function StrToDateTimeDef(const S: AnsiString; const Defvalue : TDateTime): TDateTime;
|
|
begin
|
|
begin
|
|
if not TryStrToDateTime(s,Result) Then
|
|
if not TryStrToDateTime(s,Result) Then
|
|
result:=defvalue;
|
|
result:=defvalue;
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
+function StrToDateDef(const S: AnsiString; const Defvalue : TDateTime; separator : char): TDateTime;
|
|
|
|
+begin
|
|
|
|
+ if not TryStrToDate(s,Result, separator) Then
|
|
|
|
+ result:=defvalue;
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+function StrToTimeDef(const S: AnsiString; const Defvalue : TDateTime; separator : char): TDateTime;
|
|
|
|
+begin
|
|
|
|
+ if not TryStrToTime(s,Result, separator) Then
|
|
|
|
+ result:=defvalue;
|
|
|
|
+end;
|
|
|
|
+
|
|
procedure ReplaceTime(var dati:TDateTime; NewTime : TDateTime);inline;
|
|
procedure ReplaceTime(var dati:TDateTime; NewTime : TDateTime);inline;
|
|
begin
|
|
begin
|
|
dati:= ComposeDateTime(dati, newtime);
|
|
dati:= ComposeDateTime(dati, newtime);
|