0
votes

I'm using fullcalendar integrated with Java Wicket webapp.

I have a problem with date when timezone of webbrowser is different from timezone of server.

For example : webbrowser at Cayenne (UMT -3) and server at Paris (UMT +1).

I use "ignoreTimeZone=true" of fullcalendar because I want to keep in database calendar of timezone of the user of webbrowser.

When server initialize calendar : events sended from Paris to Cayenne

server send events like this

{"id":"53922","title":"0123456789","allDay":false,"start":"2011-01-06T09:00:00.000+01:00"}

With ignoreTimeZone=true it's ok. We have 9 o'clock in calendar.

To verify, I've tested with ignoreTimeZone=false. I have correctly event positioned at 5 o'clock (9 - 4 = 5).

Problem is coming when user click a day to create an new event !

For 12 o'clock time then JSON value sended from webbrowser is correct

allDay false date "2011-01-07T15:00:00.000Z" feedbackFor "dayClick"

But if I want to have equivalent from ignoreTimeZone I'd prefer to have 2011-01-07T12:00:00:000-03:00 format or just 2011-01-07T12:00:00.000

Is it possible to have this new possibility ?

Thanks by advance of your response.

1
I have more investigating javascript code and I finded that is an added javascript that convert field date from dayClick structure to JSON String in ISO8601 Z Format. I've changed this portion of code to convert in ISO8601 with TimeZone relative +/-HH:MM and it's what I want. Probably it's not a good conception but in this version it's what i want. - Laurent Souchet

1 Answers

1
votes

My solution is always send events form server with UNIX timestamp or UTC dateformat from the client's FullCalendar.

First, the events sent from client using jquery-json plugin are like

var event ={"startDate" : startDate, "endDate" : endDate,"allDay" : allDay};
$.ajax({
  url : "${feedbackURL}", type: 'POST', contentType: 'application/json;charset=UTF-8'
 ,dataType: (($.browser.msie) ? "text" : "xml"), data : $.toJSON(event)
});

The event serialized in $.toJSON() will be formated with UTC fomat "yyyy-MM-dd'T'HH:mm:ss'Z'".

Then you can use gson and jodatime to parse the UTC format date

private static final DateTimeFormatter UTC_FORMAT = DateTimeFormat
        .forPattern("yyyy-MM-dd'T'HH:mm:ss'Z'").withZone(DateTimeZone.UTC);

public static final JsonDeserializer<Date> DATE_DESERIALIZER = new JsonDeserializer<Date>() {

    /**
     * @see org.apache.wicket.datetime.DateConverter#convertToObject(String,
     *      java.util.Locale)
     */
    @Override
    public Date deserialize(final JsonElement json, final Type typeOfT,
            final JsonDeserializationContext context)
            throws JsonParseException {
        String value = json.getAsString().replace(".000", "");
        try {
            MutableDateTime dt = UTC_FORMAT.parseMutableDateTime(value);

            return dt.toDate();
        } catch (final Exception e) {
            LOG.debug("Date parsing error", e);
            throw new ConversionException(e);
        }
    }

};

Second, display the date with org.apache.wicket.datetime.markup.html.form.DateTextField or org.apache.wicket.datetime.markup.html.basic.DateLabel.

To deal with Client's Timezone problem, add these to your Application

// always set your application's DateTimeZone to UTC
TimeZone.setDefault(TimeZone.getTimeZone("etc/UTC"));
DateTimeZone.setDefault(DateTimeZone.UTC);
// detect client's timezone in the WebClientInfo
getRequestCycleSettings().setGatherExtendedBrowserInfo(true);

Finally, query from server and send events to client's FullCalendar with UNIX Timestamp.

//Java
long toTimestamp(final Date date) {
return date.getTime() / 1000;
}

Date fromTimestamp(final long timestamp) {
return new Date(timestamp * 1000);
}

Produced jsons are like this

[{"id":"1","title":"test1","allDay":true,"start":1299805200,"end":1299807000,"editable":false},
{"id":"2","title":"test2","allDay":false,"start":1299805200,"end":1299807000,"editable":true}]