-
1. Re: Problem with decrementing dates
bfo81 Jul 31, 2006 10:48 AM (in response to bfo81)PS: I changed the timezone of my computer from GMT+1 to GMT-1, and now the date is regarded as 1976-07-04 01:00. So JSF really wants to perform a timezone adjustment.
I know that there's a timeZone attribute for <f:convertDate />. But I think it's daft to artificially add this every time I use a date. Especially since client and server are running on the same machine here and sharing the same timezone.
btw: Even the booking demo fails on my PC. If I enter a new booking from July 31st to August 1st everything is shown correctly on the confirm page, but the database entries are one day earlier. -
2. Re: Problem with decrementing dates
bfo81 Aug 1, 2006 4:14 PM (in response to bfo81)No one had to deal with that problem before?
-
3. Re: Problem with decrementing dates
fhh Aug 2, 2006 4:21 PM (in response to bfo81)Well, the problem is not JSF specific. Java (like most programming languages) uses timestamps internally. This is useful for - well, timestamps. But it is not useful for birthdates etc.
For java two persons born on the 1.1.1980 0:01:00.00 GMT+2 and 1.1.1980 0:01:00.00 GMT-2 are not born on the same day eventough the sane part of humanity would say that they are both born on the 1.1.1980.
You can only avoid this by using an artificial timezone (that is utc) when dealing with dates.
The only thing that suprises me is that the datetime converter use the local timezone instead of utc if no timezone is specified. I think this is a bug. Which JSF implementation do you use?
Regards
fhh -
4. Re: Problem with decrementing dates
bfo81 Aug 3, 2006 6:20 AM (in response to bfo81)It's MyFaces 1.1.1 that came with JBoss JEMS Installer. But I tried it out with MyFaces 1.1.3 now and the problem persists (btw: with 1.1.3 sometimes I get a "IllegalStateException: No active application scope" in the server log, but the app still keeps working).
Interresting: Some entities always have 23:00 and some always have 22:00. Always, even after restarting the application server. It's extremely weird and doesn't seem to make any sense. -
5. Re: Problem with decrementing dates
bfo81 Aug 3, 2006 11:03 AM (in response to bfo81)Erm... I'm not sure if this is really a Java problem. Remember:
<outputText value="#{person.birthday}" />
shows the correct date. But the tags using a f:convertDateTime do it wrong. Maybe I'll try to implement my own DateConverter, then we'll see ;). -
6. Re: Problem with decrementing dates
bfo81 Aug 3, 2006 11:03 AM (in response to bfo81)Erm... I'm not sure if this is really a Java problem. Remember:
<outputText value="#{person.birthday}" />
shows the correct date. But the tags using a f:convertDateTime do it wrong. Maybe I'll try to implement my own DateConverter, then we'll see ;). -
7. Re: Problem with decrementing dates
bfo81 Aug 7, 2006 6:49 AM (in response to bfo81)What can I say? It is a Java problem AND a JSF problem, so to say ;)
I added -Duser.timezone=Europe/Berlin to JAVA_OPTS environment property. Now,
System.getProperty("user.timezone") is Europe/Berlin
TimeZone.getDefault().getID() is Europe/Berlin
TimeZone.getDefault().getDisplayName() is Zentraleuropäische Zeit (Central European Time)
and the offset is 3600000 ms (i.e. one hour)
and useDaylight is true
BUT in the DateTimeConverter class
getTimeZone().getId() is GMT
getTimeZone().getId() is Greenwich Zeit (Greenwich Time)
the offset is 0,
and useDaylight is false.
Well, the JVM has the right timezone set, but JSF ignores it and falls back to Greenwich Mean Time. I think I got a big fat bone to pick with the Apache MyFaces staff ;). -
8. Re: Problem with decrementing dates
bfo81 Aug 7, 2006 6:58 AM (in response to bfo81)Ohhhh... the JSF specs are the ones to lay the blame on. See http://wiki.apache.org/myfaces/FAQ#Date (section "Why are my dates displaying the wrong date/time").
Sorry, but overriding the standard server timezone is idiotic in my eyes. So you really must use a custom timezone in every convertDateTime tag or use the MyFaces Sandbox converter instead.
Maybe I had almost a pure monolog in this thread, but possibly it will be helpful for someone (and I can hardly believe I am the only one who will ever have this problem...) -
9. Re: Problem with decrementing dates
iga3k Aug 13, 2006 11:12 AM (in response to bfo81)right now i'm cunfrunted with this issue.
did you get an elegant implementation? -
10. Re: Problem with decrementing dates
muckwarrior Oct 10, 2006 4:57 AM (in response to bfo81)"bfo81" wrote:
Maybe I had almost a pure monolog in this thread, but possibly it will be helpful for someone (and I can hardly believe I am the only one who will ever have this problem...)
I've also encountered the same problem. Thanks for pointing me in the right direction! -
11. Re: Problem with decrementing dates
msteiner Oct 10, 2006 7:09 AM (in response to bfo81)This is my solution:
Component:@Name("defaultTimeZone") @Scope(ScopeType.APPLICATION) @Intercept(NEVER) public class DefaultTimeZone { /** * @return default TimeZone */ @Unwrap public TimeZone getDefaultTimeZone() { return TimeZone.getDefault(); } }
Page:<h:outputText value="#{myObj.date}"> <f:convertDateTime pattern="yyyy-MM-dd HH:mm:ss" timeZone="#{defaultTimeZone}" /> </h:outputText>
It is easy to change for example to userTimeZone where timeZone is extracted from database or something like this -
12. Re: Problem with decrementing dates
gavin.king Oct 10, 2006 1:43 PM (in response to bfo81)Um .... do you mind if I just steal that code and put it in org.jboss.seam.core? Actually, if I did that, I should probably do a whole Timezone/TimezoneSelector thingy like what we have for locales...
I agree that the standard JSF behavior here is nuts. Or an alternative solution would be to introduce an <s:convertDateTime/> which is smart enough to default to the default server timezone ... -
13. Re: Problem with decrementing dates
msteiner Oct 11, 2006 5:08 AM (in response to bfo81)"gavin.king@jboss.com" wrote:
Um .... do you mind if I just steal that code and put it in org.jboss.seam.core?
Not at all."gavin.king@jboss.com" wrote:
Actually, if I did that, I should probably do a whole Timezone/TimezoneSelector thingy like what we have for locales...
I agree that the standard JSF behavior here is nuts. Or an alternative solution would be to introduce an <s:convertDateTime/> which is smart enough to default to the default server timezone ...
I vote for it ! With all that cookies stuff like in localeSelector and mybe rename defaultTimeZone to serverTimeZone and add posibility to set default timezone in timezoneselector to serverTimezone -