Permalink
Browse files

Defaulting timezone to GMT. Changing calendar start/end date formats …

…so the calendar doesn't try to render dates in user's local timezone.
  • Loading branch information...
1 parent 5889b4b commit 2d9155b7443751525401ee1b1b58a9b27e75c77f @craigburke committed Mar 20, 2012
@@ -12,6 +12,8 @@ class BootStrap {
def init = { servletContext ->
+ TimeZone.setDefault(TimeZone.getTimeZone('GMT'))
+
if (GrailsUtil.environment == "development") {
def now = new DateTime()
def tomorrow = now.plusDays(1)
@@ -4,6 +4,7 @@ import org.joda.time.DateTime
import org.joda.time.Instant
import grails.converters.JSON
+import java.text.SimpleDateFormat
class EventController {
def eventService
@@ -35,6 +36,9 @@ class EventController {
// iterate through to see if we need to add additional Event instances because of recurring
// events
def eventList = []
+
+ def displayDateFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss")
+
events.each {event ->
def dates = eventService.findOccurrencesInRange(event, startRange, endRange)
@@ -43,12 +47,19 @@ class EventController {
DateTime startTime = new DateTime(date)
DateTime endTime = startTime.plusMinutes(event.durationMinutes)
+ /*
+ start/end and occurrenceStart/occurrenceEnd are separate because fullCalendar will use the client's local timezone (which may be different than the server's timezone)
+ start/end are used to render the events on the calendar and the occurrenceStart/occurrenceEnd values are passed along to the show popup
+ */
+
eventList << [
id: event.id,
title: event.title,
allDay: false,
- start: startTime.toString(),
- end: endTime.toString()
+ start: displayDateFormatter.format(startTime.toDate()),
+ end: displayDateFormatter.format(endTime.toDate()),
+ occurrenceStart: startTime.toInstant().millis,
+ occurrenceEnd: endTime.toInstant().millis
]
}
}
View
@@ -7,10 +7,7 @@ $(document).ready(function() {
function renderCalendar() {
$("#calendar").fullCalendar({
- events: {
- url: 'list.json',
- ignoreTimezone: false
- },
+ events: 'list.json',
header: {
left: 'prev,next today',
center: 'title',
@@ -19,8 +16,8 @@ function renderCalendar() {
eventRender: function(event, element) {
$(element).addClass(event.cssClass);
- var occurrenceStart = event.start.getTime();
- var occurrenceEnd = event.end.getTime();
+ var occurrenceStart = event.occurrenceStart;
+ var occurrenceEnd = event.occurrenceEnd;
var data = {id: event.id, occurrenceStart: occurrenceStart, occurrenceEnd: occurrenceEnd};

0 comments on commit 2d9155b

Please sign in to comment.