Improving Time Fields fractional seconds display

The offical for ZeosLib 7.3 Report problems, ask for help, post proposals for the new version of Zeoslib 7.3/v8
Quick Info:
-We made two new drivers: odbc(raw and unicode version) and oledb
-GUID domain/field-defined support for FB
-extended error infos of Firebird
-performance ups are still in queue
In future some more feature will arrive, so stay tuned and don't hassitate to help
Post Reply
MJFShark
Expert Boarder
Expert Boarder
Posts: 211
Joined: 04.06.2020, 13:59

Improving Time Fields fractional seconds display

Post 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
marsupilami
Platinum Boarder
Platinum Boarder
Posts: 1918
Joined: 17.01.2011, 14:17

Re: Improving Time Fields fractional seconds display

Post 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
Fr0sT
Zeos Dev Team
Zeos Dev Team
Posts: 280
Joined: 08.05.2014, 12:08

Re: Improving Time Fields fractional seconds display

Post 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
User avatar
EgonHugeist
Zeos Project Manager
Zeos Project Manager
Posts: 1936
Joined: 31.03.2011, 22:38

Re: Improving Time Fields fractional seconds display

Post 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?
Best regards, Michael

You want to help? http://zeoslib.sourceforge.net/viewtopic.php?f=4&t=3671
You found a (possible) bug? Use the new bugtracker dude! http://sourceforge.net/p/zeoslib/tickets/

Image
Post Reply