[fpc-devel] TimeReFormat in FormatDateTime

petr.kristan at epos.cz petr.kristan at epos.cz
Tue Apr 8 18:27:58 CEST 2008


On Tue, Apr 08, 2008 at 06:12:15PM +0200, petr.kristan at epos.cz wrote:
> On Tue, Apr 08, 2008 at 05:54:40PM +0200, Michael Van Canneyt wrote:
> > 
> > 
> > On Tue, 8 Apr 2008, petr.kristan at epos.cz wrote:
> > 
> > > On Tue, Apr 08, 2008 at 05:23:04PM +0200, Michael Van Canneyt wrote:
> > > > 
> > > > 
> > > > On Tue, 8 Apr 2008, petr.kristan at epos.cz wrote:
> > > > 
> > > > > On Tue, Apr 08, 2008 at 04:32:30PM +0200, Michael Van Canneyt wrote:
> > > > > > 
> > > > > > 
> > > > > > On Tue, 8 Apr 2008, petr.kristan at epos.cz wrote:
> > > > > > 
> > > > > > > I do no know exact reason use TimeReFormat (replacing 'm'->'n' in time
> > > > > > > formating). But we cannot use this, because this breaks 'am/pm' and 'ampm' formating request.
> > > > > > > And we get 'Illegal character in format string'.
> > > > > > > 
> > > > > > > Here is little patch, which disables this behaviour.
> > > > > > 
> > > > > > 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.
> > > > > But this feature works without TimeReFormat hack. Here is piece of code
> > > > > from dati.inc:
> > > > 
> > > > > 
> > > > >  'M': begin
> > > > >        if lastformattoken='H' then
> > > > >          begin
> > > > >            if Count = 1 then
> > > > >              StoreInt(Minute, 0)
> > > > >            else
> > > > >              StoreInt(Minute, 2);
> > > > > 
> > > > >          end
> > > > >        else
> > > > >          begin
> > > > >            case Count of
> > > > >               1: StoreInt(Month, 0);
> > > > >               2: StoreInt(Month, 2);
> > > > >               3: StoreString(ShortMonthNames[Month]);
> > > > >               4: StoreString(LongMonthNames[Month]);
> > > > >            end;
> > > > >          end;
> > > > >     end;
> > > > > 
> > > > > Next TimeReFormat cannot work correctly, because FormatString is case
> > > > > insensitive and comparison "If Result[i]='m'" leaves this out of account.
> > > > 
> > > > Did you test it ? If you can confirm that hh:mm:ss works correctly, then
> > > > I'll apply the patch.
> > > Sure, I tested it. hh:mm:ss and hh:nn:ss works identically.
> > > But isn't cleaner solution remove TimeReFormat completly?
> > 
> > I meant: did you test with TimeReFormat removed ? :)
> Yes. I tested it with dissabled functionality of TimeReFormat:
> 
>    Function TimeReFormat(Const S : string) : string;
>    // Change m into n for time formatting.
>    //Var i : longint;
> 
>    begin
>      Result:=S;
>      {For I:=1 to Length(Result) do //We cannot do that, am/pm does not then work
>        If Result[i]='m' then
>          result[i]:='n';}
>    end;
> 
> But I think, that cleaner will be remove function TimeReFormat completly
> not only dissable functionality (superfluous call).
In the attachment is patch with TimeReFormat removed. Patch is tested, 
hh:mm:ss and hh:nn:ss works identically.

Petr

-- 
Ing. Petr Kristan
.
EPOS PRO s.r.o., Bozeny Nemcove 2625, 530 02 Pardubice
tel: +420 466335223    Czech Republic (Eastern Europe) 
fax: +420 466510709
-------------- next part --------------
Index: objpas/sysutils/dati.inc
===================================================================
--- objpas/sysutils/dati.inc	(revision 10597)
+++ objpas/sysutils/dati.inc	(working copy)
@@ -567,17 +567,6 @@
    StoreStr(pchar(@S[1]), Len);
    end ;
 
-   Function TimeReFormat(Const S : string) : string;
-   // Change m into n for time formatting.
-   Var i : longint;
-
-   begin
-     Result:=S;
-     For I:=1 to Length(Result) do
-       If Result[i]='m' then
-         result[i]:='n';
-   end;
-
 var
    Year, Month, Day, DayOfWeek, Hour, Minute, Second, MilliSecond: word;
 
@@ -716,8 +705,8 @@
                       else StoreInt(MilliSecond, 3);
                       end ;
                    'T': begin
-                      if Count = 1 then StoreFormat(timereformat(ShortTimeFormat))
-                      else StoreFormat(TimeReformat(LongTimeFormat));
+                      if Count = 1 then StoreFormat(ShortTimeFormat)
+                      else StoreFormat(LongTimeFormat);
                       end ;
                    'C':
                      begin
@@ -725,7 +714,7 @@
                        if (Hour<>0) or (Minute<>0) or (Second<>0) then
                         begin
                           StoreString(' ');
-                          StoreFormat(TimeReformat(LongTimeFormat));
+                          StoreFormat(LongTimeFormat);
                         end;
                      end;
                 end;


More information about the fpc-devel mailing list