Skip to content

Commit

Permalink
Support all integer and real data types for displaying as Unix timest…
Browse files Browse the repository at this point in the history
  • Loading branch information
ansgarbecker committed Sep 17, 2016
1 parent 3e81d33 commit 24be88d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
14 changes: 8 additions & 6 deletions source/helpers.pas
Expand Up @@ -250,8 +250,8 @@ TAppSettings = class(TObject)
function EncodeURLParam(const Value: String): String;
procedure StreamWrite(S: TStream; Text: String = '');
function _GetFileSize(Filename: String): Int64;
function MakeInt( Str: String ) : Int64;
function MakeFloat( Str: String ): Extended;
function MakeInt(Str: String; FromLocaleFormat: Boolean=True) : Int64;
function MakeFloat(Str: String; FromLocaleFormat: Boolean=True): Extended;
function CleanupNumber(Str: String): String;
function IsNumeric(Str: String): Boolean;
function esc(Text: String; ProcessJokerChars: Boolean=false; DoQuote: Boolean=True): String;
Expand Down Expand Up @@ -555,11 +555,11 @@ function _GetFileSize(Filename: String): Int64;
@param string String-number
@return int64
}
function MakeInt(Str: String): Int64;
function MakeInt(Str: String; FromLocaleFormat: Boolean=True): Int64;
begin
// Result has to be of integer type
try
Result := Trunc(MakeFloat(Str));
Result := Trunc(MakeFloat(Str, FromLocaleFormat));
except
Result := 0;
end;
Expand Down Expand Up @@ -617,13 +617,15 @@ function IsNumeric(Str: String): Boolean;
@param String text representation of a number
@return Extended
}
function MakeFloat( Str: String ): Extended;
function MakeFloat(Str: String; FromLocaleFormat: Boolean=True): Extended;
var
p_kb, p_mb, p_gb, p_tb, p_pb : Integer;
begin
// Convert result to a floating point value to ensure
// we don't discard decimal digits for the next step
Result := StrToFloat(CleanupNumber(Str));
if FromLocaleFormat then
Str := CleanupNumber(Str);
Result := StrToFloat(Str);

// Detect if the string was previously formatted by FormatByteNumber
// and convert it back by multiplying it with its byte unit
Expand Down
6 changes: 3 additions & 3 deletions source/main.pas
Expand Up @@ -2344,7 +2344,7 @@ function TMainForm.HandleUnixTimestampColumn(Sender: TBaseVirtualTree; Column: T
// Shorthand for various places where we would normally have to add all these conditions
Result := (Sender = DataGrid)
and (Column > NoColumn)
and (DataGridResult.DataType(Column).Index in [dtInt, dtBigint])
and (DataGridResult.DataType(Column).Category in [dtcInteger, dtcReal])
and (SelectedTableTimestampColumns.IndexOf(DataGrid.Header.Columns[Column].Text) > -1);
end;

Expand Down Expand Up @@ -5361,7 +5361,7 @@ procedure TMainForm.ValidateControls(Sender: TObject);
Results.RecNo := RowNum^;
GridHasChanges := Results.Modified or Results.Inserted;
if Grid.FocusedColumn > NoColumn then
EnableTimestamp := Results.DataType(Grid.FocusedColumn).Index in [dtInt, dtBigint];
EnableTimestamp := Results.DataType(Grid.FocusedColumn).Category in [dtcInteger, dtcReal];
end;
end;
inDataTab := PageControlMain.ActivePage = tabData;
Expand Down Expand Up @@ -8450,7 +8450,7 @@ procedure TMainForm.AnyGridGetText(Sender: TBaseVirtualTree; Node: PVirtualNode;
if FGridCopying then begin
CellText := Results.Col(Column);
end else if HandleUnixTimestampColumn(Sender, Column) then begin
Timestamp := MakeInt(Results.Col(Column));
Timestamp := MakeInt(Results.Col(Column), False);
Dec(Timestamp, FTimeZoneOffset);
CellText := DateTimeToStr(UnixToDateTime(Timestamp));
end else begin
Expand Down

0 comments on commit 24be88d

Please sign in to comment.