You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
fpc/fpc-3.2.0--honor_SOURCE_DAT...

52 lines
1.9 KiB

--- compiler/globals.pas 2020-01-26 11:40:37.848057995 +0100
+++ compiler/globals.pas 2020-01-26 11:40:31.014043335 +0100
@@ -559,8 +559,9 @@
startsystime : TSystemTime;
function getdatestr:string;
function gettimestr:string;
+ Function UnixToDateTime(const AValue: Int64): TDateTime;
function filetimestring( t : longint) : string;
function getrealtime(const st: TSystemTime) : real;
function getrealtime : real;
@@ -816,13 +817,34 @@
get the current date in a string YY/MM/DD
}
var
st: TSystemTime;
+ Year, Month, Day: Word;
+ SourceDateEpoch: string;
begin
- GetLocalTime(st);
- getdatestr:=L0(st.Year)+'/'+L0(st.Month)+'/'+L0(st.Day);
- end;
-
+ SourceDateEpoch := GetEnvironmentVariable('SOURCE_DATE_EPOCH');
+ if Length(SourceDateEpoch)>0 then begin
+ DecodeDate(UnixToDateTime(StrToInt64(SourceDateEpoch)),year,month,day);
+ getdatestr:=L0(Year)+'/'+L0(Month)+'/'+L0(Day)
+ end else begin
+ GetLocalTime(st);
+ getdatestr:=L0(st.Year)+'/'+L0(st.Month)+'/'+L0(st.Day)
+ end
+ end;
+
+ Function UnixToDateTime(const AValue: Int64): TDateTime;
+ { Code copied from fpcsrc/packages/rtl-objpas/src/inc/dateutil.inc and
+ fpcsrc/rtl/objpas/sysutils/datih.inc }
+ const
+ TDateTimeEpsilon = 2.2204460493e-16 ;
+ UnixEpoch = TDateTime(-2415018.5) + TDateTime(2440587.5) ;
+ begin
+ Result:=UnixEpoch + AValue/SecsPerDay;
+ if (UnixEpoch>=0) and (Result<-TDateTimeEpsilon) then
+ Result:=int(Result-1.0+TDateTimeEpsilon)-frac(1.0+frac(Result))
+ // else if (UnixEpoch<=-1.0) and (Result>-1.0+TDateTimeEpsilon) then
+ // Result:=int(Result+1.0-TDateTimeEpsilon)+frac(1.0-abs(frac(1.0+Result)));
+ end;
function filetimestring( t : longint) : string;
{
convert dos datetime t to a string YY/MM/DD HH:MM:SS