Re: Storing timestamps in text format

From: Radosław Smogura <rsmogura(at)softperience(dot)eu>
To: Dave Cramer <pg(at)fastcrypt(dot)com>
Cc: <pgsql-jdbc(at)postgresql(dot)org>
Subject: Re: Storing timestamps in text format
Date: 2010-12-01 11:39:30
Message-ID: a6ab29e93a5b9fdc7e8e6acdbdb1e325@smogura-softworks.eu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc


On Wed, 1 Dec 2010 05:38:41 -0500, Dave Cramer <pg(at)fastcrypt(dot)com> wrote:
> On Fri, Nov 26, 2010 at 1:28 PM, Radosław Smogura
> <rsmogura(at)softperience(dot)eu> wrote:
>> Hi,
>>
>> I perform following test:
>> 1. Open connection (GMT+1)
>> 2. Change timezone (GMT+3)
>> 3. Write created timestamp.
>> 4. Change timezone to different connection open and write (GMT+4)
>> 5. Read timezone
>>
>> During this I saw driver sends timestamp encoded with initial (in my
case
>> +1), form connection open, time zone. It's because
>> TimestampUtils.toString(Calendar, Timestamp) uses defaultCal. Should it
>> use
>> Calendar.getInstance() or new GregorianCalendar?
>>
>>    public synchronized String toString(Calendar cal, Timestamp x) {
>>        if (cal == null)
>>            cal = defaultCal; // = Calendar.getInstance() // new
>> GregorianCalendar()
>>
>
> What do you expect it to do?
>

I expect proper timestamps encoding store when sending timestamps to
server. To clarify test case:
3. ps.setTimestamp(Timestamp.valueOf("2010-01-01 11:10:12.345"));
4. Change timezone to different then connection open TZ and write TZ;
change to (GMT+4)
5. assertTrue(Timestamp.valueOf("2010-01-01 11:10:12.345"),
rs.getTimestamp(1).toStrig()) - will fail

It's because 3. binds following value "2010-01-01 09:10:12.345000
+01:00:00", instead of 2010-01-01 11:10:12.345+3, similarly will be for
read.

My test case shown:
The result value for #0 is invalid expected:<2010-01-01 11:10:12.345> but
was:<2010-01-01 12:10:12.345>
>>
>> --
>> ----------
>> Radosław Smogura
>> http://www.softperience.eu
>>
>> --
>> Sent via pgsql-jdbc mailing list (pgsql-jdbc(at)postgresql(dot)org)
>> To make changes to your subscription:
>> http://www.postgresql.org/mailpref/pgsql-jdbc
>>

--
----------
Radosław Smogura
http://www.softperience.eu

In response to

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Magnus Hagander 2010-12-01 11:47:13 Re: [HACKERS] Improved JDBC driver part 2
Previous Message Radosław Smogura 2010-12-01 11:17:54 Re: [HACKERS] Improved JDBC driver part 2