Ignore:
Timestamp:
Nov 15, 2012, 2:56:05 PM (12 years ago)
Author:
chronos
Message:
  • Opraveno: Editace časových údajů.
  • Opraveno: Generování ovládacích prvků v okně editace.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Packages/CoolWeb/Persistence/USqlDatabase.pas

    r16 r17  
    9191  function SQLToDateTime(Value: string): TDateTime;
    9292  function SQLToTime(Value: string): TDateTime;
     93  function SQLToDate(Value: string): TDateTime;
    9394  function DateTimeToSQL(Value: TDateTime): string;
    9495  function TimeToSQL(Value: TDateTime): string;
     
    173174end;
    174175
     176function SQLToDate(Value: string): TDateTime;
     177var
     178  DateParts: TListString;
     179  Date: TDateTime;
     180begin
     181  try
     182    DateParts := TListString.Create;
     183    DateParts.Explode(Value, '-', StrToStr);
     184    if TryEncodeDate(StrToInt(DateParts[0]), StrToInt(DateParts[1]),
     185      StrToInt(DateParts[2]), Date) then
     186        Result := Date else Result := 0;
     187  finally
     188    DateParts.Free;
     189  end;
     190end;
     191
    175192function DateTimeToSQL(Value: TDateTime): string;
    176193begin
    177   Result := FormatDateTime('yyyy-mm-dd hh.nn.ss', Value);
     194  Result := FormatDateTime('yyyy-mm-dd hh:nn:ss', Value);
    178195end;
    179196
    180197function TimeToSQL(Value: TDateTime): string;
    181198begin
    182   Result := FormatDateTime('hh.nn.ss', Value);
     199  Result := FormatDateTime('hh:nn:ss', Value);
    183200end;
    184201
     
    191208var
    192209  TimeParts: TListString;
     210  Time: TDateTime;
    193211begin
    194212  try
    195213    TimeParts := TListString.Create;
    196214    TimeParts.Explode(Value, ':', StrToStr);
    197     Result := Result + EncodeTime(StrToInt(TimeParts[0]), StrToInt(TimeParts[1]),
    198       StrToInt(TimeParts[2]), 0);
     215    if TryEncodeTime(StrToInt(TimeParts[0]), StrToInt(TimeParts[1]),
     216      StrToInt(TimeParts[2]), 0, time) then
     217        Result := Time else Result := 0;
    199218  finally
    200219    TimeParts.Free;
Note: See TracChangeset for help on using the changeset viewer.