[fpc-devel] Add {$I %DATETIME%}

wkitty42 at windstream.net wkitty42 at windstream.net
Tue Feb 23 19:19:35 CET 2016


On 02/23/2016 10:38 AM, Denis Kozlov wrote:
> On 23 February 2016 at 15:24, <wkitty42 at windstream.net
> <mailto:wkitty42 at windstream.net>> wrote:
>
>     is there something wrong with what is already available??
>
>
> Yes, as highlighted in my original post.

ahhh... sorry... i missed all that as it appeared similar to a signature over 
here...

> On 15 January 2016 at 21:23, Denis Kozlov wrote:
>
>     Benefits of this directive:
>     1) Access to build date/time in native TDateTime format. Existing {$I
>     %DATE%} and {$I %TIME%} are inserted as strings in predefined format,
>     parsing is required to extract date/time components or to reformat it.

is there a problem using sysutils' StrToDateTime() to convert to TDateTime? 
parsing is already done for you...

program compilerdatetime;

uses
   sysutils;

var
   formatSettings     : TFormatSettings;
   compiledatetime    : TDateTime;
   compiledatetimestr : string;

begin
   formatSettings := DefaultFormatSettings;
   formatSettings.DateSeparator   := '/';
   formatSettings.ShortDateFormat := 'yyyy/mm/dd';
   formatSettings.ShortTimeFormat := 'hh:nn:ss';
   writeln('DateTime Format : ',formatSettings.ShortDateFormat,' 
',formatSettings.ShortTimeFormat);

   compiledatetimestr := {$I %DATE%} + ' ' + {$I %TIME%};
   writeln('raw string      : ',compiledatetimestr);

   compiledatetime := StrToDateTime(compiledatetimestr,formatSettings);
   writeln('TDateTime       : ',compiledatetime);
   writeln('converted to str: ',DateTimeToStr(compiledatetime,formatSettings));
end.


TBH: i see and understand why this might be a good idea but i also see and 
understand why it is not desirable... for me, though, there are many times that 
i hex browse binaries to find such compiled on strings... using a floating point 
number for them doesn't allow such ease of finding this data... we won't mention 
the additional conversion needed to print it when the current method building 
with %DATE% and %TIME% are already strings... but of course there is the same 
need to convert to TDateTime if one wants to ""time bomb"" their binary so that 
it doesn't work after some period of time (eg: expiring beta, limited time 
evaluation, simple aging out of old versions)...

>     2) Atomic access to build date/time. Use of {$I %DATE%} and {$I %TIME%} can
>     have undesired effect if {$I %DATE%} is executed at 2016-01-15 23:59:59.999
>     and 1 ms later {$I %TIME%} is executed at 2016-01-16 00:00:00.000. Resulting
>     combination of two directive is 2016-01-15 00:00:00, a day out of date.

i recognize this race-type condition but it really won't come up that often to 
be bothersome, will it?

>     3) Search and replace of build date/time is no longer a trivial text editor
>     operation.

i haven't used that method in years... definitely not since i figured out how to 
embed them in TP6 code ;)

-- 
  NOTE: No off-list assistance is given without prior approval.
        *Please keep mailing list traffic on the list* unless
        private contact is specifically requested and granted.



More information about the fpc-devel mailing list