Example usage for java.util GregorianCalendar set

List of usage examples for java.util GregorianCalendar set

Introduction

In this page you can find the example usage for java.util GregorianCalendar set.

Prototype

public void set(int field, int value) 

Source Link

Document

Sets the given calendar field to the given value.

Usage

From source file:clummy.classes.DataHandlingClass.java

/**
 * generate random date of birth//from ww  w.j a  v a 2 s .  c o  m
 * @return 
 */
public String getDateOfBirth() {
    GregorianCalendar gc = new GregorianCalendar();

    int year = randBetween(DataHandlingClass.minMaxDOB[0], DataHandlingClass.minMaxDOB[1] - 1);

    gc.set(gc.YEAR, year);

    int dayOfYear = randBetween(1, gc.getActualMaximum(gc.DAY_OF_YEAR));

    gc.set(gc.DAY_OF_YEAR, dayOfYear);

    int month = gc.get(gc.MONTH);
    if (month == 0)
        month = 1;
    if (dateSeperator.equals(" "))
        dateSeperator = "";
    if (dateFormat.equalsIgnoreCase("DDMMYYYY"))
        return String.format("%02d", gc.get(gc.DAY_OF_MONTH)) + dateSeperator + String.format("%02d", month)
                + dateSeperator + gc.get(gc.YEAR);
    else if (dateFormat.equalsIgnoreCase("MMDDYYYY"))
        return String.format("%02d", month) + dateSeperator + String.format("%02d", gc.get(gc.DAY_OF_MONTH))
                + dateSeperator + gc.get(gc.YEAR);
    else if (dateFormat.equalsIgnoreCase("YYYYDDMM"))
        return gc.get(gc.YEAR) + dateSeperator + String.format("%02d", gc.get(gc.DAY_OF_MONTH)) + dateSeperator
                + String.format("%02d", month);
    else
        return gc.get(gc.YEAR) + dateSeperator + String.format("%02d", month) + dateSeperator
                + String.format("%02d", gc.get(gc.DAY_OF_MONTH));
}

From source file:org.webical.test.web.component.WeekViewPanelTest.java

/**
 * Test week view with less then 7 days/*from ww  w  . ja v a  2  s .c o m*/
 * @throws WebicalException
 */
public void testNonWeekUse() throws WebicalException {

    MockCalendarManager mockCalendarManager = (MockCalendarManager) annotApplicationContextMock
            .getBean("calendarManager");
    Calendar calendar1 = mockCalendarManager.getCalendarById("1");

    MockEventManager mockEventManager = new MockEventManager();
    annotApplicationContextMock.putBean("eventManager", mockEventManager);

    // Define the current date
    final GregorianCalendar currentDate = CalendarUtils.newTodayCalendar(getFirstDayOfWeek());
    currentDate.setFirstDayOfWeek(GregorianCalendar.MONDAY);

    // The list containing the different events
    List<Event> allEvents = new ArrayList<Event>();

    GregorianCalendar refcal = CalendarUtils.duplicateCalendar(currentDate);
    refcal.add(GregorianCalendar.DAY_OF_MONTH, 1);
    refcal.set(GregorianCalendar.HOUR_OF_DAY, 12);
    refcal.set(GregorianCalendar.MINUTE, 0);
    refcal.set(GregorianCalendar.SECOND, 0);

    GregorianCalendar cal = CalendarUtils.duplicateCalendar(currentDate);

    // Add a normal event tomorrow
    Event event = new Event();
    event.setUid("e1");
    event.setCalendar(calendar1);
    event.setSummary("Normal Event Description");
    event.setLocation("Normal Event Location");
    event.setDescription("Event e1");
    cal.setTime(refcal.getTime());
    event.setDtStart(cal.getTime());
    cal.add(GregorianCalendar.HOUR_OF_DAY, 2);
    event.setDtEnd(cal.getTime());
    log.debug(
            "Adding event: " + event.getDescription() + " -> " + event.getDtStart() + " - " + event.getDtEnd());
    allEvents.add(event);
    mockEventManager.storeEvent(event);

    // Add a short recurring event, starting today, ending tomorrow
    event = new Event();
    event.setUid("e2");
    event.setCalendar(calendar1);
    event.setSummary("Recurring Event Today");
    event.setLocation("Recurring Event Location");
    event.setDescription("Event e2");
    cal.setTime(refcal.getTime());
    cal.add(GregorianCalendar.DAY_OF_MONTH, -1);
    event.setDtStart(cal.getTime());
    cal.add(GregorianCalendar.HOUR_OF_DAY, 2);
    cal.add(GregorianCalendar.DAY_OF_MONTH, 2);
    event.setDtEnd(cal.getTime());
    RecurrenceUtil.setRecurrenceRule(event,
            new Recurrence(Recurrence.DAILY, 1, CalendarUtils.getEndOfDay(cal.getTime())));
    log.debug(
            "Adding event: " + event.getDescription() + " -> " + event.getDtStart() + " - " + event.getDtEnd());
    allEvents.add(event);
    mockEventManager.storeEvent(event);

    // Add a long recurring event, starting last week, ending next week
    event = new Event();
    event.setUid("e3");
    event.setCalendar(calendar1);
    event.setSummary("Recurring Event Last Month");
    event.setLocation("Recurring Event Location");
    event.setDescription("Event e3");
    cal.setTime(refcal.getTime());
    cal.add(GregorianCalendar.WEEK_OF_YEAR, -1);
    event.setDtStart(cal.getTime());
    cal.add(GregorianCalendar.HOUR_OF_DAY, 2);
    cal.add(GregorianCalendar.WEEK_OF_YEAR, 3);
    event.setDtEnd(cal.getTime());
    RecurrenceUtil.setRecurrenceRule(event,
            new Recurrence(Recurrence.DAILY, 1, CalendarUtils.getEndOfDay(cal.getTime())));
    log.debug(
            "Adding event: " + event.getDescription() + " -> " + event.getDtStart() + " - " + event.getDtEnd());
    allEvents.add(event);
    mockEventManager.storeEvent(event);

    // Add a (pseudo) all day event, starting day + 1 midnight, ending day + 2 00:00 hours
    event = new Event();
    event.setUid("e4");
    event.setCalendar(calendar1);
    event.setSummary("Pseudo All Day Event");
    event.setLocation("All Day Event Location");
    event.setDescription("Starting day + 1, ending day + 2 00:00 hours");
    cal.setTime(refcal.getTime());
    cal.add(GregorianCalendar.DAY_OF_MONTH, 1);
    cal.set(GregorianCalendar.HOUR_OF_DAY, 0);
    cal.set(GregorianCalendar.MINUTE, 0);
    cal.set(GregorianCalendar.SECOND, 0);
    cal.set(GregorianCalendar.MILLISECOND, 0);
    event.setDtStart(cal.getTime());
    cal.add(GregorianCalendar.DAY_OF_MONTH, 1);
    event.setDtEnd(cal.getTime());
    log.debug(
            "Adding event: " + event.getDescription() + " -> " + event.getDtStart() + " - " + event.getDtEnd());
    allEvents.add(event);
    mockEventManager.storeEvent(event);

    // Create test page with a WeekViewPanel
    wicketTester.startPage(new ITestPageSource() {
        private static final long serialVersionUID = 1L;

        public Page getTestPage() {
            return new PanelTestPage(new WeekViewPanel(PanelTestPage.PANEL_MARKUP_ID, 4, currentDate) {
                private static final long serialVersionUID = 1L;

                @Override
                public void onAction(IAction action) {
                    /* NOTHING TO DO */ }
            });
        }
    });

    // Basic assertions
    wicketTester.assertRenderedPage(PanelTestPage.class);
    wicketTester.assertComponent(PanelTestPage.PANEL_MARKUP_ID, WeekViewPanel.class);

    // Assert number of days rendered
    // Set the correct dates to find the first and last day of the week
    GregorianCalendar viewFirstDayCalendar = CalendarUtils.duplicateCalendar(currentDate);
    // Assert the first day in the view
    wicketTester.assertComponent(PanelTestPage.PANEL_MARKUP_ID + ":weekColumnRepeater:day"
            + viewFirstDayCalendar.get(GregorianCalendar.DAY_OF_YEAR), WeekDayPanel.class);

    GregorianCalendar viewLastDayCalendar = CalendarUtils.duplicateCalendar(currentDate);
    viewLastDayCalendar.add(GregorianCalendar.DAY_OF_MONTH, 3);
    // Assert the last day in the view
    wicketTester.assertComponent(PanelTestPage.PANEL_MARKUP_ID + ":weekColumnRepeater:day"
            + viewLastDayCalendar.get(GregorianCalendar.DAY_OF_YEAR), WeekDayPanel.class);

    // Events for days in this 4 day period
    List<Event> dayEvents = new ArrayList<Event>();
    // Assert weekday events
    GregorianCalendar weekCal = CalendarUtils.duplicateCalendar(currentDate);
    for (int i = 0; i < 4; ++i) {
        WeekDayPanel weekDayEventsListView = (WeekDayPanel) wicketTester.getLastRenderedPage()
                .get(PanelTestPage.PANEL_MARKUP_ID + ":weekColumnRepeater:day"
                        + weekCal.get(GregorianCalendar.DAY_OF_YEAR));
        switch (i) {
        case 0:
            dayEvents.clear();
            dayEvents.add(allEvents.get(1)); // e2
            dayEvents.add(allEvents.get(2)); // e3
            break;
        case 1:
            dayEvents.clear();
            dayEvents.add(allEvents.get(0)); // e1
            dayEvents.add(allEvents.get(1)); // e2
            dayEvents.add(allEvents.get(2)); // e3
            break;
        case 2:
            dayEvents.clear();
            dayEvents.add(allEvents.get(1)); // e2
            dayEvents.add(allEvents.get(2)); // e3
            dayEvents.add(allEvents.get(3)); // e4
            break;
        case 3:
            dayEvents.clear();
            dayEvents.add(allEvents.get(2)); // e3
            break;
        }
        String path = weekDayEventsListView.getPageRelativePath() + ":eventItem";
        wicketTester.assertListView(path, dayEvents);

        ListView listView = (ListView) wicketTester.getComponentFromLastRenderedPage(path);
        Iterator<?> lvIt = listView.iterator();
        while (lvIt.hasNext()) {
            ListItem item = (ListItem) lvIt.next();
            Event evt = (Event) item.getModelObject();
            List<?> bhvs = item.getBehaviors();
            if (evt.getUid().equals("e4"))
                assertEquals(1, bhvs.size()); // e4 all day event
            else
                assertEquals(0, bhvs.size());
        }

        weekCal.add(GregorianCalendar.DAY_OF_WEEK, 1);
    }
}

From source file:org.webical.web.component.event.EventForm.java

/**
 * Create an empty Event and set the start and end times
 * @return Event//from  w  w  w .  j  av  a 2s  .c  om
 */
private EventWrapper createEmptyEvent() {
    this.formEvent = new Event();
    this.eventWrapper = new EventWrapper(formEvent);

    GregorianCalendar dateCalendar = CalendarUtils.duplicateCalendar(selectedDate);
    GregorianCalendar timeCalendar = CalendarUtils.newTodayCalendar(dateCalendar.getFirstDayOfWeek());
    dateCalendar.set(GregorianCalendar.HOUR_OF_DAY, timeCalendar.get(GregorianCalendar.HOUR_OF_DAY));
    dateCalendar.set(GregorianCalendar.MINUTE, timeCalendar.get(GregorianCalendar.MINUTE) / 5 * 5);

    //Fill the start and end times with proper values
    eventWrapper.setDtStart(dateCalendar.getTime());
    dateCalendar.add(GregorianCalendar.HOUR_OF_DAY, 1);
    eventWrapper.setDtEnd(dateCalendar.getTime());

    return this.eventWrapper;
}

From source file:org.webical.test.web.component.MonthViewPanelTest.java

/**
 * Test rendering with events./*ww w . j  ava2  s  .co  m*/
 * @throws WebicalException
 */
public void testRenderingWithEvents() throws WebicalException {
    log.debug("testRenderingWithEvents");

    String path = null;
    MockCalendarManager mockCalendarManager = (MockCalendarManager) annotApplicationContextMock
            .getBean("calendarManager");
    Calendar calendar1 = mockCalendarManager.getCalendarById("1");

    MockEventManager mockEventManager = new MockEventManager();
    annotApplicationContextMock.putBean("eventManager", mockEventManager);

    GregorianCalendar cal = CalendarUtils.newTodayCalendar(getFirstDayOfWeek());
    cal.set(GregorianCalendar.DAY_OF_MONTH, 15);
    final GregorianCalendar currentDate = CalendarUtils.duplicateCalendar(cal);

    // FIXME mattijs: test fails when run at 23:30 (probably also between 22:00 and 00:00)

    // all events
    List<Event> allEvents = new ArrayList<Event>();

    // Add a normal event
    Event event = new Event();
    event.setUid("e1");
    event.setCalendar(calendar1);
    event.setSummary("Normal Event Description");
    event.setLocation("Normal Event Location");
    event.setDescription("Event e1");
    cal.set(GregorianCalendar.DAY_OF_MONTH, 15);
    cal.set(GregorianCalendar.HOUR_OF_DAY, 13);
    cal.set(GregorianCalendar.MINUTE, 30);
    event.setDtStart(cal.getTime());
    cal.add(GregorianCalendar.HOUR_OF_DAY, 2);
    event.setDtEnd(cal.getTime());
    log.debug(
            "Adding event: " + event.getDescription() + " -> " + event.getDtStart() + " - " + event.getDtEnd());
    allEvents.add(event);
    mockEventManager.storeEvent(event);

    // Add a short recurring event, starting yesterday, ending tomorrow
    event = new Event();
    event.setUid("e2");
    event.setCalendar(calendar1);
    event.setSummary("Recurring Event Yesterday");
    event.setLocation("Recurring Event Location");
    event.setDescription("Event e2");
    cal.set(GregorianCalendar.DAY_OF_MONTH, 14);
    cal.set(GregorianCalendar.HOUR_OF_DAY, 10);
    cal.set(GregorianCalendar.MINUTE, 0);
    event.setDtStart(cal.getTime());
    cal.add(GregorianCalendar.HOUR_OF_DAY, 2);
    cal.set(GregorianCalendar.DAY_OF_MONTH, 17);
    event.setDtEnd(cal.getTime());
    RecurrenceUtil.setRecurrenceRule(event,
            new Recurrence(Recurrence.DAILY, 1, CalendarUtils.getEndOfDay(cal.getTime())));
    log.debug(
            "Adding event: " + event.getDescription() + " -> " + event.getDtStart() + " - " + event.getDtEnd());
    allEvents.add(event);
    mockEventManager.storeEvent(event);

    // Add a long recurring event, starting last month, ending next month
    event = new Event();
    event.setUid("e3");
    event.setCalendar(calendar1);
    event.setSummary("Recurring Event Last Month");
    event.setLocation("Recurring Event Location");
    event.setDescription("Event e3");
    cal.set(GregorianCalendar.DAY_OF_MONTH, 15);
    cal.set(GregorianCalendar.HOUR_OF_DAY, 16);
    cal.set(GregorianCalendar.MINUTE, 0);
    cal.add(GregorianCalendar.MONTH, -1);
    event.setDtStart(cal.getTime());
    cal.add(GregorianCalendar.HOUR_OF_DAY, 1);
    cal.set(GregorianCalendar.MINUTE, 30);
    cal.add(GregorianCalendar.MONTH, 2);
    event.setDtEnd(cal.getTime());
    RecurrenceUtil.setRecurrenceRule(event,
            new Recurrence(Recurrence.DAILY, 1, CalendarUtils.getEndOfDay(cal.getTime())));
    log.debug(
            "Adding event: " + event.getDescription() + " -> " + event.getDtStart() + " - " + event.getDtEnd());
    allEvents.add(event);
    mockEventManager.storeEvent(event);

    // Add a (pseudo) all day event, starting 21 00:00 hours, ending 22 00:00 hours
    event = new Event();
    event.setUid("e4");
    event.setCalendar(calendar1);
    event.setSummary("Pseudo All Day Event");
    event.setLocation("All Day Event Location");
    event.setDescription("Starting 21 00:00 hours, ending 22 00:00 hours");
    cal = CalendarUtils.duplicateCalendar(currentDate);
    cal.set(GregorianCalendar.DAY_OF_MONTH, 21);
    cal.set(GregorianCalendar.HOUR_OF_DAY, 0);
    cal.set(GregorianCalendar.MINUTE, 0);
    cal.set(GregorianCalendar.SECOND, 0);
    cal.set(GregorianCalendar.MILLISECOND, 0);
    event.setDtStart(cal.getTime());
    cal.add(GregorianCalendar.DAY_OF_MONTH, 1);
    event.setDtEnd(cal.getTime());
    log.debug(
            "Adding event: " + event.getDescription() + " -> " + event.getDtStart() + " - " + event.getDtEnd());
    allEvents.add(event);
    mockEventManager.storeEvent(event);

    // Add a long event this week starting 23 14.00 hours and ending 25 16.00 hours
    event = new Event();
    event.setUid("e5");
    event.setCalendar(calendar1);
    event.setSummary("Long Event Description");
    event.setLocation("Long Event Location");
    event.setDescription("Event e5");
    cal.set(GregorianCalendar.DAY_OF_MONTH, 23);
    cal.set(GregorianCalendar.HOUR_OF_DAY, 14);
    cal.set(GregorianCalendar.MINUTE, 0);
    event.setDtStart(cal.getTime());
    cal.add(GregorianCalendar.DAY_OF_MONTH, 2);
    cal.add(GregorianCalendar.HOUR_OF_DAY, 2);
    event.setDtEnd(cal.getTime());
    log.debug(
            "Adding event: " + event.getDescription() + " -> " + event.getDtStart() + " - " + event.getDtEnd());
    allEvents.add(event);
    mockEventManager.storeEvent(event);

    // Render test page with a MonthViewPanel
    wicketTester.startPage(new ITestPageSource() {
        private static final long serialVersionUID = 1L;

        public Page getTestPage() {
            MonthViewPanel monthViewPanel = new MonthViewPanel(PanelTestPage.PANEL_MARKUP_ID, 1, currentDate) {
                private static final long serialVersionUID = 1L;

                @Override
                public void onAction(IAction action) {
                    /* NOTHING TO DO */ }
            };
            return new PanelTestPage(monthViewPanel);
        }
    });

    // Basic Assertions
    wicketTester.assertRenderedPage(PanelTestPage.class);
    wicketTester.assertComponent(PanelTestPage.PANEL_MARKUP_ID, MonthViewPanel.class);

    // Assert number of days rendered
    // Set the correct dates to find the first and last day of the month
    GregorianCalendar monthFirstDayDate = CalendarUtils.duplicateCalendar(currentDate);
    monthFirstDayDate
            .setTime(CalendarUtils.getFirstDayOfWeekOfMonth(currentDate.getTime(), getFirstDayOfWeek()));
    // Assert the first day in the view
    path = PanelTestPage.PANEL_MARKUP_ID + ":monthRowRepeater:week"
            + monthFirstDayDate.get(GregorianCalendar.WEEK_OF_YEAR) + ":monthDayRepeater:day"
            + monthFirstDayDate.get(GregorianCalendar.DAY_OF_YEAR);
    wicketTester.assertComponent(path, MonthDayPanel.class);

    GregorianCalendar monthLastDayDate = CalendarUtils.duplicateCalendar(currentDate);
    monthLastDayDate.setTime(CalendarUtils.getLastWeekDayOfMonth(currentDate.getTime(), getFirstDayOfWeek()));
    // Assert the last day in the view
    path = PanelTestPage.PANEL_MARKUP_ID + ":monthRowRepeater:week"
            + monthLastDayDate.get(GregorianCalendar.WEEK_OF_YEAR) + ":monthDayRepeater:day"
            + monthLastDayDate.get(GregorianCalendar.DAY_OF_YEAR);
    wicketTester.assertComponent(path, MonthDayPanel.class);

    // Check events
    List<Event> dayEvents = new ArrayList<Event>();

    cal = CalendarUtils.duplicateCalendar(currentDate);

    // Assert events day 13
    cal.set(GregorianCalendar.DAY_OF_MONTH, 13);
    dayEvents.clear();
    dayEvents.add(allEvents.get(2)); // e3
    path = PanelTestPage.PANEL_MARKUP_ID + ":monthRowRepeater:week" + cal.get(GregorianCalendar.WEEK_OF_YEAR)
            + ":monthDayRepeater:day" + cal.get(GregorianCalendar.DAY_OF_YEAR);
    MonthDayPanel monthDayEventsListView = (MonthDayPanel) wicketTester.getLastRenderedPage().get(path);
    wicketTester.assertListView(monthDayEventsListView.getPageRelativePath() + ":eventItem", dayEvents);

    // Assert events day 14
    cal.set(GregorianCalendar.DAY_OF_MONTH, 14);
    dayEvents.clear();
    path = PanelTestPage.PANEL_MARKUP_ID + ":monthRowRepeater:week" + cal.get(GregorianCalendar.WEEK_OF_YEAR)
            + ":monthDayRepeater:day" + cal.get(GregorianCalendar.DAY_OF_YEAR);
    monthDayEventsListView = (MonthDayPanel) wicketTester.getLastRenderedPage().get(path);
    dayEvents.add(allEvents.get(1)); // e2
    dayEvents.add(allEvents.get(2)); // e3
    wicketTester.assertListView(monthDayEventsListView.getPageRelativePath() + ":eventItem", dayEvents);

    // Assert events day 15
    cal.set(GregorianCalendar.DAY_OF_MONTH, 15);
    dayEvents.clear();
    dayEvents.add(allEvents.get(0)); // e1
    dayEvents.add(allEvents.get(1)); // e2
    dayEvents.add(allEvents.get(2)); // e3
    path = PanelTestPage.PANEL_MARKUP_ID + ":monthRowRepeater:week" + cal.get(GregorianCalendar.WEEK_OF_YEAR)
            + ":monthDayRepeater:day" + cal.get(GregorianCalendar.DAY_OF_YEAR);
    monthDayEventsListView = (MonthDayPanel) wicketTester.getLastRenderedPage().get(path);
    wicketTester.assertListView(monthDayEventsListView.getPageRelativePath() + ":eventItem", dayEvents);

    cal.set(GregorianCalendar.DAY_OF_MONTH, 16);
    dayEvents.clear();
    dayEvents.add(allEvents.get(1)); // e2
    dayEvents.add(allEvents.get(2)); // e3
    path = PanelTestPage.PANEL_MARKUP_ID + ":monthRowRepeater:week" + cal.get(GregorianCalendar.WEEK_OF_YEAR)
            + ":monthDayRepeater:day" + cal.get(GregorianCalendar.DAY_OF_YEAR);
    monthDayEventsListView = (MonthDayPanel) wicketTester.getLastRenderedPage().get(path);
    wicketTester.assertListView(monthDayEventsListView.getPageRelativePath() + ":eventItem", dayEvents);

    cal.set(GregorianCalendar.DAY_OF_MONTH, 17);
    dayEvents.clear();
    dayEvents.add(allEvents.get(1)); // e2
    dayEvents.add(allEvents.get(2)); // e3
    path = PanelTestPage.PANEL_MARKUP_ID + ":monthRowRepeater:week" + cal.get(GregorianCalendar.WEEK_OF_YEAR)
            + ":monthDayRepeater:day" + cal.get(GregorianCalendar.DAY_OF_YEAR);
    monthDayEventsListView = (MonthDayPanel) wicketTester.getLastRenderedPage().get(path);
    wicketTester.assertListView(monthDayEventsListView.getPageRelativePath() + ":eventItem", dayEvents);

    // Only long recurring event
    cal.set(GregorianCalendar.DAY_OF_MONTH, 18);
    dayEvents.clear();
    dayEvents.add(allEvents.get(2)); // e3
    path = PanelTestPage.PANEL_MARKUP_ID + ":monthRowRepeater:week" + cal.get(GregorianCalendar.WEEK_OF_YEAR)
            + ":monthDayRepeater:day" + cal.get(GregorianCalendar.DAY_OF_YEAR);
    monthDayEventsListView = (MonthDayPanel) wicketTester.getLastRenderedPage().get(path);
    wicketTester.assertListView(monthDayEventsListView.getPageRelativePath() + ":eventItem", dayEvents);

    // Assert long recurring event first and last view day
    dayEvents.clear();
    dayEvents.add(allEvents.get(2)); // e3
    path = PanelTestPage.PANEL_MARKUP_ID + ":monthRowRepeater:week"
            + monthFirstDayDate.get(GregorianCalendar.WEEK_OF_YEAR) + ":monthDayRepeater:day"
            + monthFirstDayDate.get(GregorianCalendar.DAY_OF_YEAR);
    monthDayEventsListView = (MonthDayPanel) wicketTester.getLastRenderedPage().get(path);
    wicketTester.assertListView(monthDayEventsListView.getPageRelativePath() + ":eventItem", dayEvents);
    monthDayEventsListView = (MonthDayPanel) wicketTester.getLastRenderedPage()
            .get(PanelTestPage.PANEL_MARKUP_ID + ":monthRowRepeater:week"
                    + monthLastDayDate.get(GregorianCalendar.WEEK_OF_YEAR) + ":monthDayRepeater:day"
                    + monthLastDayDate.get(GregorianCalendar.DAY_OF_YEAR));
    wicketTester.assertListView(monthDayEventsListView.getPageRelativePath() + ":eventItem", dayEvents);

    // Assert events day 21
    cal.set(GregorianCalendar.DAY_OF_MONTH, 21);
    dayEvents.clear();
    dayEvents.add(allEvents.get(2)); // e3
    dayEvents.add(allEvents.get(3)); // e4
    path = PanelTestPage.PANEL_MARKUP_ID + ":monthRowRepeater:week" + cal.get(GregorianCalendar.WEEK_OF_YEAR)
            + ":monthDayRepeater:day" + cal.get(GregorianCalendar.DAY_OF_YEAR);
    monthDayEventsListView = (MonthDayPanel) wicketTester.getLastRenderedPage().get(path);
    path = monthDayEventsListView.getPageRelativePath() + ":eventItem";
    wicketTester.assertListView(path, dayEvents);

    ListView listView = (ListView) wicketTester.getComponentFromLastRenderedPage(path);
    Iterator<?> lvIt = listView.iterator();
    while (lvIt.hasNext()) {
        ListItem item = (ListItem) lvIt.next();
        Event evt = (Event) item.getModelObject();
        List<?> bhvs = item.getBehaviors();
        if (evt.getUid().equals("e4"))
            assertEquals(1, bhvs.size()); // e4 is an all day event on day 21
        else
            assertEquals(0, bhvs.size());
    }

    // Assert events day 22
    cal.set(GregorianCalendar.DAY_OF_MONTH, 22);
    dayEvents.clear();
    dayEvents.add(allEvents.get(2)); // e3
    path = PanelTestPage.PANEL_MARKUP_ID + ":monthRowRepeater:week" + cal.get(GregorianCalendar.WEEK_OF_YEAR)
            + ":monthDayRepeater:day" + cal.get(GregorianCalendar.DAY_OF_YEAR);
    monthDayEventsListView = (MonthDayPanel) wicketTester.getLastRenderedPage().get(path);
    wicketTester.assertListView(monthDayEventsListView.getPageRelativePath() + ":eventItem", dayEvents);

    // Assert events day 23
    cal.set(GregorianCalendar.DAY_OF_MONTH, 23);
    dayEvents.clear();
    dayEvents.add(allEvents.get(2)); // e3
    dayEvents.add(allEvents.get(4)); // e5
    path = PanelTestPage.PANEL_MARKUP_ID + ":monthRowRepeater:week" + cal.get(GregorianCalendar.WEEK_OF_YEAR)
            + ":monthDayRepeater:day" + cal.get(GregorianCalendar.DAY_OF_YEAR);
    monthDayEventsListView = (MonthDayPanel) wicketTester.getLastRenderedPage().get(path);
    path = monthDayEventsListView.getPageRelativePath() + ":eventItem";
    wicketTester.assertListView(path, dayEvents);

    listView = (ListView) wicketTester.getComponentFromLastRenderedPage(path);
    lvIt = listView.iterator();
    while (lvIt.hasNext()) {
        ListItem item = (ListItem) lvIt.next();
        List<?> bhvs = item.getBehaviors();
        assertEquals(0, bhvs.size()); // no all day events
    }

    // Assert events day 24
    cal.set(GregorianCalendar.DAY_OF_MONTH, 24);
    dayEvents.clear();
    dayEvents.add(allEvents.get(2)); // e3
    dayEvents.add(allEvents.get(4)); // e5
    path = PanelTestPage.PANEL_MARKUP_ID + ":monthRowRepeater:week" + cal.get(GregorianCalendar.WEEK_OF_YEAR)
            + ":monthDayRepeater:day" + cal.get(GregorianCalendar.DAY_OF_YEAR);
    monthDayEventsListView = (MonthDayPanel) wicketTester.getLastRenderedPage().get(path);
    path = monthDayEventsListView.getPageRelativePath() + ":eventItem";
    wicketTester.assertListView(path, dayEvents);

    listView = (ListView) wicketTester.getComponentFromLastRenderedPage(path);
    lvIt = listView.iterator();
    while (lvIt.hasNext()) {
        ListItem item = (ListItem) lvIt.next();
        Event evt = (Event) item.getModelObject();
        List<?> bhvs = item.getBehaviors();
        if (evt.getUid().equals("e5"))
            assertEquals(1, bhvs.size()); // e5 is an all day event on day 24
        else
            assertEquals(0, bhvs.size());
    }

    // Assert events day 25
    cal.set(GregorianCalendar.DAY_OF_MONTH, 25);
    dayEvents.clear();
    dayEvents.add(allEvents.get(2)); // e3
    dayEvents.add(allEvents.get(4)); // e5
    path = PanelTestPage.PANEL_MARKUP_ID + ":monthRowRepeater:week" + cal.get(GregorianCalendar.WEEK_OF_YEAR)
            + ":monthDayRepeater:day" + cal.get(GregorianCalendar.DAY_OF_YEAR);
    monthDayEventsListView = (MonthDayPanel) wicketTester.getLastRenderedPage().get(path);
    path = monthDayEventsListView.getPageRelativePath() + ":eventItem";
    wicketTester.assertListView(path, dayEvents);

    listView = (ListView) wicketTester.getComponentFromLastRenderedPage(path);
    lvIt = listView.iterator();
    while (lvIt.hasNext()) {
        ListItem item = (ListItem) lvIt.next();
        List<?> bhvs = item.getBehaviors();
        assertEquals(0, bhvs.size()); // no all day events
    }

    // Assert events day 26
    cal.set(GregorianCalendar.DAY_OF_MONTH, 26);
    dayEvents.clear();
    dayEvents.add(allEvents.get(2)); // e3
    path = PanelTestPage.PANEL_MARKUP_ID + ":monthRowRepeater:week" + cal.get(GregorianCalendar.WEEK_OF_YEAR)
            + ":monthDayRepeater:day" + cal.get(GregorianCalendar.DAY_OF_YEAR);
    monthDayEventsListView = (MonthDayPanel) wicketTester.getLastRenderedPage().get(path);
    wicketTester.assertListView(monthDayEventsListView.getPageRelativePath() + ":eventItem", dayEvents);
}

From source file:com.opendesign.utils.Day.java

public long getTimeInMillis() {
    GregorianCalendar cal = new GregorianCalendar(this.timeZone);
    cal.set(Calendar.YEAR, year);
    cal.set(Calendar.MONTH, month - 1);
    cal.set(Calendar.DAY_OF_MONTH, day);
    cal.set(Calendar.HOUR_OF_DAY, hour);
    cal.set(Calendar.MINUTE, minute);
    cal.set(Calendar.SECOND, second);
    return cal.getTimeInMillis();
}

From source file:org.gcaldaemon.core.GCalUtilitiesV3.java

private static final DateTime toOneDayEventDateTime(Date date) throws Exception {

    // Convert one day event's date to UTC date
    String text = date.toString();
    GregorianCalendar calendar = new GregorianCalendar(UTC);
    calendar.set(GregorianCalendar.YEAR, Integer.parseInt(text.substring(0, 4)));
    calendar.set(GregorianCalendar.MONTH, Integer.parseInt(text.substring(4, 6)) - 1);
    calendar.set(GregorianCalendar.DAY_OF_MONTH, Integer.parseInt(text.substring(6)));
    calendar.set(GregorianCalendar.HOUR_OF_DAY, 0);
    calendar.set(GregorianCalendar.MINUTE, 0);
    calendar.set(GregorianCalendar.SECOND, 0);
    calendar.set(GregorianCalendar.MILLISECOND, 0);
    DateTime dateTime = new DateTime(true, calendar.getTime().getTime(), 0);
    return dateTime;
}

From source file:gov.noaa.pfel.erddap.dataset.EDDTableFromHttpGet.java

/**
     * This figures out the name of the relevant file (which may or 
     * may not exist.//  w w w.j  a  v a  2s  .  c  o  m
     *
     * @param startDir with trailing slash
     * @param tDirStructureColumnNames For each part, the variable's source column name
     *   or "" if not used for this part.
     *   Any column names here should be in requiredColumnNames.
     * @param tDirStructureNs     For each part, the number of YEAR, MONTH, ...
     *   or -1 if not used for this part
     * @param tDirStructureCalendars  For each part, 
     *   Calendar.YEAR, MONTH, DATE, HOUR_OF_DAY, MINUTE, SECOND, MILLISECOND, 
     *   or -1 if not used for this part
     * @param tColumnNames  the source names of the columns
     * @param tColumnValues the source values associated with the tColumnNames.
     *    All should have the same size().
     *    Only values on the specified row will be used.
     * @param row the value of the rightmost array of tColumnSourceValues
     * @param timeEpSec the time value, in epoch seconds.
     *   It is usually a requiredColumn, but not always.
     *   It is an error if it is needed here, but timeEpSec is NaN.
     * @return the full file dir+name, starting with startDir.
     */
    public static String whichFile(String startDir, StringArray tDirStructureColumnNames, IntArray tDirStructureNs,
            IntArray tDirStructureCalendars, String tColumnNames[], PrimitiveArray tColumnValues[], int row,
            double timeEpSec) {

        StringBuilder dirSB = new StringBuilder(startDir);
        StringBuilder nameSB = new StringBuilder();
        int nParts = tDirStructureColumnNames.size();
        for (int i = 0; i < nParts; i++) {
            if (i > 0) {
                dirSB.append('/');
                nameSB.append('_');
            }
            int cal = tDirStructureCalendars.get(i);
            if (cal == -1) {
                //Find the var. Add its value.
                int sni = String2.indexOf(tColumnNames, tDirStructureColumnNames.get(i));
                if (sni < 0)
                    throw new SimpleException(String2.ERROR + " in directoryStructure part#" + i + ": column="
                            + tDirStructureColumnNames.get(i) + " isn't in columnNames="
                            + String2.toCSSVString(tColumnNames) + ".");
                //data value of "" is a valid value. It will be converted to something.
                String tp = String2.encodeFileNameSafe(tColumnValues[sni].getString(row));
                if (i < nParts - 1)
                    dirSB.append(tp);
                nameSB.append(tp);

            } else {
                //Find the time part. Round down to n'th precision. 
                //e.g., 17 seconds to 5seconds precision is 15 seconds.
                //(MONTH is 0-based, so that works correctly as is.)
                if (!Double.isFinite(timeEpSec))
                    throw new SimpleException(
                            String2.ERROR + " in directoryStructure part#" + i + ": time value is NaN!");
                //need a new gc for each part since gc is modified
                GregorianCalendar gc = Calendar2.epochSecondsToGc(timeEpSec);
                int n = tDirStructureNs.get(i);
                gc.set(cal, (gc.get(cal) / n) * n);
                //Get the ISO 8601 date/time string just to that precision/field.
                String s = Calendar2.formatAsISODateTimeT3(gc); //to millis 
                int nChar = s.length();
                if (cal == Calendar.YEAR)
                    nChar = 4;
                else if (cal == Calendar.MONTH)
                    nChar = 7;
                else if (cal == Calendar.DATE)
                    nChar = 10;
                else if (cal == Calendar.HOUR_OF_DAY)
                    nChar = 13;
                else if (cal == Calendar.MINUTE)
                    nChar = 16;
                else if (cal == Calendar.SECOND)
                    nChar = 19;
                //else to millis precision
                String tp = s.substring(0, nChar);
                tp = String2.replaceAll(tp, ':', '-'); //make fileNameSafe
                if (i < nParts - 1)
                    dirSB.append(tp);
                nameSB.append(tp);
            }
        }

        return dirSB.toString() + nameSB.toString() + ".nc";
    }

From source file:cz.zcu.kiv.eegdatabase.logic.controller.group.AddBookingRoomViewParamsController.java

@Override
public Map referenceData(HttpServletRequest request, Object command, Errors errors) throws Exception {
    Map map = new HashMap<String, Object>();

    int filterGroup = Integer.parseInt(request.getParameter("filterGroup"));
    String filterDate = request.getParameter("filterDate");
    if (filterDate.compareTo("") == 0)
        filterDate = null;// w  w w.  j  a v  a 2s . c o  m
    int repType = Integer.parseInt(request.getParameter("repType"));
    int repCount = Integer.parseInt(request.getParameter("repCount"));

    String date = request.getParameter("date");
    String startStr = request.getParameter("startTime");
    String endStr = request.getParameter("endTime");

    GregorianCalendar cal = BookingRoomUtils.getCalendar(startStr);
    boolean collisions = false;

    //reservations in not visible time period
    if (repCount > 0) {
        GregorianCalendar nextS = BookingRoomUtils.getCalendar(startStr);
        GregorianCalendar nextE = BookingRoomUtils.getCalendar(endStr);

        List<Reservation> coll = BookingRoomUtils.getCollisions(reservationDao, repCount, repType, nextS,
                nextE);

        map.put("collisionsInNext", coll);
        map.put("collisionsInNextCount", coll.size());
        if (coll.size() > 0)
            collisions = true;
    }

    //reservations in currently visible time period
    cal.set(Calendar.DAY_OF_WEEK, cal.getFirstDayOfWeek());
    GregorianCalendar weekStart = BookingRoomUtils.getCalendar(BookingRoomUtils.getDate(cal) + " 00:00:00");

    GregorianCalendar weekEnd = (GregorianCalendar) weekStart.clone();
    weekEnd.add(Calendar.DAY_OF_YEAR, 7);
    weekEnd.add(Calendar.SECOND, -1);

    map.put("reservations", reservationDao.getReservationsBetween(weekStart, weekEnd, filterDate, filterGroup));
    map.put("timerange", date + " " + BookingRoomUtils.getHoursAndMinutes(startStr) + " - "
            + BookingRoomUtils.getHoursAndMinutes(endStr));

    String displayed = String.format(
            messageSource.getMessage("bookRoom.displayed.week", null, RequestContextUtils.getLocale(request)),
            BookingRoomUtils.getDate(weekStart), BookingRoomUtils.getDate(weekEnd));

    boolean filtered = false;

    if (filterDate != null) {//filter of date
        filtered = true;
        displayed = messageSource.getMessage("bookRoom.displayed.day", null,
                RequestContextUtils.getLocale(request)) + " " + filterDate;
    }

    if (filterGroup > 0) {
        filtered = true;
        displayed += (filterDate == null ? "," : " and") + " "
                + messageSource.getMessage("bookRoom.displayed.group", null,
                        RequestContextUtils.getLocale(request))
                + " " + getResearchGroup(filterGroup).getTitle();
    }

    if (filtered) {//we must verify that there are no reservations in selected range
        GregorianCalendar start = BookingRoomUtils.getCalendar(startStr);
        GregorianCalendar end = BookingRoomUtils.getCalendar(endStr);
        List<Reservation> coll = reservationDao.getReservationsBetween(start, end);
        if (coll.size() > 0) {
            //if the collision exists
            collisions = true;
            map.put("collisions", coll);
            map.put("collisionsCount", coll.size());
        }
    }

    map.put("displayed", displayed);

    map.put("collisionsExist", (collisions) ? "1" : "0");

    /*
    -- JSP can get this from params object --
    map.put("repCount", repCount);
    map.put("repType", repType);
    map.put("group", group);
    map.put("date", date);*/
    map.put("startTime", BookingRoomUtils.getHoursAndMinutes(startStr).replaceAll(":", ""));
    map.put("endTime", BookingRoomUtils.getHoursAndMinutes(endStr).replaceAll(":", ""));
    map.put("loggedUser", personDao.getLoggedPerson());
    GroupMultiController.setPermissionToRequestGroupRole(map, personDao.getLoggedPerson());

    return map;
}

From source file:org.kuali.continuity.admin.main.server.SimpleServiceImpl.java

Date getDateFromString(String dateString) {
    GregorianCalendar gc = new GregorianCalendar();
    gc.set(Calendar.MONTH, Integer.parseInt(dateString.substring(0, 2)) - 1);
    gc.set(Calendar.DATE, Integer.parseInt(dateString.substring(3, 5)));
    gc.set(Calendar.YEAR, Integer.parseInt(dateString.substring(6, 10)));
    Date ret = gc.getTime();/* www  .  j a v a2  s  .  co  m*/
    return ret;
}

From source file:gr.abiss.calipso.controller.AbstractServiceBasedRestController.java

@RequestMapping(value = "reports", produces = { "application/json" }, method = RequestMethod.GET)
@ResponseBody//  w  ww  .  j a va 2  s.co m
//@ApiOperation(value = "reports", httpMethod = "GET")
public Page<ReportDataSet> getReportDatasets(

        @RequestParam(value = "page", required = false, defaultValue = "1") Integer page,
        @RequestParam(value = "size", required = false, defaultValue = "10") Integer size,
        @RequestParam(value = "properties", required = false, defaultValue = "id") String sort,
        @RequestParam(value = "direction", required = false, defaultValue = "ASC") String direction,

        @RequestParam(value = "timeUnit", required = false, defaultValue = "DAY") TimeUnit timeUnit,
        @RequestParam(value = "dateField", required = false, defaultValue = "createdDate") String dateField,
        @RequestParam(value = "period", required = false) String period,
        @RequestParam(value = "reportType", required = false) String reportType) {

    if (StringUtils.isBlank(period)) {
        GregorianCalendar now = new GregorianCalendar();
        StringBuffer buff = new StringBuffer();
        if (timeUnit.equals(TimeUnit.DAY)) {
            buff.append(now.get(Calendar.MONTH)).append('/');
        }
        period = buff.append(now.get(Calendar.YEAR)).toString();
    }
    LOGGER.info("getReportDatasets, timeUnit: " + timeUnit + ", dateField: " + dateField + ", period: " + period
            + ", reportName: " + reportType);
    GregorianCalendar start = null;
    GregorianCalendar end = null;
    if (timeUnit.equals(TimeUnit.DAY)) {
        String[] monthYear = period.split("/");
        start = new GregorianCalendar(Integer.parseInt(monthYear[1]), Integer.parseInt(monthYear[0]) - 1, 0);
        end = new GregorianCalendar(Integer.parseInt(monthYear[1]), Integer.parseInt(monthYear[0]) - 1, 0);
        end.set(Calendar.DAY_OF_MONTH, end.getActualMaximum(Calendar.DAY_OF_MONTH));
    } else {
        start = new GregorianCalendar(Integer.parseInt(period), 0, 0);
        end = new GregorianCalendar(Integer.parseInt(period), 11, 0);
        end.set(Calendar.DAY_OF_MONTH, end.getActualMaximum(Calendar.DAY_OF_MONTH));
    }

    start.set(Calendar.HOUR_OF_DAY, start.getMinimum(Calendar.HOUR_OF_DAY));
    start.set(Calendar.MINUTE, start.getMinimum(Calendar.MINUTE));
    start.set(Calendar.SECOND, start.getMinimum(Calendar.SECOND));
    start.set(Calendar.MILLISECOND, start.getMinimum(Calendar.MILLISECOND));

    end.set(Calendar.HOUR_OF_DAY, end.getMinimum(Calendar.HOUR_OF_DAY));
    end.set(Calendar.MINUTE, end.getMinimum(Calendar.MINUTE));
    end.set(Calendar.SECOND, end.getMinimum(Calendar.SECOND));
    end.set(Calendar.MILLISECOND, end.getMinimum(Calendar.MILLISECOND));

    Map<String, String[]> paramsMap = request.getParameterMap();
    LOGGER.info("getReportDatasets, timeUnit: " + timeUnit + ", dateField: " + dateField + ", dateFrom: "
            + start + ", dateTo: " + end + ", reportName: " + reportType);
    Pageable pageable = buildPageable(page, size, sort, direction, paramsMap);
    Page<ReportDataSet> results = this.service.getReportDatasets(pageable, timeUnit, dateField, start.getTime(),
            end.getTime(), reportType);
    LOGGER.info("getReportDatasets returning " + results.getTotalElements());
    return results;
}