* add unix timezone test

git-svn-id: trunk@47322 -
This commit is contained in:
ondrej 2020-11-05 12:53:51 +00:00
parent 3ee2097f1a
commit 691fb2c9fe
2 changed files with 44 additions and 0 deletions

1
.gitattributes vendored
View File

@ -16175,6 +16175,7 @@ tests/test/units/sysutils/twstrcmp.pp svneol=native#text/plain
tests/test/units/types/ttbitconverter.pp svneol=native#text/pascal
tests/test/units/ucomplex/tcsqr1.pp svneol=native#text/pascal
tests/test/units/unix/tepoch1.pp svneol=native#text/pascal
tests/test/units/unix/ttimezone1.pp svneol=native#text/pascal
tests/test/units/variants/tcustomvariant.pp svneol=native#text/plain
tests/test/units/variants/tvararrayofintf.pp svneol=native#text/plain
tests/test/units/variants/tw26370.pp svneol=native#text/plain

View File

@ -0,0 +1,43 @@
{ %target=linux,freebsd,openbsd,aix,darwin,netbsd }
uses
BaseUnix,unix;
function GetOffset(Year, Month, Day, Hour, Minute, Second: word; const UTC: Boolean): Integer;
var
UnixTime: Int64;
lTZInfo: TTZInfo;
begin
lTZInfo:=Default(TTZInfo);
UnixTime:=UniversalToEpoch(Year, Month, Day, Hour, Minute, Second);
if not GetLocalTimezone(UnixTime,UTC,lTZInfo) then
Halt(1);
if not UTC then
UnixTime := UnixTime-lTZInfo.seconds;
if not ((lTZInfo.validsince<=UnixTime) and (UnixTime<lTZInfo.validuntil)) then
Halt(2);
if lTZInfo.seconds mod 3600<>0 then
Halt(3);
Result:=lTZInfo.seconds div 3600;
end;
begin
if not ReadTimezoneFile('Europe/Vienna') then // check against Europe/Vienna file
begin
writeln('timezone file not found');
halt(10);
end;
if GetOffset(2019, 03, 31, 1, 59, 0, False)<>1 then Halt(11);
if GetOffset(2019, 03, 31, 3, 0, 0, False)<>2 then Halt(12);
if GetOffset(2019, 10, 27, 2, 59, 0, False)<>2 then Halt(13);
if GetOffset(2019, 10, 27, 3, 0, 0, False)<>1 then Halt(14);
if GetOffset(2019, 03, 31, 0, 59, 0, True)<>1 then Halt(15);
if GetOffset(2019, 03, 31, 1, 0, 0, True)<>2 then Halt(16);
if GetOffset(2019, 10, 27, 0, 59, 0, True)<>2 then Halt(17);
if GetOffset(2019, 10, 27, 1, 0, 0, True)<>1 then Halt(18);
writeln('ok');
end.