GWT Date 'week of year' and 'day of week' problem

1,057 views
Skip to first unread message

md

unread,
Aug 22, 2011, 5:11:26 PM8/22/11
to Google Web Toolkit
Hi!







Due to the fact that the Java Calendar Class is (unfortunately) not
compatible with GWT I’m having some problems:

I need to generate a Date-Object out of the Information by “week of
year” and “day of week”.

With the Calendar-class my code looks like:





Calendar cal = Calendar.getInstance();

cal.set(Calendar.WEEK_OF_YEAR, getComboBox_6().getSelectedIndex()+1 );

cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);





Is there any possibility to solve this problem by using the normal
‘Date’-class or ‘DateTimeFormat’ or any other suggestions?

Thanks for your reply!

geert3

unread,
Aug 23, 2011, 3:10:33 PM8/23/11
to google-we...@googlegroups.com
There are some 3rd party Calendar replacements out there, search GWT Calendar Class.
i tried one and it worked, but had massive performance hit on first use. Maybe today others are better but I managed to do without anyway.
Perhaps silly but could you make a server call and let the server do it?

md

unread,
Sep 1, 2011, 5:09:20 AM9/1/11
to Google Web Toolkit
Thanks geert3 for your answer, and sorry for my late reply!


I didn't found something helpfull and made (in the end) a workaround
with a GWT RPC... so let the server do the stuff.
Definetely not a good solution, but it works.


Thanks alot for your help!

Tom Carchrae

unread,
Sep 1, 2011, 10:41:35 AM9/1/11
to google-we...@googlegroups.com
For day of the week, you can use DateFormat.

For week of the year, you could look at the gap from Jan 1 to the date, look at the difference and then adjust to ensure you are counting weeks.  

Java Date is a mess.  An abomination.  But Calendar was even worse and you'd never use it in performance code.  (curses to you who was born in the 0th month!).  I'm predicting that GWT team will port Joda someday.  There's an attempt called Goda - but it seems dead.  

Most people I've spoken with have their own little library of hacks using Date and DateFormat.

Tom

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.


maticpetek

unread,
Sep 4, 2011, 5:03:36 AM9/4/11
to google-we...@googlegroups.com
Maybe you should try goda-time, if you don't need TimeZones. See https://groups.google.com/forum/#!topic/goda-time/lIcnmLB-0ww

Regards,
   Matic
------------------
GWT stuff twitter  - http://twitter.com/#!/gwtstuff
Reply all
Reply to author
Forward
0 new messages