java.time support

66 views
Skip to first unread message

blackh...@gmail.com

unread,
Oct 9, 2024, 8:10:50 AMOct 9
to GWT Users
LS,

I have seen several discussions about support for java.time, but i do not fully understand what the current status is.
Our project currently depends on Java.util.Date, but there is an issue with this Date and the year 2038. 
Are there plans to add support for the java.time package in GWT or do we need to go for another approach?

Jens

unread,
Oct 9, 2024, 8:39:28 AMOct 9
to GWT Users
Nobody is working on integrating java.time into GWT SDK. There is an external project which has emulated java.time based on reference implementation of java.time before it was integrated into Java 1.8. Changes to java.time between Java 1.8 and current Java are not part of that project as far as I know.


GWT itself currently uses the browser's JavaScript Date and some helper methods to emulate java.util.Date. What is your issue with year 2038?

-- J.

Jasper Suijker

unread,
Oct 9, 2024, 9:36:28 AMOct 9
to google-we...@googlegroups.com
Here is a link about the year 2038 problem: https://en.wikipedia.org/wiki/Year_2038_problem
 

Op wo 9 okt 2024 om 14:39 schreef Jens <jens.ne...@gmail.com>:
--
You received this message because you are subscribed to the Google Groups "GWT Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-tool...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-web-toolkit/49d56f8c-839b-4ed6-92a1-8288cb1e407en%40googlegroups.com.

Jens

unread,
Oct 9, 2024, 10:51:01 AMOct 9
to GWT Users
Here is a link about the year 2038 problem: https://en.wikipedia.org/wiki/Year_2038_problem

Ah ok, thats where you are coming from.

JavaScript/ECMAScript defines that JavaScript Date supports exactly 100000000 days before and after unix epoch. This gives us a maximum year of 275760 that JavaScript Date can currently represent.

Java itself uses a long to represent millis since epoch in java.util.Date. Because long is 64 bit the maximum year that java.util.Date can represent is 292278994.

JavaScript: 275760
Java: 292278994

Since GWT emulates java.util.Date using native JavaScript Date the max year in GWT code is the one of JavaScript.

In any case year 2038 shouldn't be a problem, thats why I asked. You can easily verify it in browser console using

var millis = Date.parse("2040-06-01");
var date = new Date(millis);
console.log(date);

-- J. 

Jasper Suijker

unread,
Oct 9, 2024, 11:08:42 AMOct 9
to google-we...@googlegroups.com
So web is not going to be worried, but... :) 
We have user interfaces for both thick (swing) and web using dates and now we need to use java.util.Date as this is supported by GWT.
Is there a way to use anything else than java.util.Date that is supported by GWT? 

Op wo 9 okt 2024 om 16:51 schreef Jens <jens.ne...@gmail.com>:
--
You received this message because you are subscribed to the Google Groups "GWT Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-tool...@googlegroups.com.

Colin Alworth

unread,
Oct 9, 2024, 12:26:28 PMOct 9
to GWT Users
On the server, java.util.Date is unaffected as Jens pointed out - it is not backed by a 32-bit int, but a 64-bit int. Your swing and web implementations will be able to use java.util.Date beyond 2038:

Here's plain Java, using jshell to demonstrate that this will work with much larger dates than a decade away:

jshell> new java.util.Date(Long.MAX_VALUE)
$1 ==> Sun Aug 17 01:12:55 CST 292278994


As he also pointed out, you _can_ use java.time using the linked package, but the java.time APIs are not very conducive to emulation in the browser, so any emulation will always be a subset of the full possible functionality that a regular JVM has.

Leon Pennings

unread,
Oct 10, 2024, 1:34:43 AMOct 10
to GWT Users
Hi Jasper,

besides the fact that you don't need to worry for java.util.Date until the year 292278994, there is always the possibility to implement your own value object for a Date in GWT.
You can also use 3 party custom Date implementations too, as long as you include the source for the GWT compiler, and as long as that implementation is based on GWT supported building blocks.

rg,

Leon.

Op woensdag 9 oktober 2024 om 18:26:28 UTC+2 schreef Colin Alworth:
Reply all
Reply to author
Forward
0 new messages