List of usage examples for java.util GregorianCalendar add
@Override public void add(int field, int amount)
From source file:de.fhbingen.wbs.wpOverview.tabs.AvailabilityGraph.java
/** * Set the view to DAY.//from w w w. ja va 2 s . co m */ private void setDayView() { actualStart = (GregorianCalendar) actualDay.clone(); actualStart.set(Calendar.HOUR_OF_DAY, 0); actualStart.set(Calendar.MINUTE, 0); actualStart.add(Calendar.HOUR, -1); actualEnd = (GregorianCalendar) actualDay.clone(); actualEnd.set(Calendar.HOUR_OF_DAY, 23); actualEnd.set(Calendar.MINUTE, 59); actualEnd.add(Calendar.HOUR, 1); actualView = DAY; GregorianCalendar helper = (GregorianCalendar) actualEnd.clone(); helper.add(Calendar.DATE, -1); makeChart(new SimpleDateFormat("EEEE, dd.MM.yyyy").format(helper.getTime())); }
From source file:de.fhbingen.wbs.wpOverview.tabs.AvailabilityGraph.java
/** * Set the view to YEAR./*from ww w.ja va 2s. co m*/ */ private void setYearView() { actualStart = (GregorianCalendar) actualDay.clone(); actualStart.set(Calendar.DAY_OF_YEAR, actualDay.getActualMinimum(Calendar.DAY_OF_YEAR)); actualStart.set(Calendar.HOUR, 0); actualStart.set(Calendar.MINUTE, 0); actualStart.add(Calendar.DAY_OF_YEAR, -1); actualEnd = (GregorianCalendar) actualDay.clone(); actualEnd.set(Calendar.DAY_OF_YEAR, actualDay.getActualMaximum(Calendar.DAY_OF_YEAR)); actualEnd.set(Calendar.HOUR, 23); actualEnd.set(Calendar.MINUTE, 59); actualView = YEAR; GregorianCalendar helper = (GregorianCalendar) actualEnd.clone(); helper.add(Calendar.DATE, -1); makeChart(new SimpleDateFormat("yyyy").format(helper.getTime())); }
From source file:org.eurekastreams.server.persistence.TabGroupMapperTest.java
/** * Verify the configurable time window for permanent deletion of a Tab - for a tab that's still within the window. * //from w w w .ja v a2s . c o m * @throws TabDeletionException * thrown on exception deleting the tab. */ @Test public void testDeletedTabWithinWindowShouldRemainAfterAnotherDelete() throws TabDeletionException { final int undeleteTabWindowInMinutes = 110; final int minutesSinceTestTabWasDeleted = 100; // set the undelete tab window jpaTabGroupMapper.setUndeleteTabWindowInMinutes(undeleteTabWindowInMinutes); // set the date the tab was deleted GregorianCalendar tabDeletionDate = new GregorianCalendar(); tabDeletionDate.add(Calendar.MINUTE, -minutesSinceTestTabWasDeleted); getEntityManager() .createQuery("update versioned Tab set " + "dateDeleted = :deletedTimestamp " + "where id = :tabId") .setParameter("deletedTimestamp", tabDeletionDate.getTime()) .setParameter("tabId", fordsDeletedTabId).executeUpdate(); // delete the active tab jpaTabGroupMapper.deleteTab(jpaTabMapper.findById(fordsFirstTabId)); // make sure that the deleted tab is still available int resultCount = getEntityManager() .createQuery("select version from Tab where id = :tabId and deleted = true") .setParameter("tabId", fordsDeletedTabId).getResultList().size(); assertEquals( "After deleting a Tab, the Tab that was deleted within the undo window should still be present.", 1, resultCount); }
From source file:org.eurekastreams.server.persistence.TabGroupMapperTest.java
/** * Verify the configurable time window for permanent deletion of a Tab - for a tab that's outside the window. * /* w w w .ja va 2 s.c om*/ * @throws TabDeletionException * thrown on exception deleting the tab. */ @Test public void testDeletedTabOutsideWindowShouldBePermanentlyDeletedAfterAnotherDelete() throws TabDeletionException { final int undeleteTabWindowInMinutes = 90; final int minutesSinceTestTabWasDeleted = 100; // set the undelete tab window jpaTabGroupMapper.setUndeleteTabWindowInMinutes(undeleteTabWindowInMinutes); // set the date the tab was deleted GregorianCalendar tabDeletionDate = new GregorianCalendar(); tabDeletionDate.add(Calendar.MINUTE, -minutesSinceTestTabWasDeleted); getEntityManager() .createQuery("update versioned Tab set " + "dateDeleted = :deletedTimestamp " + "where id = :tabId") .setParameter("deletedTimestamp", tabDeletionDate.getTime()) .setParameter("tabId", fordsDeletedTabId).executeUpdate(); // delete the active tab jpaTabGroupMapper.deleteTab(jpaTabMapper.findById(fordsFirstTabId)); // make sure that the deleted tab is still available int resultCount = getEntityManager() .createQuery("select version from Tab where id = :tabId and deleted = true") .setParameter("tabId", fordsDeletedTabId).getResultList().size(); assertEquals("After deleting a Tab, the Tab that was deleted outside the undo " + "window should still be permanently deleted.", 0, resultCount); }
From source file:de.fhbingen.wbs.wpOverview.tabs.AvailabilityGraph.java
/** * Set the view to MONTH./*from w w w . ja va 2s .c om*/ */ private void setMonthView() { actualStart = (GregorianCalendar) actualDay.clone(); actualStart.set(Calendar.DAY_OF_MONTH, 1); actualStart.set(Calendar.HOUR, 0); actualStart.set(Calendar.MINUTE, 0); actualEnd = (GregorianCalendar) actualDay.clone(); actualEnd.set(Calendar.DAY_OF_MONTH, actualEnd.getActualMaximum(Calendar.DAY_OF_MONTH)); actualEnd.set(Calendar.HOUR, 23); actualEnd.set(Calendar.MINUTE, 59); actualStart.add(Calendar.HOUR, -1); actualEnd.add(Calendar.HOUR, 1); actualView = MONTH; GregorianCalendar helper = (GregorianCalendar) actualEnd.clone(); helper.add(Calendar.DATE, -1); makeChart(new SimpleDateFormat("MMMM yyyy").format(helper.getTime())); }
From source file:de.fhbingen.wbs.wpOverview.tabs.AvailabilityGraph.java
/** * Set the view to WEEK.//from w ww . j av a2s . c om */ private void setWeekView() { actualStart = (GregorianCalendar) actualDay.clone(); actualStart.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY); actualStart.set(Calendar.HOUR_OF_DAY, 0); actualStart.set(Calendar.MINUTE, 0); actualEnd = (GregorianCalendar) actualDay.clone(); actualEnd.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY); actualEnd.set(Calendar.HOUR_OF_DAY, 23); actualEnd.set(Calendar.MINUTE, 59); actualStart.add(Calendar.HOUR_OF_DAY, -1); actualEnd.add(Calendar.HOUR_OF_DAY, 1); actualView = WEEK; GregorianCalendar helper = (GregorianCalendar) actualEnd.clone(); helper.add(Calendar.DATE, -1); makeChart(LocalizedStrings.getGeneralStrings().calendarWeekAbbreviation() + " " + new SimpleDateFormat("ww yyyy").format(helper.getTime())); }
From source file:org.nuclos.common2.SeriesUtils.java
/** * //from www . j a va 2s .c o m * @param series * @param dateOrigin * @return the next date calculated by series from origin. * origin could be a calculated date (result >= origin) */ public static DateTime getSeriesNext(String series, DateTime dateOrigin) { if (series == null) return dateOrigin; GregorianCalendar calendar = new GregorianCalendar(); calendar.setTime(dateOrigin.getDate()); String[] split = org.apache.commons.lang.StringUtils.split(series, '|'); if (split.length > 0) { String modus = split[0]; if ("d".equals(modus)) { int hour = Integer.parseInt(split[1]); int minute = Integer.parseInt(split[2]); calendar.set(GregorianCalendar.HOUR_OF_DAY, hour); calendar.set(GregorianCalendar.MINUTE, minute); int days = Integer.parseInt(split[3]); if (days == 0) { // add one day if calculated date is before origin if (calendar.getTime().before(dateOrigin.getDate())) { calendar.add(GregorianCalendar.DAY_OF_MONTH, 1); } while (!isWorkingDay(calendar.get(GregorianCalendar.DAY_OF_WEEK))) { calendar.add(GregorianCalendar.DAY_OF_MONTH, 1); } } else { // add one day if calculated date is before origin if (calendar.getTime().before(dateOrigin.getDate())) { calendar.add(GregorianCalendar.DAY_OF_MONTH, 1); } if (days > 1) { calendar.add(GregorianCalendar.DAY_OF_MONTH, days - 1); } } } else if ("w".equals(modus)) { int hour = Integer.parseInt(split[1]); int minute = Integer.parseInt(split[2]); calendar.set(GregorianCalendar.HOUR_OF_DAY, hour); calendar.set(GregorianCalendar.MINUTE, minute); int weeks = Integer.parseInt(split[3]); List<Integer> possibleWeekdays = new ArrayList<Integer>(); int firstSelectedWeekday = -1000; int lastWeekday = -1000; // use getWeekdayItems() in order to get the right start (end) of the week for (SeriesListItem sli : getWeekdayItems()) { boolean addWeekday = false; switch (sli.getId()) { case GregorianCalendar.MONDAY: if (split[4].equals("0") ? false : true) addWeekday = true; break; case GregorianCalendar.TUESDAY: if (split[5].equals("0") ? false : true) addWeekday = true; break; case GregorianCalendar.WEDNESDAY: if (split[6].equals("0") ? false : true) addWeekday = true; break; case GregorianCalendar.THURSDAY: if (split[7].equals("0") ? false : true) addWeekday = true; break; case GregorianCalendar.FRIDAY: if (split[8].equals("0") ? false : true) addWeekday = true; break; case GregorianCalendar.SATURDAY: if (split[9].equals("0") ? false : true) addWeekday = true; break; case GregorianCalendar.SUNDAY: if (split[10].equals("0") ? false : true) addWeekday = true; break; } if (addWeekday) { possibleWeekdays.add(sli.getId()); if (firstSelectedWeekday == -1000) firstSelectedWeekday = sli.getId(); } lastWeekday = sli.getId(); } // add one day if calculated date is before origin boolean weeksAdded = false; if (calendar.getTime().before(dateOrigin.getDate())) { if (lastWeekday == calendar.get(GregorianCalendar.DAY_OF_WEEK)) { calendar.add(GregorianCalendar.WEEK_OF_YEAR, weeks - 1); weeksAdded = true; } else { calendar.add(GregorianCalendar.DAY_OF_MONTH, 1); } } while (!possibleWeekdays.contains(new Integer(calendar.get(GregorianCalendar.DAY_OF_WEEK)))) { if (!weeksAdded && lastWeekday == calendar.get(GregorianCalendar.DAY_OF_WEEK)) { calendar.add(GregorianCalendar.WEEK_OF_YEAR, weeks - 1); } calendar.add(GregorianCalendar.DAY_OF_MONTH, 1); } } else if ("m".equals(modus)) { int hour = Integer.parseInt(split[1]); int minute = Integer.parseInt(split[2]); calendar.set(GregorianCalendar.HOUR_OF_DAY, hour); calendar.set(GregorianCalendar.MINUTE, minute); if ("m1".equals(split[3])) { int day = Integer.parseInt(split[4]); int months = Integer.parseInt(split[5]); calendar.set(GregorianCalendar.DAY_OF_MONTH, day); // add one month if calculated date is before origin if (calendar.getTime().before(dateOrigin.getDate())) { calendar.add(GregorianCalendar.MONTH, 1); calendar.set(GregorianCalendar.DAY_OF_MONTH, day); } if (months > 1) { calendar.add(GregorianCalendar.MONTH, months - 1); calendar.set(GregorianCalendar.DAY_OF_MONTH, day); } } else { int number = Integer.parseInt(split[4]); int weekday = Integer.parseInt(split[5]); int months = Integer.parseInt(split[6]); calendar.set(GregorianCalendar.DAY_OF_WEEK, weekday); calendar.set(GregorianCalendar.DAY_OF_WEEK_IN_MONTH, number); // add one month if calculated date is before origin if (calendar.getTime().before(dateOrigin.getDate())) { calendar.add(GregorianCalendar.MONTH, 1); calendar.set(GregorianCalendar.DAY_OF_WEEK, weekday); calendar.set(GregorianCalendar.DAY_OF_WEEK_IN_MONTH, number); } if (months > 1) { calendar.add(GregorianCalendar.MONTH, months - 1); calendar.set(GregorianCalendar.DAY_OF_WEEK, weekday); calendar.set(GregorianCalendar.DAY_OF_WEEK_IN_MONTH, number); } } } else if ("y".equals(modus)) { int hour = Integer.parseInt(split[1]); int minute = Integer.parseInt(split[2]); calendar.set(GregorianCalendar.HOUR_OF_DAY, hour); calendar.set(GregorianCalendar.MINUTE, minute); if ("y1".equals(split[3])) { int day = Integer.parseInt(split[4]); int month = Integer.parseInt(split[5]); calendar.set(GregorianCalendar.MONTH, month); calendar.set(GregorianCalendar.DAY_OF_MONTH, day); // add one year if calculated date is before origin if (calendar.getTime().before(dateOrigin.getDate())) { calendar.add(GregorianCalendar.YEAR, 1); calendar.set(GregorianCalendar.MONTH, month); calendar.set(GregorianCalendar.DAY_OF_MONTH, day); } } else { int number = Integer.parseInt(split[4]); int weekday = Integer.parseInt(split[5]); int month = Integer.parseInt(split[6]); calendar.set(GregorianCalendar.MONTH, month); calendar.set(GregorianCalendar.DAY_OF_WEEK, weekday); calendar.set(GregorianCalendar.DAY_OF_WEEK_IN_MONTH, number); // add one year if calculated date is before origin if (calendar.getTime().before(dateOrigin.getDate())) { calendar.add(GregorianCalendar.YEAR, 1); calendar.set(GregorianCalendar.MONTH, month); calendar.set(GregorianCalendar.DAY_OF_WEEK, weekday); calendar.set(GregorianCalendar.DAY_OF_WEEK_IN_MONTH, number); } } } } return new DateTime(calendar.getTimeInMillis()); }
From source file:edu.umm.radonc.ca_dash.controllers.HistogramController.java
public void onSelectTimePeriod() { GregorianCalendar gc = new GregorianCalendar(); gc.setTime(startDate);/*from ww w.j a v a 2 s . com*/ switch (interval) { case "1wk": gc.add(Calendar.DATE, 7); endDate = gc.getTime(); break; case "1m": gc.add(Calendar.MONTH, 1); endDate = gc.getTime(); break; case "3m": gc.add(Calendar.MONTH, 3); endDate = gc.getTime(); break; case "6m": gc.add(Calendar.MONTH, 6); endDate = gc.getTime(); break; case "1y": gc.add(Calendar.YEAR, 1); endDate = gc.getTime(); break; case "2y": gc.add(Calendar.YEAR, 2); endDate = gc.getTime(); break; case "3y": gc.add(Calendar.YEAR, 3); endDate = gc.getTime(); break; case "Q1": gc.setTime(FiscalDate.getQuarter(1)); startDate = gc.getTime(); gc.add(Calendar.MONTH, 3); endDate = gc.getTime(); break; case "Q2": gc.setTime(FiscalDate.getQuarter(2)); startDate = gc.getTime(); gc.add(Calendar.MONTH, 3); endDate = gc.getTime(); break; case "Q3": gc.setTime(FiscalDate.getQuarter(3)); startDate = gc.getTime(); gc.add(Calendar.MONTH, 3); endDate = gc.getTime(); break; case "Q4": gc.setTime(FiscalDate.getQuarter(4)); startDate = gc.getTime(); gc.add(Calendar.MONTH, 3); endDate = gc.getTime(); break; } }
From source file:org.getobjects.appserver.publisher.GoResource.java
@Override public void appendToResponse(final WOResponse _r, final WOContext _ctx) { URLConnection con = null;/*w ww .j a v a 2 s . co m*/ try { con = this.url.openConnection(); } catch (IOException coe) { log.warn("could not open connection to url: " + this.url); _r.setStatus(WOMessage.HTTP_STATUS_NOT_FOUND); return; } /* open stream */ InputStream is = null; try { is = con.getInputStream(); } catch (IOException ioe) { log.warn("could not open stream to url: " + this.url); _r.setStatus(WOMessage.HTTP_STATUS_NOT_FOUND); return; } /* transfer */ try { String mimeType = con.getContentType(); if (mimeType == null || "content/unknown".equals(mimeType)) mimeType = mimeTypeForPath(this.url.getPath()); if (mimeType == null) mimeType = "application/octet-stream"; _r.setHeaderForKey(mimeType, "content-type"); _r.setHeaderForKey("" + con.getContentLength(), "content-length"); /* setup caching headers */ Date now = new Date(); GregorianCalendar cal = new GregorianCalendar(); cal.setTime(new Date(con.getLastModified())); _r.setHeaderForKey(WOMessage.httpFormatDate(cal), "last-modified"); cal.setTime(now); _r.setHeaderForKey(WOMessage.httpFormatDate(cal), "date"); cal.add(Calendar.SECOND, this.expirationIntervalForMimeType(mimeType)); _r.setHeaderForKey(WOMessage.httpFormatDate(cal), "expires"); /* start streaming */ _r.enableStreaming(); byte[] buffer = new byte[0xFFFF]; for (int len; (len = is.read(buffer)) != -1;) _r.appendContentData(buffer, len); } catch (IOException e) { log.error("IO error trying to deliver resource: " + this.url, e); _r.setStatus(WOMessage.HTTP_STATUS_INTERNAL_ERROR); } finally { try { if (is != null) is.close(); } catch (IOException e) { log.warn("could not close URL input stream: " + this.url, e); } } }
From source file:org.getobjects.appserver.publisher.JoResource.java
@Override public void appendToResponse(WOResponse _r, WOContext _ctx) { URLConnection con = null;//from ww w.ja v a 2 s . c om try { con = this.url.openConnection(); } catch (IOException coe) { log.warn("could not open connection to url: " + this.url); _r.setStatus(WOMessage.HTTP_STATUS_NOT_FOUND); return; } /* open stream */ InputStream is = null; try { is = con.getInputStream(); } catch (IOException ioe) { log.warn("could not open stream to url: " + this.url); _r.setStatus(WOMessage.HTTP_STATUS_NOT_FOUND); return; } /* transfer */ try { String mimeType = con.getContentType(); if (mimeType == null || "content/unknown".equals(mimeType)) mimeType = mimeTypeForPath(this.url.getPath()); if (mimeType == null) mimeType = "application/octet-stream"; _r.setHeaderForKey(mimeType, "content-type"); _r.setHeaderForKey("" + con.getContentLength(), "content-length"); /* setup caching headers */ Date now = new Date(); GregorianCalendar cal = new GregorianCalendar(); cal.setTime(new Date(con.getLastModified())); _r.setHeaderForKey(WOMessage.httpFormatDate(cal), "last-modified"); cal.setTime(now); _r.setHeaderForKey(WOMessage.httpFormatDate(cal), "date"); cal.add(Calendar.SECOND, this.expirationIntervalForMimeType(mimeType)); _r.setHeaderForKey(WOMessage.httpFormatDate(cal), "expires"); /* start streaming */ _r.enableStreaming(); byte[] buffer = new byte[0xFFFF]; for (int len; (len = is.read(buffer)) != -1;) _r.appendContentData(buffer, len); } catch (IOException e) { log.error("IO error trying to deliver resource: " + this.url, e); _r.setStatus(WOMessage.HTTP_STATUS_INTERNAL_ERROR); } finally { try { if (is != null) is.close(); } catch (IOException e) { log.warn("could not close URL input stream: " + this.url, e); } } }