Subject | Re: time zone problem |
---|---|
Author | rwilcom |
Post date | 2004-07-29T17:56:38Z |
FYI: decodeTimestamp(..) method has the same problem (referencing
the local machine's time zone).
--- In Firebird-Java@yahoogroups.com, "rwilcom" <ron.wilcom@n...>
wrote:
the local machine's time zone).
--- In Firebird-Java@yahoogroups.com, "rwilcom" <ron.wilcom@n...>
wrote:
> I believe I have found the bug in the JayBird JDBC code - theclass:
> following method is defined in the org.firebirdsql.gds.XSQLVAR
>());
> public Timestamp encodeTimestamp(java.sql.Timestamp value,
> Calendar cal){
> if (cal == null) {
> return value;
> }
> else {
> long time = value.getTime() -
> (cal.getTimeZone().getRawOffset() -
> Calendar.getInstance().getTimeZone().getRawOffset
>is
> return new Timestamp(time);
> }
> }
>
> I think the bug is the use of "Calendar.getInstance().getTimeZone
> ().getRawOffset());" and the subtraction since that line of code
> getting the local machine's time zone to perform the time zonethis
> conversion calculation (which it should *never* do) shouldn't
> just simply be:use
>
> long time = value.getTime() + cal.getTimeZone().getRawOffset();
>
> This simply take the UTC and addes (or subtracts if negative) the
> passed calendar object's offset value.
>
> ??thoughts??
>
> Ron
>
>
> --- In Firebird-Java@yahoogroups.com, "Rick DeBay" <rdebay@r...>
> wrote:
> > Be wary of using static Calendars and parsers. They set instance
> > variables during calculations, and if you use the same parser at
> the
> > same time in two different threads, they'll step on each others'
> > results.
> >
> > -----Original Message-----
> > From: rwilcom [mailto:ron.wilcom@n...]
> > Sent: Thursday, July 29, 2004 8:54 AM
> > To: Firebird-Java@yahoogroups.com
> > Subject: [Firebird-Java] Re: time zone problem
> >
> > Roman,
> >
> > I believe I am setting the timezone correctly for the calendar
> > object - setting as follows:
> >
> > private static final Calendar GMT = Calendar.getInstance
> > (TimeZone.getTimeZone("GMT") );
> >
> > I am using the machine locale (which would be US/en) but that
> should
> > not impact the time zone. Reminder, if I change the OS timezone
> > setting the inserted date value changes!? This should never be
> the
> > case when using:
> >
> > ps.setTimestamp(1, new java.sql.Timestamp( testDateTime.getTime
> ()),
> > GMT );
> >
> > Even if the calander object was wrongly set to a different
> timezone
> > the entry inserted into the database should be consistent even
> when
> > the OS timezone is changed. The driver should not relay on or
> > the OS timezone setting to calculate the date/time entry fromthe
> > UTC millisec value?!JDBC
> >
> > Also - I did upgrade to RC4 and the same problem occurs.
> >
> > From my code snippet below you should easily be able to recreate
> > this problem. Please advise! Meanwhile, I will look into the
> > source code.testDateTime.getTime
> >
> > thanks,
> > Ron
> >
> > start code snippet-----------------------
> >
> >
> > //assuming you have a connection object
> > //already connected via JayBird JDBC
> >
> > Calendar GMT = Calendar.getInstance(TimeZone.getTimeZone
> > ("GMT") ); //machine locale
> > PreparedStatement ps = null;
> > try {
> > ps = connection.prepareStatement("INSERT INTO MyTable(id,
> > dateAndtimeInGMT) VALUES (?, ?)");
> >
> > ps.setInt(1, 1 );
> >
> > Date testDate = format.parse("02-10-2004 10:00:00 EST");
> > ps.setTimestamp(2, new java.sql.Timestamp( testDate.getTime
> ()),
> > GMT );
> >
> > ps.executeUpdate();
> >
> > //check the database value; this will be
> > //dependent on your OS time zone
> > //not on the GMT calculated value;
> > //After running this once change
> > //your OS time zone and run again -
> > //a different date/time value is inserted
> > }
> > catch (SQLException e){
> > System.out.println("error:"+e.toString());
> > }
> > finally{
> > try{ps.close();}
> > catch(Exception any){/*nothing*/}
> > }
> >
> >
> > end code snippet-----------------------
> >
> >
> > --- In Firebird-Java@yahoogroups.com, "Roman Rokytskyy"
> > <rrokytskyy@a...> wrote:
> > > > Date testDateTime= format.parse("02-10-2004 10:00:00 EST");
> > >
> > > > ps.setTimestamp(1, new java.sql.Timestamp(
> > ()),
> > > > GMT );
> > >
> > > Please ensure that your GMT calendar has the time zone set
> > correctly (i.e.
> > > it is not the default time zone). If you still believe that
> there
> > is a bug,
> > > please prepare a test case that reproduces the problem.
> > >
> > > If you want to check sources, please see
> > > org.firebirdsql.jdbc.field.FBTimestampField and
> > org.firebirdsql.gds.XSQLVAR
> > > classes.
> > >
> > > Roman
> >
> >
> >
> >
> >
> > Yahoo! Groups Links