mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-17 13:39:36 +02:00
+ patch by Denis Kozlov to add date/time tokens: %DATEYEAR%, %DATEMONTH%, %DATEDAY%, %TIMEHOUR%, %TIMEMINUTE%, %TIMESECOND%
+ test git-svn-id: trunk@38329 -
This commit is contained in:
parent
ccbaf748b8
commit
c671683e80
1
.gitattributes
vendored
1
.gitattributes
vendored
@ -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
|
||||
|
@ -252,7 +252,8 @@ begin
|
||||
SetExceptionMask([exInvalidOp, exDenormalized, exZeroDivide,
|
||||
exOverflow, exUnderflow, exPrecision]);
|
||||
|
||||
starttime:=getrealtime;
|
||||
GetLocalTime(startsystime);
|
||||
starttime := getrealtime(startsystime);
|
||||
|
||||
{ Initialize the compiler }
|
||||
InitCompiler(cmd);
|
||||
|
@ -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;
|
||||
|
||||
{****************************************************************************
|
||||
|
@ -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
tests/webtbs/tw26472.pp
Normal file
18
tests/webtbs/tw26472.pp
Normal file
@ -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.
|
Loading…
Reference in New Issue
Block a user