I suggested that h2 should store timestamp as a long value signifying
milliseconds since Unix Epoch.
Most compact representation of time and leaves no room for
misinterpretation.
For the time being I would suggest route B.
And do all your timezone calculations in java because it seems to get
the timezone issues right.
That's what I do.
If you want timezone aware functions into H2 you can easily create your
own functions that can
utilize java's inherent power to deal with timezones.
- Rami
I think in most cases it's better to *not* convert the date/time to
UTC (Coordinated Universal Time) before storing, because of following
problem: Let's say you store a birthday in the database. After that,
you close the database, and move the database file to a different time
zone. Then you open the database and read the birthday. If the
date/time is converted to UTC, then the birthday might change, which
is completely unexpected. This is an extreme example (you could say
"birthdays don't contain the time"). But also for other cases it's
more common to store the date/time in the local time zone, so that
moving a database file will not change the value. Please note the
problem is only moving the database file.
I agree in some cases it would be better to convert the date to UTC,
but this you could also do in the application.
I think most databases ignore the time zone by default when using the
"normal" data types DATE, DATETIME, or TIMESTAMP (that means, the
value doesn't change if you move a database file to a different time
zone). If you think this isn't true please tell me which database, and
provide a reproducible test case. I'm very interested to make H2
compatible with other databases (I know some databases support
TIMESTAMP WITH TIME ZONE; this is not what I talk about - H2 simply
doesn't support storing the time zone - I'm talking about the normal
DATE, DATETIME and TIMESTAMP data types).
Regards,
Thomas
--
You received this message because you are subscribed to the Google Groups "H2 Database" group.
To post to this group, send email to h2-da...@googlegroups.com.
To unsubscribe from this group, send email to h2-database...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/h2-database?hl=en.
> DATE and TIME types have nothing to do with timezones.
Well, currently they do. See also ResultSet.getDate and getTime(...,
Calendar cal).
> TIMESTAMP refers to a point of time in the whole universe that can be shared
> by all possible calendar systems.
For certain use cases, yes. For other use cases, no. Let's say you
want to store a log file in the database. Of course you *could*
convert the timestamps to UTC. In this case you would get different
results depending on the timezone where you open the database file.
But in many cases people prefer to *not* convert the timestamp. If you
send a log file (that includes a timestamp column) to another country
then the timestamp in the log file doesn't magically change. You don't
*want* it to change. If it changes when you send the database file
then that's unexpected and therefore confusing. Maybe not for you, but
for others.
That's probably why all databases I know don't convert timestamps when
you send the database file to another time zone.
I'm not saying a new data type "TIMESTAMP WITH TIMEZONE" is not
needed. It would be a nice feature. But it's currently not
implemented.
Regards,
Thomas
There is a feature request to support timestamp with timezone. I will
increase the priority.
Regards,
Thomas
El 12/10/10 14:55, Thomas Mueller escribi�:
>> DATE and TIME types have nothing to do with timezones.
> Well, currently they do. See also ResultSet.getDate and getTime(...,
> Calendar cal).
Rami say and I agree, that date and time fields stored in a database must be "static" values that should never be adjusted in regards of client's TZ.
Only timestamps can be used for calendar conversions and arithmetic.
>> TIMESTAMP refers to a point of time in the whole universe that can be shared
>> by all possible calendar systems.
> For certain use cases, yes. For other use cases, no. Let's say you
> want to store a log file in the database. Of course you *could*
> convert the timestamps to UTC. In this case you would get different
> results depending on the timezone where you open the database file.
> But in many cases people prefer to *not* convert the timestamp. If you
> send a log file (that includes a timestamp column) to another country
> then the timestamp in the log file doesn't magically change. You don't
> *want* it to change. If it changes when you send the database file
> then that's unexpected and therefore confusing. Maybe not for you, but
> for others.
>
> That's probably why all databases I know don't convert timestamps when
> you send the database file to another time zone.
>
> I'm not saying a new data type "TIMESTAMP WITH TIMEZONE" is not
> needed. It would be a nice feature. But it's currently not
> implemented.
Thomas , again I understand that Rami say exactly the same thing.
He argues that timestamps by default default should also be static, and if you need TZ conversions (and you don't have timestamp with TZ) you can add an extra field to store origin TZ of this timestamps or convert always to GMT, making timestamp with time
zone data type a dispensable comfort feature.
regards,
Dario.
DATE and TIME types have nothing to do with timezones.Well, currently they do. See also ResultSet.getDate and getTime(..., Calendar cal).
TIMESTAMP refers to a point of time in the whole universe that can be shared by all possible calendar systems.For certain use cases, yes. For other use cases, no. Let's say you want to store a log file in the database. Of course you *could* convert the timestamps to UTC. In this case you would get different results depending on the timezone where you open the database file. But in many cases people prefer to *not* convert the timestamp. If you send a log file (that includes a timestamp column) to another country then the timestamp in the log file doesn't magically change. You don't *want* it to change. If it changes when you send the database file then that's unexpected and therefore confusing. Maybe not for you, but for others. That's probably why all databases I know don't convert timestamps when you send the database file to another time zone. I'm not saying a new data type "TIMESTAMP WITH TIMEZONE" is not needed. It would be a nice feature. But it's currently not implemented.
Please try to keep your responses short.
The documentation at
http://h2database.com/html/tutorial.html#date_time is incorrect, I
will change it to :
"If the time zone is not set, the value is parsed using the current
time zone setting of the system. Date and time information is stored
in H2 database files without time zone information. If the database is
opened using another system time zone, the date and time will be the
same.
That means if you store the value '2000-01-01 12:00:00' in one time
zone, then close the database and open the database again in a
different time zone, you will also get '2000-01-01 12:00:00'. Please
note that changing the time zone after the H2 driver is loaded is not
supported."
Example:
TimeZone.setDefault(TimeZone.getTimeZone("PST"));
// TimeZone.setDefault(TimeZone.getTimeZone("CET"));
Class.forName("org.h2.Driver");
String dir = "~/data/h2database/h2/data";
String url = "jdbc:h2:" + dir + "/test";
Connection conn = DriverManager.getConnection(url);
Statement stat = conn.createStatement();
stat.execute("create table if not exists test(x timestamp)");
stat.execute("insert into test values('2000-01-01 12:00:00')");
conn.close();
conn = DriverManager.getConnection(url);
stat = conn.createStatement();
ResultSet rs = stat.executeQuery("select * from test");
while(rs.next()) {
System.out.println(rs.getString(1));
}
Regards,
Thomas
I promise to try, but I find clear and explicit communication in higher
value
than the the sparsity of expression.
Now the documentation seems to me clear and concise.
It expresses everything in a pragmatic way using a concrete example.
Well done.
Still, I would propose a different implementation for the future
but I quess you knew that already ;-)
- Rami