Browse Source

+ patch by Denis Kozlov to add date/time tokens: %DATEYEAR%, %DATEMONTH%, %DATEDAY%, %TIMEHOUR%, %TIMEMINUTE%, %TIMESECOND%
+ test

git-svn-id: trunk@38329 -

florian 7 năm trước cách đây
mục cha
commit
c671683e80
5 tập tin đã thay đổi với 58 bổ sung2 xóa
  1. 1 0
      .gitattributes
  2. 2 1
      compiler/compiler.pas
  3. 7 1
      compiler/globals.pas
  4. 30 0
      compiler/scanner.pas
  5. 18 0
      tests/webtbs/tw26472.pp

+ 1 - 0
.gitattributes

@@ -15608,6 +15608,7 @@ tests/webtbs/tw2643.pp svneol=native#text/plain
 tests/webtbs/tw2645.pp svneol=native#text/plain
 tests/webtbs/tw26467.pp svneol=native#text/pascal
 tests/webtbs/tw2647.pp svneol=native#text/plain
+tests/webtbs/tw26472.pp svneol=native#text/pascal
 tests/webtbs/tw26481.pp svneol=native#text/pascal
 tests/webtbs/tw26482.pp svneol=native#text/pascal
 tests/webtbs/tw26483.pp svneol=native#text/pascal

+ 2 - 1
compiler/compiler.pas

@@ -252,7 +252,8 @@ begin
        SetExceptionMask([exInvalidOp, exDenormalized, exZeroDivide,
                          exOverflow, exUnderflow, exPrecision]);
 
-       starttime:=getrealtime;
+       GetLocalTime(startsystime);
+       starttime := getrealtime(startsystime);
 
        { Initialize the compiler }
        InitCompiler(cmd);

+ 7 - 1
compiler/globals.pas

@@ -539,10 +539,12 @@ interface
 
     var
       starttime  : real;
+      startsystime : TSystemTime;
 
     function getdatestr:string;
     function gettimestr:string;
     function filetimestring( t : longint) : string;
+    function getrealtime(const st: TSystemTime) : real;
     function getrealtime : real;
 
     procedure DefaultReplacements(var s:ansistring);
@@ -825,13 +827,17 @@ implementation
        Result := L0(Year)+'/'+L0(Month)+'/'+L0(Day)+' '+L0(Hour)+':'+L0(min)+':'+L0(sec);
      end;
 
+   function getrealtime(const st: TSystemTime) : real;
+     begin
+       result := st.Hour*3600.0 + st.Minute*60.0 + st.Second + st.MilliSecond/1000.0;
+     end;
 
    function getrealtime : real;
      var
        st:TSystemTime;
      begin
        GetLocalTime(st);
-       result:=st.Hour*3600.0+st.Minute*60.0+st.Second+st.MilliSecond/1000.0;
+       result:=getrealtime(st);
      end;
 
 {****************************************************************************

+ 30 - 0
compiler/scanner.pas

@@ -2439,6 +2439,36 @@ type
                hs:=gettimestr;
              'DATE':
                hs:=getdatestr;
+             'DATEYEAR':
+               begin
+                 hs:=tostr(startsystime.Year);
+                 macroIsString:=false;
+               end;
+             'DATEMONTH':
+               begin
+                 hs:=tostr(startsystime.Month);
+                 macroIsString:=false;
+               end;
+             'DATEDAY':
+               begin
+                 hs:=tostr(startsystime.Day);
+                 macroIsString:=false;
+               end;
+             'TIMEHOUR':
+               begin
+                 hs:=tostr(startsystime.Hour);
+                 macroIsString:=false;
+               end;
+             'TIMEMINUTE':
+               begin
+                 hs:=tostr(startsystime.Minute);
+                 macroIsString:=false;
+               end;
+             'TIMESECOND':
+               begin
+                 hs:=tostr(startsystime.Second);
+                 macroIsString:=false;
+               end;
              'FILE':
                hs:=current_module.sourcefiles.get_file_name(current_filepos.fileindex);
              'LINE':

+ 18 - 0
tests/webtbs/tw26472.pp

@@ -0,0 +1,18 @@
+uses
+  SysUtils, DateUtils;
+const
+  Year = {$I %DATEYEAR%};
+  Month = {$I %DATEMONTH%};
+  Day = {$I %DATEDAY%};
+  Hour = {$I %TIMEHOUR%};
+  Minute = {$I %TIMEMINUTE%};
+  Second = {$I %TIMESECOND%};
+var
+  Date, Time, DateTime: TDateTime;
+begin
+  Date := EncodeDate(Year, Month, Day);
+  Time := EncodeTime(Hour, Minute, Second, 0);
+  DateTime := ComposeDateTime(Date, Time);
+  WriteLn('Built at: ', DateTimeToStr(DateTime));
+  WriteLn('Time ago: ', SecondsBetween(DateTime, Now), ' seconds');
+end.