Page 1 of 1

Improving Time Fields fractional seconds display

Posted: 24.11.2020, 20:18
by MJFShark
Hi all!

I fixed some minor bugs recently in the time and datetime display for fractional seconds. I kept the code the same besides the fix, but it is a bit odd in the way that it works.

Case 1:
if your timeformat is "simple" (i.e. it ends with the fractional seconds), then they are concatenated to the end of the string and trailing zeros are not trimmed. e.g. 12:21:03.1230

Case 2:
If your timeformat is not simple (usually because it ends with an AM or PM indicator), then the current code puts the fractional time at the correct position, and then removes any trailing zeros. This causes a bit of an issue if the fractional time is zero, as the decimal character is not removed (so you can get a time that shows '12:21:03. AM' (note the '.')

My first thought was that the solution would just be not removing the trailing zeros, but it seems that Firebird doesn't actually tell you the current scale of a timestamp, so it's always 4, and that ends up looking a bit odd.

So I *think* the best solution is to always trim the trailing zeros on the fractional time including the decimal char. Any thoughts?

-Mark

Re: Improving Time Fields fractional seconds display

Posted: 24.11.2020, 22:29
by marsupilami
Hello Mark,

this is from the Firebird 2.5 language reference:
3.4.2. TIME wrote:The TIME data type is available in Dialect 3 only. It stores the time of day within the range from 00:00:00.0000 to 23:59:59.9999
For me that means that in the case of Firebird we should always have a precision of 4 fractional parts of seconds because that is what this datatype is. If a user wants to display times in a different way, we have the parameters DateDisplayFormat, TimeDisplayFormat and DateTimeDisplayFormat to influence the way dates and times get displayed.

Best regards,

Jan

Re: Improving Time Fields fractional seconds display

Posted: 25.11.2020, 01:00
by Fr0sT
From my FB utils:

Code: Select all

const
  IBTimeScaleStart: array[1..3] of Word = (17, 11, 1858); // November 17, 1858
  IBTimeScale_TDateTime_Delta = 15018; // [days] TDateTime(0) - IBTimeScaleStart
  TIME_MSEC_PRECISION = TIME_SECONDS_PRECISION div MSecsPerSec; // timestamp_time is in msec/10 units

implementation

function IBTimestampToDateTime(Epoch: TISC_TIMESTAMP): TDateTime;
begin
  Result := IncDay(0, Epoch.timestamp_date - IBTimeScale_TDateTime_Delta);
  Result := IncMilliSecond(Result, Epoch.timestamp_time div TIME_MSEC_PRECISION);
end;
So yes, timestamp in FB is always in 1/10 of msec

Re: Improving Time Fields fractional seconds display

Posted: 08.12.2020, 18:00
by EgonHugeist
Mark,

the question is correct. Thoughts:

if the format has a fraction indicator(ie. '.'/dot) then the fractions should be displayed as:

if the fraction part is shorter than the left fractional part the minimal fractions should be displayed.
Example: Format is: "....HH:NN:SS.F/Z" and NanoFraction are 999.000.000 than the right zeoroes shoud be padded away: Result would be "HH.NN.SS.999"

if the fraction part is longer than the left fractional part the maximum fractions should be displayed.
Example: Format is: "....HH:NN:SS.FFFFFFFFF/ZZZZZZZZZ" and NanoFraction are 90.000 then the Result should be: "HH.NN.SS.000900000"

A trainling dot should never be display...

Do you agree?