List of usage examples for java.util GregorianCalendar get
public int get(int field)
From source file:TimePeriod.java
/** * Setzt den bis-Wert auf einen der Standard-Typen * //from w ww. j a v a2 s . c om * @param neuertyp */ public void setToTyp(int neuertyp) { this.to_typ = neuertyp; if (from_typ != to_typ) typ = -1; else typ = neuertyp; switch (neuertyp) { case TODAY: to = new GregorianCalendar(); set2359(to); break; case YESTERDAY: to = new GregorianCalendar(); set2359(to); to.setTimeInMillis(to.getTimeInMillis() - ONE_DAY); break; case THIS_WEEK: to = new GregorianCalendar(); int day_of_week = to.get(Calendar.DAY_OF_WEEK); // unsere Woche beginnt am Montag. Montag hat den Wert 2 int day_offset_von; // wenn es sonntag ist, wird die zurck liegende woche betrachtet if (day_of_week == 1) { day_offset_von = -6; } else { day_offset_von = 2 - day_of_week; } // bis ist logischerweise 6-Tage nach von int day_offset_bis = day_offset_von + 6; set2359(to); to.setTimeInMillis(to.getTimeInMillis() + ONE_DAY * day_offset_bis); break; case LAST_WEEK: // wie diese woche, nur 7 tage weiter zurck to = new GregorianCalendar(); int day_of_week2 = to.get(Calendar.DAY_OF_WEEK); // unsere Woche beginnt am Montag. Montag hat den Wert 2 int day_offset_von2; // wenn es sonntag ist, wird die zurck liegende woche betrachtet if (day_of_week2 == 1) { day_offset_von2 = -13; } else { day_offset_von2 = -5 - day_of_week2; } // bis ist logischerweise 6-Tage nach von int day_offset_bis2 = day_offset_von2 + 6; set2359(to); to.setTimeInMillis(to.getTimeInMillis() + ONE_DAY * day_offset_bis2); break; case THIS_MONTH: GregorianCalendar temp = new GregorianCalendar(); setMidnight(temp); temp.set(Calendar.DAY_OF_MONTH, 1); to = new GregorianCalendar(); set2359(to); // wann der letzte tag im monat ist ist unklar, also solange weiter // gehen, // bis der neue monat anfngt, dann einen tag zurck while (to.get(Calendar.MONTH) == temp.get(Calendar.MONTH)) to.setTimeInMillis(to.getTimeInMillis() + ONE_DAY); // Jetzt wieder einen tag zurck to.setTimeInMillis(to.getTimeInMillis() - ONE_DAY); break; case LAST_MONTH: GregorianCalendar temp2 = new GregorianCalendar(); setMidnight(temp2); temp2.set(Calendar.DAY_OF_MONTH, 1); // der erste tag des letzten Monats ist vielleicht nicht mehr in // diesem Jahr, also // rckwrts laufen, bis wieder ein erster Tag gefunden wird temp2.setTimeInMillis(temp2.getTimeInMillis() - ONE_DAY); to = new GregorianCalendar(); to.setTimeInMillis(temp2.getTimeInMillis()); set2359(to); break; case THIS_JEAR: to = new GregorianCalendar(); set2359(to); to.set(Calendar.MONTH, 11); to.set(Calendar.DAY_OF_MONTH, 31); break; case LAST_JEAR: to = new GregorianCalendar(); int jahr = to.get(Calendar.YEAR); jahr--; set2359(to); to.set(Calendar.MONTH, 11); to.set(Calendar.DAY_OF_MONTH, 31); to.set(Calendar.YEAR, jahr); break; case EVER: to = new GregorianCalendar(); int jahr2 = to.get(Calendar.YEAR); set2359(to); to.set(Calendar.MONTH, 11); to.set(Calendar.DAY_OF_MONTH, 31); to.set(Calendar.YEAR, jahr2); break; } // Von darf nicht nach bis liegen, ist bis schon initialisiert, so muss // es angepasst werden if (from != null) if (to.before(from)) { from.setTimeInMillis(to.getTimeInMillis()); setMidnight(from); from_typ = to_typ; } }
From source file:org.eclipse.uomo.util.impl.Iso8601Date.java
/** * /*from ww w . ja v a2 s . c om*/ * @param date * the date to set the component fields to * @param timezone * - what to do about timezone (CLEAR, SETLOCAL or IGNORE) */ public void setAsDate(Date date, int timezone) { GregorianCalendar cal = new GregorianCalendar(); cal.setTime(date); reset(timezone != IGNORE); year = cal.get(Calendar.YEAR); month = cal.get(Calendar.MONTH) + 1; // java Month starts from 0, but // ours starts from 1 day = cal.get(Calendar.DAY_OF_MONTH); hour = cal.get(Calendar.HOUR_OF_DAY); minute = cal.get(Calendar.MINUTE); second = cal.get(Calendar.SECOND); milli = cal.get(Calendar.MILLISECOND); if (timezone == CLEAR) { tzHour = 0; tzMinute = 0; tzNegative = null; } else if (timezone == SETLOCAL) { TimeZone tzLcl = TimeZone.getDefault(); int offset = tzLcl.getOffset(date.getTime()); if (offset < 0) { tzNegative = new Boolean(true); offset = -offset; } else { tzNegative = new Boolean(true); } tzHour = offset / (1000 * 60 * 60); tzMinute = (offset - (tzHour * 1000 * 60 * 60)) / (1000 * 60); } }
From source file:org.webical.test.web.component.WeekViewPanelTest.java
public void testWeekUse() throws WebicalException { MockCalendarManager mockCalendarManager = (MockCalendarManager) annotApplicationContextMock .getBean("calendarManager"); Calendar calendar1 = mockCalendarManager.getCalendarById("1"); MockEventManager mockEventManager = new MockEventManager(); annotApplicationContextMock.putBean("eventManager", mockEventManager); SimpleDateFormat dateFormat = new SimpleDateFormat( WebicalSession.getWebicalSession().getUserSettings().getTimeFormat(), getTestSession().getLocale()); final GregorianCalendar currentDate = CalendarUtils.newTodayCalendar(getFirstDayOfWeek()); // All events for this week List<Event> allEvents = new ArrayList<Event>(); Date midWeek = CalendarUtils.getFirstDayOfWeek(currentDate.getTime(), getFirstDayOfWeek()); midWeek = CalendarUtils.addDays(midWeek, 3); /* CREATE EVENTS TO RENDER */ GregorianCalendar cal = CalendarUtils.duplicateCalendar(currentDate); // Add a normal event this week Event event = new Event(); event.setUid("e1"); event.setCalendar(calendar1);// w w w .j av a 2 s.c om event.setSummary("Normal Event Description"); event.setLocation("Normal Event Location"); event.setDescription("Event e1"); cal.setTime(midWeek); cal.set(GregorianCalendar.HOUR_OF_DAY, 12); 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 Tuesday, ending Friday event = new Event(); event.setUid("e2"); event.setCalendar(calendar1); event.setSummary("Recurring Event Yesterday"); event.setLocation("Recurring Event Location"); event.setDescription("Event e2"); cal.setTime(midWeek); cal.set(GregorianCalendar.HOUR_OF_DAY, 15); cal.add(GregorianCalendar.DAY_OF_MONTH, -1); event.setDtStart(cal.getTime()); cal.add(GregorianCalendar.HOUR_OF_DAY, 3); cal.add(GregorianCalendar.DAY_OF_MONTH, 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 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.setTime(midWeek); cal.set(GregorianCalendar.HOUR_OF_DAY, 9); 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 Monday midnight, ending Tuesday 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 Monday 00:00 hours, ending Tuesday 00:00 hours"); cal.setTime(midWeek); cal.add(GregorianCalendar.DAY_OF_MONTH, -2); 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 Friday 14.00 hours and ending Saturday 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.setTime(midWeek); cal.add(GregorianCalendar.DAY_OF_MONTH, 2); cal.set(GregorianCalendar.HOUR_OF_DAY, 14); cal.set(GregorianCalendar.MINUTE, 0); event.setDtStart(cal.getTime()); cal.add(GregorianCalendar.DAY_OF_MONTH, 1); 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); // 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, 7, 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); // Set the correct dates to find the first and last day of the week // Assert number of days rendered GregorianCalendar weekFirstDayCalendar = CalendarUtils.duplicateCalendar(currentDate); weekFirstDayCalendar.setTime(CalendarUtils.getFirstDayOfWeek(currentDate.getTime(), getFirstDayOfWeek())); // Assert the first day in the view wicketTester.assertComponent(PanelTestPage.PANEL_MARKUP_ID + ":weekColumnRepeater:day" + weekFirstDayCalendar.get(GregorianCalendar.DAY_OF_YEAR), WeekDayPanel.class); GregorianCalendar weekLastDayCalendar = CalendarUtils.duplicateCalendar(currentDate); weekLastDayCalendar.setTime(CalendarUtils.getLastDayOfWeek(currentDate.getTime(), getFirstDayOfWeek())); // Assert the last day in the view wicketTester.assertComponent(PanelTestPage.PANEL_MARKUP_ID + ":weekColumnRepeater:day" + weekLastDayCalendar.get(GregorianCalendar.DAY_OF_YEAR), WeekDayPanel.class); // Events for days in this week List<Event> dayEvents = new ArrayList<Event>(); // Assert weekday events GregorianCalendar weekCal = CalendarUtils.duplicateCalendar(currentDate); weekCal.setTime(CalendarUtils.getFirstDayOfWeek(currentDate.getTime(), getFirstDayOfWeek())); for (int i = 0; i < 7; ++i) { WeekDayPanel weekDayEventsListView = (WeekDayPanel) wicketTester.getLastRenderedPage() .get(PanelTestPage.PANEL_MARKUP_ID + ":weekColumnRepeater:day" + weekCal.get(GregorianCalendar.DAY_OF_YEAR)); int weekDay = getFirstDayOfWeek() + weekCal.get(GregorianCalendar.DAY_OF_WEEK) - 1; // First day of the week is 1 if (weekDay > 7) weekDay = 1; switch (weekDay) { case GregorianCalendar.SUNDAY: dayEvents.clear(); dayEvents.add(allEvents.get(2)); // e3 break; case GregorianCalendar.MONDAY: dayEvents.clear(); dayEvents.add(allEvents.get(2)); // e3 dayEvents.add(allEvents.get(3)); // e4 break; case GregorianCalendar.TUESDAY: dayEvents.clear(); dayEvents.add(allEvents.get(1)); // e2 dayEvents.add(allEvents.get(2)); // e3 break; case GregorianCalendar.WEDNESDAY: dayEvents.clear(); dayEvents.add(allEvents.get(0)); // e1 dayEvents.add(allEvents.get(1)); // e2 dayEvents.add(allEvents.get(2)); // e3 break; case GregorianCalendar.THURSDAY: dayEvents.clear(); dayEvents.add(allEvents.get(1)); // e2 dayEvents.add(allEvents.get(2)); // e3 break; case GregorianCalendar.FRIDAY: dayEvents.clear(); dayEvents.add(allEvents.get(1)); // e2 dayEvents.add(allEvents.get(2)); // e3 dayEvents.add(allEvents.get(4)); // e5 break; case GregorianCalendar.SATURDAY: dayEvents.clear(); dayEvents.add(allEvents.get(2)); // e3 dayEvents.add(allEvents.get(4)); // e5 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()); // only e4 is an all day event else assertEquals(0, bhvs.size()); if (evt.getUid().equals("e5")) { // e5: Fri 14:00 to Sat 16:00 String timePath = item.getPageRelativePath() + ":eventLink:eventTime"; String timeLabelText = null; if (weekDay == GregorianCalendar.FRIDAY) timeLabelText = dateFormat.format(evt.getDtStart()); else timeLabelText = dateFormat.format(midWeek); // time 00:00 wicketTester.assertLabel(timePath, timeLabelText); } } weekCal.add(GregorianCalendar.DAY_OF_WEEK, 1); } }
From source file:org.apache.unomi.services.services.SegmentServiceImpl.java
private GregorianCalendar getDay(int offset) { GregorianCalendar gc = new GregorianCalendar(); gc = new GregorianCalendar(gc.get(Calendar.YEAR), gc.get(Calendar.MONTH), gc.get(Calendar.DAY_OF_MONTH)); gc.add(Calendar.DAY_OF_MONTH, offset); return gc;/*from w ww . j a va2 s.com*/ }
From source file:com.ccserver.digital.service.LOSService.java
private XMLGregorianCalendar dateToXMLGregorianCalendar(Date date) { if (date == null) { return null; }/* www . ja v a 2 s .c o m*/ try { GregorianCalendar gregory = new GregorianCalendar(); gregory.setTime(date); return DatatypeFactory.newInstance() .newXMLGregorianCalendarDate(gregory.get(Calendar.YEAR), gregory.get(Calendar.MONTH) + 1, gregory.get(Calendar.DAY_OF_MONTH), DatatypeConstants.FIELD_UNDEFINED) .normalize(); } catch (DatatypeConfigurationException e) { logger.error(Utils.getErrorFormatLog("LOSService", "dateToXMLGregorianCalendar", "", "Can not convert from LocalDateTime to XMLGregorianCalenda", e.toString())); } return null; }
From source file:org.webical.test.web.component.MonthViewPanelTest.java
/** * Test rendering with events.// w w w . j a va 2s . 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:org.orcid.persistence.adapter.impl.Jpa2JaxbAdapterImpl.java
private XMLGregorianCalendar toXMLGregorianCalendarWithoutTime(Date date) { if (date != null) { GregorianCalendar c = new GregorianCalendar(); c.setTime(date);//ww w .j a v a2s . co m XMLGregorianCalendar xmlGregorianCalendar = datatypeFactory.newXMLGregorianCalendar(); xmlGregorianCalendar.setDay(c.get(Calendar.DAY_OF_MONTH)); xmlGregorianCalendar.setMonth(c.get(Calendar.MONTH) + 1); xmlGregorianCalendar.setYear(c.get(Calendar.YEAR)); return xmlGregorianCalendar; } else { return null; } }
From source file:fhtw.lvplan.LV_PlanActivity.java
@Override public void onCreate(Bundle savedInstanceState) { /*View title = getWindow().findViewById(android.R.id.title); View titleBar = (View) title.getParent(); titleBar.setBackgroundColor(Color.parseColor("#0087c7"));*/ try {/*w w w.j a va 2 s .c o m*/ super.onCreate(savedInstanceState); setContentView(R.layout.main); epView = (ExpandableListView) findViewById(R.id.expandableListView1); Settings set = SettingsManager.getInstance(this.getBaseContext()).getSettingsInstance(); //Read Credentials if existing, if not --> Open Credentials Dialog to create settings if (set == null) { CredDialog.showChangelog = true; startCredDialog(); } else { //Check if Calendar already downloaded... //Downloaded is true per default if (DOWNLOADED) { if (set.getLastUpdate() != null) { GregorianCalendar now = new GregorianCalendar(); //Validate Update Interval settings. switch (set.getUpdateInterval()) { case STARTUP: DownloadFromUrl(); break; case DAILY: long delta = now.getTimeInMillis() - set.getLastUpdate().getTimeInMillis(); if (delta >= 24 * 60 * 60 * 100) { DownloadFromUrl(); } else if (delta > 0) { if (now.get(Calendar.DAY_OF_YEAR) > set.getLastUpdate().get(Calendar.DAY_OF_YEAR)) { DownloadFromUrl(); } } break; case MONTHLY: if (now.get(Calendar.YEAR) > set.getLastUpdate().get(Calendar.YEAR)) { DownloadFromUrl(); } else if (now.get(Calendar.MONTH) > set.getLastUpdate().get(Calendar.MONTH)) { DownloadFromUrl(); } break; default: // MANUAL do nothing break; } } List<LvPlanEntries> entries = CalendarReader.getLvPlanEntries(); if (entries == null) { ReadCalender(); //Reread if there aren't any } else { this.UpateCalendarUI(entries); } } else { DownloadFromUrl(); } //Verify if newer version installed if (Changelog.verifyVersionChanged(this)) { Changelog.viewChangelog(this); } } //Init List mAdapter = new MyExpandableListAdapter(this, groups, children); epView.setAdapter(mAdapter); } catch (Exception ex) { Log.d("OnCreate", "Exception: ", ex); } }
From source file:org.agnitas.util.AgnUtils.java
public static boolean dayListIncludes(List<GregorianCalendar> listOfDays, GregorianCalendar day) { for (GregorianCalendar listDay : listOfDays) { if (listDay.get(Calendar.DAY_OF_YEAR) == day.get(Calendar.DAY_OF_YEAR)) return true; }//from ww w. j a v a 2 s . co m return false; }
From source file:ca.uhn.fhir.model.primitive.BaseDateTimeDt.java
@Override protected String encode(Date theValue) { if (theValue == null) { return null; } else {/*from w ww. java 2 s .c om*/ GregorianCalendar cal; if (myTimeZoneZulu) { cal = new GregorianCalendar(TimeZone.getTimeZone("GMT")); } else if (myTimeZone != null) { cal = new GregorianCalendar(myTimeZone); } else { cal = new GregorianCalendar(); } cal.setTime(theValue); StringBuilder b = new StringBuilder(); leftPadWithZeros(cal.get(Calendar.YEAR), 4, b); if (myPrecision.ordinal() > TemporalPrecisionEnum.YEAR.ordinal()) { b.append('-'); leftPadWithZeros(cal.get(Calendar.MONTH) + 1, 2, b); if (myPrecision.ordinal() > TemporalPrecisionEnum.MONTH.ordinal()) { b.append('-'); leftPadWithZeros(cal.get(Calendar.DATE), 2, b); if (myPrecision.ordinal() > TemporalPrecisionEnum.DAY.ordinal()) { b.append('T'); leftPadWithZeros(cal.get(Calendar.HOUR_OF_DAY), 2, b); b.append(':'); leftPadWithZeros(cal.get(Calendar.MINUTE), 2, b); if (myPrecision.ordinal() > TemporalPrecisionEnum.MINUTE.ordinal()) { b.append(':'); leftPadWithZeros(cal.get(Calendar.SECOND), 2, b); if (myPrecision.ordinal() > TemporalPrecisionEnum.SECOND.ordinal()) { b.append('.'); b.append(myFractionalSeconds); for (int i = myFractionalSeconds.length(); i < 3; i++) { b.append('0'); } } } if (myTimeZoneZulu) { b.append('Z'); } else if (myTimeZone != null) { int offset = myTimeZone.getOffset(theValue.getTime()); if (offset >= 0) { b.append('+'); } else { b.append('-'); offset = Math.abs(offset); } int hoursOffset = (int) (offset / DateUtils.MILLIS_PER_HOUR); leftPadWithZeros(hoursOffset, 2, b); b.append(':'); int minutesOffset = (int) (offset % DateUtils.MILLIS_PER_HOUR); minutesOffset = (int) (minutesOffset / DateUtils.MILLIS_PER_MINUTE); leftPadWithZeros(minutesOffset, 2, b); } } } } return b.toString(); } }