If you mean the date selection calendar in the dialog: yes, dates are converted automatically (and correctly). But as I said: If you're calling
NodeDataUtil.getDate() you will get a Calendar object in UTC. -will On 01.03.2011, at 16:33, Unger, Richard wrote: > > Hi Will! > > Ah yes, the Java Date question - dates/times are always an issue with Java. > > AFAIK Magnolia essentially takes the viewpoint (following JackRabbit) that > dates are saved in the repo in UTC. > > When you read out the date, you must ensure the timezone set in your calendar > object is appropriate for the user looking at the date. > Thus, a user sitting in London will see 22h, while his friend in NYC will see > 16h ---> both are correct local time represenations of the same UTC time. > > I was under the impression that the calendar is automatically set to the > timezone of the server by default. Is this not the case? > > Regards from Vienna, > > Richard > > > > -----Ursprüngliche Nachricht----- > Von: [email protected] > [mailto:[email protected]] Im Auftrag von Will Scheidegger > Gesendet: Dienstag, 01. März 2011 12:17 > An: Magnolia User-List > Betreff: [magnolia-user] JCR Dates -> Java Calender objects: TimeZone?!? > > > Dear Magnolians > > Either I'm missing something or the conversion from JCR Dates to Java > Calendar objects is eerie. I would be glad if you could confirm this or tell > me what I'm doing wrong. > > Situation: A JCR property "date" contains a date which was entered via a date > field ("time" set to false). It is stored correctly in the repository > converted to UTC: > > <sv:property sv:name="date" sv:type="Date"> > <sv:value>2011-04-04T22:00:00.000Z</sv:value> > </sv:property> > > Now I read this property into a Calendar object: > > Calendar date = NodeDataUtil.getDate(content, "date", null); > > When I print this object, I get: > > date: > java.util.GregorianCalendar[time=1301954400000,areFieldsSet=true,areAllFieldsSet=true,lenient=true,zone=sun.util.calendar.ZoneInfo[id="UTC",offset=0,dstSavings=0,useDaylight=false,transitions=0,lastRule=null],firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,YEAR=2011,MONTH=3,WEEK_OF_YEAR=15,WEEK_OF_MONTH=2,DAY_OF_MONTH=4,DAY_OF_YEAR=94,DAY_OF_WEEK=2,DAY_OF_WEEK_IN_MONTH=1,AM_PM=1,HOUR=10,HOUR_OF_DAY=22,MINUTE=0,SECOND=0,MILLISECOND=0,ZONE_OFFSET=0,DST_OFFSET=0] > > No surprises so far. Also when I output it with a SimpleDateFormat object > with pattern "yyyy-MM-dd HH:mm:ss z" things still look fine (except that I > did not know that the default time zone is applied automatically): > > 2011-04-05 00:00:00 CEST > > But then, when I try to get the start of the month, things get weird: > > date.set(Calendar.DATE, 1); > date.set(Calendar.HOUR_OF_DAY, 0); > date.set(Calendar.MINUTE, 0); > date.set(Calendar.SECOND, 0); > date.set(Calendar.MILLISECOND, 0); > > No I get: > > 2011-04-01 02:00:00 CEST > > which is of course not what I wanted. Even worse when the date should happen > to be on the first of the month -> then you'll end up more than a month off > target. > > However when I set the TimeZone of the date object I get from NodeDataUtil > explicitly to the default timezone I get the expected result: > > 2011-04-01 00:00:00 CEST > > My question / suggestion now: Wouldn't it make sense to set the TimeZone of > the Calendar objects returned from NodeData(Utils) per default to the default > timezone because most likely this was also the timezone they were created in? > > -will > > > ---------------------------------------------------------------- > For list details see > http://www.magnolia-cms.com/home/community/mailing-lists.html > To unsubscribe, E-mail to: <[email protected]> > ---------------------------------------------------------------- > > > > > > ---------------------------------------------------------------- > For list details see > http://www.magnolia-cms.com/home/community/mailing-lists.html > To unsubscribe, E-mail to: <[email protected]> > ---------------------------------------------------------------- > ---------------------------------------------------------------- For list details see http://www.magnolia-cms.com/home/community/mailing-lists.html To unsubscribe, E-mail to: <[email protected]> ----------------------------------------------------------------
