[fpc-devel] TimeReFormat in FormatDateTime
sergei_gorelkin at mail.ru
Tue Apr 8 19:20:25 CEST 2008
Michael Van Canneyt wrote:
> It should not be disabled, but fixed properly.
> This code is there for a reason:
> Normal time formatting is hh:nn (n = minutes). But Delphi explicitly
> allows also hh:mm for time, even though mm is the placeholder for month.
I have a more complex patch, that fixes this issue together with a
number of others. Have a look.
a) Enables threadsafe versions of date/time formatting functions (this
was primary goal of the patching).
b) Favours case of AM/PM and A/P tokens, as Delphi does.
c) More tolerant to mistakes in format strings (e.g. 'mmmmm' and longer
will be treated as 'mmmm'; empty format string is treated as 'c' - again
d) Prevents possibility of endless recursion in certain cases of
malformed format settings, e.g. when ShortTimeFormat contains 't'.
Since format settings may come from anywhere (including untrusted
sources), this is an important security issue.
e) Refactored to exclude ansistring operations (except final setting of
result), this should increase performance.
As for TimeReformat, I excluded it primarily for performance reasons,
substituting with a flag that causes 'm' be treated as 'n' even if it is
not preceded by 'h'. This preserves existing logic as much as possible,
but am/pm tokens won't be affected because they are handled in another
branch of code.
The patch also refactors CurrentYear function to exclude unnecessary
date encoding and decoding.
I tested it locally on Russian locale and it works fine, however I
cannot guarantee that everything is correct on every locale.
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 3567 bytes
Desc: not available
More information about the fpc-devel