diff --git a/.gitattributes b/.gitattributes index 91f96ccef7..5541a41f1d 100644 --- a/.gitattributes +++ b/.gitattributes @@ -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 diff --git a/tests/test/units/unix/ttimezone1.pp b/tests/test/units/unix/ttimezone1.pp new file mode 100644 index 0000000000..ec85e9cf50 --- /dev/null +++ b/tests/test/units/unix/ttimezone1.pp @@ -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 (UnixTime0 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.