View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0038577 | FPC | RTL | public | 2021-03-03 16:50 | 2021-03-03 16:52 |
Reporter | wp | Assigned To | |||
Priority | normal | Severity | minor | Reproducibility | have not tried |
Status | new | Resolution | open | ||
Summary | 0038577: FormatDateTime with option fdoInterval not showing leading zeros | ||||
Description | The function FormatDateTime can be set up to display hours > 23 (or minutes or seconds > 59) by using the corresponding parameter in square brackets. However, the result string does not display leading zeros even when the format string tells that it should. Example FormatDateTime('[hh]:nn:ss.zzz', t, [fdoInterval]), for t = 8:30:15 displays the hour as single-digit number, although the format string tells that it should use a leading zero when the value is < 10. The attached patch fixes the issue. | ||||
Steps To Reproduce | Run this simple test program: program Project1; uses SysUtils; procedure Test(t: TDateTime; AFormatString: String; Expected: String); var s: String; begin s := FormatDateTime(AFormatString, t, [fdoInterval]); Write(TimeToStr(t):15, AFormatString:20, Expected:20, s:20); if s = Expected then WriteLn('OK':8) else WriteLn('ERROR':8); end; var t: TDateTime; begin WriteLn('Time':15, 'Format string':20, 'Expected':20, 'Result':20); WriteLn; t := EncodeTime(8, 30, 15, 0); Test(t, '[h]:nn:ss.zzz', '8:30:15.000'); Test(t, '[hh]:nn:ss.zzz', '08:30:15.000'); t := EncodeTime(0, 8, 15, 0); Test(t, '[n]:ss', '8:15'); Test(t, '[nn]:ss', '08:15'); t := EncodeTime(0, 0, 8, 216); Test(t, '[s].zzz', '8.216'); Test(t, '[ss].zzz','08.216'); ReadLn; end. The output of the current version of FormatDateTime is Time Format string Expected Result 08:30:15 [h]:nn:ss.zzz 8:30:15.000 8:30:15.000 OK 08:30:15 [hh]:nn:ss.zzz 08:30:15.000 8:30:15.000 ERROR 00:08:15 [n]:ss 8:15 8:15 OK 00:08:15 [nn]:ss 08:15 8:15 ERROR 00:00:08 [s].zzz 8.216 8.216 OK 00:00:08 [ss].zzz 08.216 8.216 ERROR After application of the patch the output is correct: Time Format string Expected Result 08:30:15 [h]:nn:ss.zzz 8:30:15.000 8:30:15.000 OK 08:30:15 [hh]:nn:ss.zzz 08:30:15.000 08:30:15.000 OK 00:08:15 [n]:ss 8:15 8:15 OK 00:08:15 [nn]:ss 08:15 08:15 OK 00:00:08 [s].zzz 8.216 8.216 OK 00:00:08 [ss].zzz 08.216 08.216 OK | ||||
Tags | No tags attached. | ||||
Fixed in Revision | |||||
FPCOldBugId | |||||
FPCTarget | |||||
Attached Files |
|
|
dati.inc.patch (1,286 bytes)
Index: rtl/objpas/sysutils/dati.inc =================================================================== --- rtl/objpas/sysutils/dati.inc (revision 48682) +++ rtl/objpas/sysutils/dati.inc (working copy) @@ -1139,7 +1139,7 @@ end ; 'H': if isInterval then - StoreInt(Hour + trunc(abs(DateTime))*24, 0) + StoreInt(Hour + trunc(abs(DateTime))*24, Count) else if Clock12 then begin @@ -1157,7 +1157,7 @@ StoreInt(Hour, 2); end; 'N': if isInterval then - StoreInt(Minute + (Hour + trunc(abs(DateTime))*24)*60, 0) + StoreInt(Minute + (Hour + trunc(abs(DateTime))*24)*60, Count) else if Count = 1 then StoreInt(Minute, 0) @@ -1164,7 +1164,7 @@ else StoreInt(Minute, 2); 'S': if isInterval then - StoreInt(Second + (Minute + (Hour + trunc(abs(DateTime))*24)*60)*60, 0) + StoreInt(Second + (Minute + (Hour + trunc(abs(DateTime))*24)*60)*60, Count) else if Count = 1 then StoreInt(Second, 0) |
|
(sorry - pasting in the test results was not a good idea...) |