Postgres Timezone change

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
rchostakovis
Posts: 5
Joined: Sat 24 Oct 2009 20:59

Postgres Timezone change

Post by rchostakovis » Sat 24 Oct 2009 21:02

Hi,

How do I change the timezone of Postgres session?

Thanks

Roberto Chostakovis

Plash
Devart Team
Posts: 2844
Joined: Wed 10 May 2006 07:09

Post by Plash » Mon 26 Oct 2009 09:05

You should execute the following SQL command:

Code: Select all

  SET TIME ZONE 

rchostakovis
Posts: 5
Joined: Sat 24 Oct 2009 20:59

Post by rchostakovis » Mon 26 Oct 2009 15:36

Hi,

I tried this using TUniSql but it doesn´t work.

UniDAC appears to use the computer´s time zone and not allow to change this.

Running the scripts (select and timezone change) manually works fine.

Regards

Roberto Chostakovis

Plash
Devart Team
Posts: 2844
Joined: Wed 10 May 2006 07:09

Post by Plash » Tue 27 Oct 2009 09:15

UniDAC always uses the computer time zone for TIMESTAMP WITH TIMEZONE fields. UniDAC does not use PostgreSQL client, and UniDAC does not contain the time conversion rules for all time zones. UniDAC uses time conversion rules from Windows settings.

rchostakovis
Posts: 5
Joined: Sat 24 Oct 2009 20:59

Post by rchostakovis » Tue 27 Oct 2009 11:04

How do I change this?

I am using UniDAC in a webserver application that runs under GMT+0.

I have users from many timezones using it and I have to convert the timestamp for their location.

I have to be able at least to sum or subtract # hours from timestamp. How I do that?

Regards

Roberto Chostakovis

rchostakovis
Posts: 5
Joined: Sat 24 Oct 2009 20:59

Post by rchostakovis » Tue 27 Oct 2009 11:15

Could you please tell me where the conversion take place in source code?

My subscription include source code and I can try to create a workaround.

Regards

Roberto Chostakovis

Plash
Devart Team
Posts: 2844
Joined: Wed 10 May 2006 07:09

Post by Plash » Wed 28 Oct 2009 10:09

See the UTCTimeToLocalTime function in the PgObjects unit.

rchostakovis
Posts: 5
Joined: Sat 24 Oct 2009 20:59

Post by rchostakovis » Wed 28 Oct 2009 12:13

Thank you! I got how it works and create a workaround.

I´ve changed the PgObjectsUni.pas in the following ways:

1 - Change the TimeZoneInformation variable to UniDACPgTimeZoneInfomation and moved it to Interface section, making it Global.

2 - Changed the functions that use this variable.

3 - The UniDACPgTimeZoneInformation is initialized as it was, with no change.

On my projet, I include PgObjectsUni at uses clausule and at runtime changed the bias value to reflect the timezone that I want.

I think that is a very simple way to give flexibility to UniDAC to handle with timezones.

Would you like that I send the PgObjectsUni.pas to you?

Regards

Roberto Chostakovis

Plash
Devart Team
Posts: 2844
Joined: Wed 10 May 2006 07:09

Post by Plash » Thu 29 Oct 2009 08:21

We have made such changes ourselves:

We have renamed TimeZoneInformation to PgTimeZoneInformation and placed it to the interface section. This fix will be included in the next UniDAC build.

Post Reply