gwtproject / gwt

GWT Open Source Project
http://www.gwtproject.org
1.52k stars 375 forks source link

javax.time (JSR-310) emulation #611

Open dankurka opened 9 years ago

dankurka commented 9 years ago

Originally reported on Google Code with ID 603

GWT Release: 1.3

Detailed description:
This is a feature request to include emulation for the java.util.Calendar
abstract class, and an implementation like GregorianCalendar. This would
make dealing with dates much better in GWT. java.text.SimpleDateFormat
would be nice too, but not essential.

Workaround if you have one:
Dealing with dates on the client side of GWT is currently fairly messy, and
involves using all of the deprecated methods on the java.util.Date class.

Links to the relevant GWT Developer Forum posts:
http://groups.google.com/group/Google-Web-Toolkit/browse_frm/thread/220837cbfce5e4b0/118901d39dd2b10b?lnk=gst&q=java.util.Calendar&rnum=2#118901d39dd2b10b
http://groups.google.com/group/Google-Web-Toolkit/browse_thread/thread/f9136940ddd494e9/e53fc30c7a2e42f9?lnk=gst&q=date&rnum=1#e53fc30c7a2e42f9

Reported by rustyshelf on 2007-01-17 06:13:26

dankurka commented 9 years ago

Reported by gwt.team.morrildl on 2007-01-17 17:06:18

dankurka commented 9 years ago

Reported by gwt.team.morrildl on 2007-02-12 21:13:16

dankurka commented 9 years ago
I hope this issue gets resolved soon, because having to use the deprecated Date
methods is not nice at all.

Reported by b.q.mulder on 2007-07-30 13:29:11

dankurka commented 9 years ago

Reported by gwt.team.jgw on 2007-10-25 13:53:15

dankurka commented 9 years ago
This enhancement would indeed greatly increase GWT's usability. Maybe
java.util.TimeZone and java.util.Locale can be considered as well. These are all
classes that are very practical for presentation logic, which is the domain of GWT.

Reported by jeroen%kransen.nl@gtempaccount.com on 2008-02-21 07:07:13

dankurka commented 9 years ago
Vote for this. But I suspect this will be hard to do in any meaningful sense, won't
it? Seeing as (AFAIK) Javascript is blissfully unaware of such things as time zones,
locales and daylight savings?

Reported by mundoli on 2008-02-26 11:52:07

dankurka commented 9 years ago
Yes, pls add this, with TimeZone implemented.

Reported by jennybaotranla on 2008-03-05 19:50:22

dankurka commented 9 years ago
Marked "Planned" in the sense that we definitely want to consider it in the future,
although we may not actually do this exact task.

We need to consider carefully what's more important: java.util.Calendar (for sheer
compatbility) or something that much more lightweight and optimizable (for better
size/speed).

Reported by bruce+personal@google.com on 2008-04-08 17:09:43

dankurka commented 9 years ago
It would be great if I could use calendar in shared code, even if it can only run on

the server (it could throw an exception in the client).  Is that possible in any way?

Reported by dobesv on 2008-04-30 07:13:03

dankurka commented 9 years ago
is that available now since i got error on client side?

Reported by yshaoxp on 2008-10-10 15:52:12

dankurka commented 9 years ago

Reported by bruce+personal@google.com on 2008-10-21 21:31:36

dankurka commented 9 years ago

Reported by ecc%google.com@gtempaccount.com on 2009-01-05 15:57:34

dankurka commented 9 years ago
Any word on an update for this :D ? I flinch every time I look at our datepicker
because it uses so many deprecated methods. They certainly work for now, but am
curious to see what is in the works as far as date manipulation on the client side.

Reported by JhnClvr on 2009-08-12 19:42:12

dankurka commented 9 years ago
plus 1 
I'm tired of warnings on Date's deprecated methods.
Is there any progress in java.util.Calendar support?

Reported by sergey.yermakov on 2009-08-12 20:32:29

dankurka commented 9 years ago
Calendar's API is nearly universal hated, and it certainly seems hard to optimize well
from the compiler's 
perspective. How does the idea of a new and improved Date-like class strike you?

Reported by bruce+personal@google.com on 2009-08-12 22:43:23

dankurka commented 9 years ago
This is not the only Java API which is universal hated, but still it is the part of
the standard Java API. 
I'm not sure that replacing it with something else is a good idea.
At least think of newcomers. GWT is really great and innovative, but every deviation
from the standards puts additional barriers on its learning curve.

Reported by sergey.yermakov on 2009-08-12 23:06:19

dankurka commented 9 years ago
if you decide not to support Calendar api i'd like you to go towards a "de facto"
standard like yoda-time

Reported by federico.monaldi on 2009-08-13 08:05:38

dankurka commented 9 years ago
I have no problems with a custom Date class. Just name it something obviously different.
like HammerTime. Or 
better yet HammerDateTime.

I kid about the hammer time, but I'm serious about the custom class I have no problem
with it. I agree that the 
java.util.Calendar is a pain in the proverbial...

Reported by rustyshelf on 2009-08-13 08:26:25

dankurka commented 9 years ago
How about just having a "public class JsDate extends JavaScriptObject" just wrapping

the ECMA-262 Date object? (replacing "new Date" with JsDate.createInstance() static

methods)

Reported by t.broyer on 2009-08-13 10:09:42

dankurka commented 9 years ago
Attached is a very basic such JsDate JSO, with only added newInstance(Date) and 
toJavaDate() methods to convert from/to java.util.Date.

Reported by t.broyer on 2009-08-24 23:36:06


dankurka commented 9 years ago
If at all feasible, just skipping the awful date API in favor of Joda-Time would be

fantastic.

Reported by eelco.hillenius on 2009-12-15 13:21:33

dankurka commented 9 years ago
Joda-Time is very good I agree. I used it on a previous project and it was very
intuitive, and was everything java dates should have been.

Reported by JhnClvr on 2009-12-15 13:30:31

dankurka commented 9 years ago
Looks like there's a third-party library for Joda-Time already:

http://code.google.com/p/goda-time/

Reported by dobesv on 2009-12-15 17:33:18

dankurka commented 9 years ago
It doesn't look like "goda-time" is remotely close to usable at this point.
"goda-time" has no releases, the source doesn't compile and it doesn't look like it's
actively developed (last commits were 9/2/09, 8/24/09, 6/11/09 and then back 11/18/08).

I don't see any technical reason to implement Calendar instead of a custom date
structure. Personally I'm in favor of the JodaTime route though. JodaTime is
outstanding, while Calendar is annoying to use. 

Reported by organicveggie on 2010-01-07 17:26:25

dankurka commented 9 years ago
I've sucessfully patched goda-time to suit my needs. Although it's a huge lib, its 
working. The patch is in goda time's issues.

But I agree a Calendar implementation would be better.

Reported by miguel.ping on 2010-01-07 17:36:28

dankurka commented 9 years ago
In the SimpleDateFormat class in gwt, few methods of the java.text.SimpleDateFormat
are missing too.Like the setLenient(boolean) method which basically sets the leniency
level for parsing the date. GWT should have all the methods and functionality of the
java.text.SimpleDateFormat class

Reported by suhas.bilaye on 2010-01-22 04:30:06

dankurka commented 9 years ago
I vote for dropping Calendar in favor of a new date api, like joda-time, if (and only
if) it did NOT contain any native/js code so that it can run in the server side too.
Remember that the JSR-310 will be strongly based on the experiences gained from the
joda-time project.

Note: It would be nice to see some initial implementation of this JSR-310, but it
seems to be evolving at a freaking extremely slow pace. More on this here
http://jcp.org/en/jsr/detail?id=310 and here
https://jsr-310.dev.java.net/servlets/ReadMsg?list=dev&msgNo=1389

Reported by ccidral on 2010-02-26 14:31:10

dankurka commented 9 years ago
Has anyone tried the following with GWT 2.x?
http://joda-time.svn.sourceforge.net/viewvc/joda-
time/trunk/JodaTimeContrib/gwt/README.txt?view=markup

Reported by dale.wyttenbach on 2010-03-18 15:22:21

dankurka commented 9 years ago
Check out goda-time on github. I have a fork from the project that was on google code,

and there's also another fork from my own that patches some GWT compiler warnings.

Reported by miguel.ping on 2010-03-19 13:48:26

dankurka commented 9 years ago
@31 yeah - just gave it a quick try, worked well. Transparently use org.joda.time.DateTime
et al one client and server. Nice.

Reported by antony.stubbs on 2010-06-08 06:57:55

dankurka commented 9 years ago
@33 antony, I've got joda-time-gwt compiled and loaded in my GWT app.  But every datetime
class I try to use - DateTime, MutableDateTime - gets this exception:

uncaught exception: java.lang.UnsupportedOperationException: Locale not supported in
GWT

You say you are able to use DateTime on client.  How did you get around this Locale
issue?  Thanks.

Reported by guy.rouillier on 2010-07-16 05:00:56

dankurka commented 9 years ago
@34 i know, we have the same problem :/ Haven't really tried to fix it yet. It also
seem to be inconsistent. Either that or it's dependenant on where you're running the
GWT app i.e. Idea vs Eclips vs Mvn (jetty).

Reported by antony.stubbs on 2010-07-16 05:08:20

dankurka commented 9 years ago
Turns out not to be a problem with the library but simply my attempting to pop-up the
value in an alert window.  Here is what I had:

MutableDateTime mdt = new MutableDateTime();
mdt.setMillisOfDay(0);

Window.alert( "MutableDateTime: " + mdt );

The alert was what was causing the problem!  If I delete that and instead use this:

Window.alert( "MutableDateTime.getMinuteOfDay(): " + mdt.getMinuteOfDay() );

Everything works fine.  Leaving this post in case others find it via search.

My thanks to the author and to those here for pointing it out.

Reported by guy.rouillier on 2010-07-16 18:11:43

dankurka commented 9 years ago
I would be willing to contribute our Calendar emulation. We wrote it and some people
contributed to it. We already have it in an isolated project since we have been hoping
this would become emulated in a future release. It been running in production for over
a year now. Timezone are not supported at the moment.

http://code.google.com/p/ftr-gwt-library/

Reported by mnouwens on 2010-08-26 05:56:06

dankurka commented 9 years ago
You could produce a patch for the current gwt trunk and send it to the review board
application at http://gwt-code-reviews.appspot.com/.

I think this should speed up the process.

Reported by manuel.carrasco.m on 2010-08-26 10:14:43

dankurka commented 9 years ago
I would prefer to see support for http://www.datejs.com/ instead of java.util.Calendar

Reported by adrian.murray on 2010-08-29 15:52:14

dankurka commented 9 years ago
Adrian: You can get a datejs wrapper class from the kiyaa project: 

http://code.google.com/p/kiyaa/

Reported by dobesv on 2010-08-29 18:49:34

dankurka commented 9 years ago
Does it include DateFormat?

Reported by mk.agile on 2010-10-05 06:38:58

dankurka commented 9 years ago
I've created a rough implementation that emulates TimeZone, Calendar, and Locale. It
uses super-source  to emulate the the classes.  It's still in alpha but, feel free
to check it out.

http://code.google.com/p/gwt-calendar-class/downloads/list

Reported by another.two on 2010-10-11 00:55:37

dankurka commented 9 years ago
You can use the CalendarUtil class
com.google.gwt.user.datepicker.client.CalendarUtil 
http://google-web-toolkit.googlecode.com/svn/javadoc/1.6/com/google/gwt/user/datepicker/client/CalendarUtil.html

Reported by sharpen.soul on 2010-10-23 20:42:25

dankurka commented 9 years ago

Reported by rjrjr@google.com on 2011-01-13 03:09:43

dankurka commented 9 years ago
do you think, we can use Joda time/date API right now in GWT 2.2.0 ?
http://joda-time.sourceforge.net/

what do you think of porting Joda to GWT ?

Reported by zixzigma on 2011-03-07 06:31:38

dankurka commented 9 years ago
I came across this port:
http://code.google.com/p/gwt-joda-time/

As anyone following this bug checked it out?

Reported by nesrait on 2011-03-07 08:37:06

dankurka commented 9 years ago
I think emulation of Calendar is necessary, even if it is not fully supported.  It is
a pain to have to bounce between different classes from client to server.

It might not be so bad if something was written that could be used on the client and
the server though.  At least this will keep us from having to write a client and server
copy of the necessary classes.

+1 for emulating Calendar.

Reported by patrick.tucker@macefusion.com on 2011-03-22 15:20:13

dankurka commented 9 years ago
I vote for supporting JSR-310 in GWT. It's on its way to becoming the new standard Date/Time
API while Date and Calendar will be deprecated.

Reported by inetperson on 2011-04-23 17:20:14

dankurka commented 9 years ago
I just checked-out joda-time-gwt trunk and it compiles and is mostly usable, maybe it's
the fastest way to get a working date api ?

My vote goes to working on that as opposed to starting from scratch or waiting for
jsr310.

Reported by diaz.salvador on 2011-05-15 18:29:04

dankurka commented 9 years ago
diaz, 
are you using the project listed in comment #46?

Reported by rakeshw on 2011-05-16 00:44:45

dankurka commented 9 years ago
I'm the guy who started work on gwt-joda-time. I haven't been doing much work with GWT
since I started that, so I haven't really had time to make any progress for a while.
But, if there's interest, I could resurrect the project.

http://code.google.com/p/gwt-joda-time/

Reported by organicveggie on 2011-05-16 01:37:59

dankurka commented 9 years ago
I was talking about the project listed in comment 31:
http://joda-time.svn.sourceforge.net/viewvc/joda-time/trunk/JodaTimeContrib/gwt/

But now that joda-time has migrated to github, that subproject was left behind, it
would be cool if the gwt team could take over its ownership.

Reported by diaz.salvador on 2011-05-19 11:49:50

dankurka commented 9 years ago
I just wanted to balance out some of the negative by saying that GWT has been great
for me. I started a contract for a company a year ago. They asked me to pick a technology
to write their internal portal with and I picked GWT. In less than four months I'd
constructed a portal it normally would have taken me six months to write. I've found
the Eclipse IDE is well integrated and the APIs are (mostly) well documented and very
easy to work with. 

So overall, I don't see any grounds for raising a stink over this particular issue
taking a few seconds of googling to solve. If it can be improved in the future without
too much client overhead, great. If not, GWT is still a fantastic and very powerful
toolkit. 

So great job devs, all around! 

Reported by andy16666 on 2011-07-31 00:11:35