Example usage for org.joda.time DateTimeZone setDefault

List of usage examples for org.joda.time DateTimeZone setDefault

Introduction

In this page you can find the example usage for org.joda.time DateTimeZone setDefault.

Prototype

public static void setDefault(DateTimeZone zone) throws SecurityException 

Source Link

Document

Sets the default time zone.

Usage

From source file:se.jguru.nazgul.test.xmlbinding.junit.StandardTimeZoneRule.java

License:Apache License

/**
 * {@inheritDoc}
 */
@Override
protected void starting(final Description description) {
    DateTimeZone.setDefault(desiredTimeZone);
}

From source file:se.jguru.nazgul.test.xmlbinding.junit.StandardTimeZoneRule.java

License:Apache License

/**
 * {@inheritDoc}
 */
@Override
protected void finished(final Description description) {
    DateTimeZone.setDefault(originalTimeZone);
}

From source file:se.vgregion.portal.notes.calendar.controllers.NotesCalendarViewController.java

License:Open Source License

/**
 * Displays the calendar events for the logged in user.
 *
 * @param model    the model//from   w  ww. j a  va2 s.  com
 * @param request  the portletRequest
 * @param response the portletResponse
 * @return the view to display
 */
@RenderMapping
public String displayCalendarEvents(ModelMap model, RenderRequest request, RenderResponse response) {

    // It would seem that Joda Times DateTimeZone does not use Sun:s TimeZone.getDefault (user.timezone) as its
    // often claims but defaults to timezone UTC. So therefor we do this:
    DateTimeZone.setDefault(DateTimeZone.forTimeZone(TimeZone.getDefault()));
    // ... getting the value set in the java_opt - setting it as default for JT.

    String userId = portletData.getUserId(request);
    LOGGER.debug("Userid: {}", userId);
    CalendarEventsPeriod displayPeriod = (CalendarEventsPeriod) model.get(displayPeriodKey);
    if (displayPeriod == null) {
        DateTime startDate = new DateTime().withDayOfWeek(DateTimeConstants.MONDAY).withHourOfDay(0)
                .withMinuteOfHour(0).withSecondOfMinute(0).withMillisOfSecond(0);
        displayPeriod = new CalendarEventsPeriod(startDate, CalendarEventsPeriod.DEFAULT_PERIOD_LENGTH);
        model.put(displayPeriodKey, displayPeriod);
    }
    try {
        Map<String, Future<CalendarEvents>> futureCalendarEvents = new HashMap<String, Future<CalendarEvents>>();

        // Initialize CalendarEvents
        CalendarEvents events = new CalendarEvents();
        events.setCalendarItems(new ArrayList<CalendarItem>());

        // Retrieve asynchronously
        futureCalendarEvents.put("VGR", calendarService.getFutureCalendarEvents(userId, displayPeriod));

        // Get from Google, asynchronously
        //            String selectedCalendars = request.getPreferences().getValue(this.SELECTED_GOOGLE_CALENDARS, "");
        //            List<String> selectedCalendarsList = Arrays.asList(stringToArray(selectedCalendars));
        //            futureCalendarEvents.put("Google", googleCalendarService.getFutureCalendarEvents(userId, displayPeriod,
        //                    selectedCalendarsList));

        // Get from other sources, asynchronously.
        Map<String, String> externalSources = getExternalSources(request.getPreferences());
        for (Map.Entry<String, String> externalSource : externalSources.entrySet()) {
            futureCalendarEvents.put(externalSource.getKey(),
                    calendarService.getFutureCalendarEventsFromIcalUrl(externalSource.getValue(), displayPeriod,
                            externalSource.getKey()));
        }

        // Now that we have a list of Future objects which all are processed concurrently we start to "get()" them.
        List<String> failedRetrievals = new ArrayList<String>();
        for (Map.Entry<String, Future<CalendarEvents>> futureCalendarEvent : futureCalendarEvents.entrySet()) {
            try {
                Future<CalendarEvents> value = futureCalendarEvent.getValue();
                CalendarEvents calendarEvents = value.get(15, TimeUnit.SECONDS);
                if (calendarEvents != null) {
                    List<CalendarItem> calendarItems = calendarEvents.getCalendarItems();
                    if (calendarItems != null) {
                        events.getCalendarItems().addAll(calendarItems);
                    }
                }
            } catch (Exception ex) {
                if (userId.equals("lifra1")) {
                    LOGGER.warn("Failed to get a calendar for user " + userId + ". " + ex.getMessage());
                } else {
                    LOGGER.warn("Failed to get a calendar for user " + userId + ". " + ex.getMessage(), ex);
                }
                failedRetrievals.add(futureCalendarEvent.getKey());
            }
        }

        if (failedRetrievals.size() > 0) {
            String errorMessage = "Fljande hmtningar misslyckades: "
                    + StringUtils.arrayToCommaDelimitedString(failedRetrievals.toArray()) + ".";
            model.addAttribute("errorMessage", errorMessage);
        }

        List<List<CalendarItem>> calendarItems = events.getCalendarItemsGroupedByStartDate();
        model.put("displayPeriodText", getFormattedDateIntervalToTitle(displayPeriod, locale));
        model.put("calendarItems", calendarItems);
        model.put("randomNumber", random.nextInt());
        return VIEW;
    } catch (RuntimeException ex) {
        LOGGER.error(ex.getMessage(), ex);
        return NO_CALENDAR_VIEW;
    } catch (Exception ex) {
        LOGGER.error(ex.getMessage(), ex);
        return NO_CALENDAR_VIEW;
    }
}