Several problems:
TTimestamp = record
date.isbc : SmallInt;
date.year : SmallInt;
date.mon : ShortInt;
date.mday : SmallInt;
time.hour : ShortInt;
time.min : ShortInt;
time.sec : ShortInt;
time.usec : SmallInt;
time.gmtoff : SmallInt;
end;
Where did you get this definition from? libpqtypes.h says (
http://libpqtypes.esilo.com/browse_source.html?file=libpqtypes.h)
257 typedef struct
258 {
259 int isbc;
260 int year;
261 int mon;
262 int mday;
263 int jday;
264 int yday;
265 int wday;
266 } PGdate;
267
268 typedef struct
269 {
270 int hour;
271 int min;
272 int sec;
273 int usec;
274 int withtz;
275 int isdst;
276 int gmtoff;
277 char tzabbr[16];
278 } PGtime;
279
280 typedef struct
281 {
282 PGint8 epoch;
283 PGdate date;
284 PGtime time;
285 } PGtimestamp;
AFAIK PGtimestamp is relatively new and will cause quite some backwards compatibility problems.
PQgetf(res,CurTuple,'%pg_catalog.timestamptz',x,ts);
How did you define PQgetf? It is one of these functions that accept a variable number of parameters like printf. So your declaration should be something like
function PQgetf(...., array of const):longint;cdecl;
and the call should look like
PQgetf(res,CurTuple,'%pg_catalog.timestamptz',[x,ts]);
dbl := pointer(buffer)+ts.time.gmtoff;
dbl is pdouble. You change the pointer while you intend to change the value. You can better change the line
dbl^ := dbl^ / SecsPerDay;
with
dbl^ := (dbl^+ts.time.gmtoff) / SecsPerDay;
A solution is to execute the query
select now(),cast(now() as timestamp without time zone)
calculate the difference between the 2 times and store that as the timezone correction.
Edit: Or even simpler, offset in seconds
SELECT extract(timezone FROM now())