diff --git a/components/fpspreadsheet/fpsnumformat.pas b/components/fpspreadsheet/fpsnumformat.pas index e773f078d..7d30b6aa2 100644 --- a/components/fpspreadsheet/fpsnumformat.pas +++ b/components/fpspreadsheet/fpsnumformat.pas @@ -51,6 +51,7 @@ function IsDateFormat(ANumFormat: TsNumFormatParams): Boolean; function IsTimeFormat(AFormat: TsNumberFormat): Boolean; overload; function IsTimeFormat(AFormatStr: String): Boolean; overload; function IsTimeFormat(ANumFormat: TsNumFormatParams): Boolean; overload; +function IsLongTimeFormat(AFormatStr: String; ATimeSeparator: char): Boolean; overload; function IsTimeIntervalFormat(ANumFormat: TsNumFormatParams): Boolean; @@ -186,6 +187,20 @@ begin (ANumFormat.Sections[0].Kind * [nfkTime] <> []); end; +{@@ ---------------------------------------------------------------------------- + Returns TRUE if the specified format string represents a long time format, i.e. + it contains two TimeSeparators. +-------------------------------------------------------------------------------} +function IsLongTimeFormat(AFormatStr: String; ATimeSeparator: Char): Boolean; +var + i, n: Integer; +begin + n := 0; + for i:=1 to Length(AFormatStr) do + if AFormatStr[i] = ATimeSeparator then inc(n); + Result := (n=2); +end; + {@@ ---------------------------------------------------------------------------- Checks whether the specified number format parameters is a time interval format. diff --git a/components/fpspreadsheet/fpspreadsheet.pas b/components/fpspreadsheet/fpspreadsheet.pas index c04a7072b..d12d24441 100755 --- a/components/fpspreadsheet/fpspreadsheet.pas +++ b/components/fpspreadsheet/fpspreadsheet.pas @@ -4017,15 +4017,18 @@ begin if TryStrToDateTime(AValue, number, FWorkbook.FormatSettings) then begin - if number < 1.0 then begin // this is a time alone - if not IsTimeFormat(numFmtParams) then begin - if SecondOf(number) = 0 then - WriteDateTime(ACell, number, nfShortTime) + if number < 1.0 then // this is a time alone + begin + if not IsTimeFormat(numFmtParams) then + begin + if IsLongTimeFormat(AValue, FWorkbook.FormatSettings.TimeSeparator) then + WriteDateTime(ACell, number, nfLongTime) else - WriteDateTime(ACell, number, nfLongTime); + WriteDateTime(ACell, number, nfShortTime); end; end else - if frac(number) = 0.0 then begin // this is a date alone + if frac(number) = 0.0 then // this is a date alone + begin if not IsDateFormat(numFmtParams) then WriteDateTime(ACell, number, nfShortDate); end else