List of usage examples for java.util GregorianCalendar add
@Override public void add(int field, int amount)
From source file:org.vanbest.xmltv.ZiggoGids.java
public static URL programmeUrl(Channel channel, int day, int hour, int period) throws Exception { StringBuilder s = new StringBuilder(epg_data_root); s.append("?channelIDs="); s.append(channel.id);//w w w.java 2s . c om GregorianCalendar cal = new GregorianCalendar(); cal.add(Calendar.DAY_OF_MONTH, day); cal.set(Calendar.HOUR_OF_DAY, hour); cal.set(Calendar.MINUTE, 0); String date = new SimpleDateFormat("yyyy-MM-dd+HH").format(cal.getTime()); s.append("&date=" + date); s.append("&period=" + period); return new URL(s.toString()); }
From source file:org.glite.slcs.caclient.impl.CMPRequest.java
private static CertTemplate makeCertTemplate(CertificateRequest certRequest, String issuerDN) { PKCS10CertificationRequest pkcs10 = new PKCS10CertificationRequest(certRequest.getDEREncoded()); CertificationRequestInfo pkcs10info = pkcs10.getCertificationRequestInfo(); log.debug("Constructing CMP CertTemplate..."); CertTemplate certTemplate = new CertTemplate(); certTemplate.setPublicKey(pkcs10info.getSubjectPublicKeyInfo()); certTemplate.setSubject(pkcs10info.getSubject()); certTemplate.setIssuer(new X509Name(issuerDN)); // validity/*from w ww .j a v a 2 s . c o m*/ OptionalValidity validity = new OptionalValidity(); GregorianCalendar date = new GregorianCalendar(TimeZone.getTimeZone("GMT")); // five minutes extra to before/after date.add(Calendar.MINUTE, -5); Time notBefore = new Time(date.getTime()); date.add(Calendar.MINUTE, 5); // TODO: lifetime fixed to 1 mio seconds, should be possible to configure by user date.add(Calendar.SECOND, 1000000); Time notAfter = new Time(date.getTime()); validity.setNotBefore(notBefore); validity.setNotAfter(notAfter); certTemplate.setValidity(validity); log.debug("Constructed " + certTemplate.toString()); return certTemplate; }
From source file:org.mifos.calendar.CalendarUtils.java
public static DateTime getNextDateForMonthOnDate(final DateTime startDate, final int dayOfMonth, final int every) { final GregorianCalendar gc = new GregorianCalendar(); gc.setTime(startDate.toDate());//from w ww.ja v a 2s . c om gc.add(GregorianCalendar.MONTH, every); int M1 = gc.get(GregorianCalendar.MONTH); gc.set(GregorianCalendar.DATE, dayOfMonth); int M2 = gc.get(GregorianCalendar.MONTH); int daynum = dayOfMonth; while (M1 != M2) { gc.set(GregorianCalendar.MONTH, gc.get(GregorianCalendar.MONTH) - 1); gc.set(GregorianCalendar.DATE, daynum - 1); M2 = gc.get(GregorianCalendar.MONTH); daynum--; } return new DateTime(gc.getTime().getTime()); }
From source file:be.vds.jtbdive.client.view.core.stats.StatChartGenerator.java
private static JFreeChart buildChartForDive(StatQueryObject sqo) { Collection<StatSerie> s = sqo.getValues(); String legend = I18nResourceManager.sharedInstance().getString("dive.times"); TimeSeriesCollection collection = new TimeSeriesCollection(); for (StatSerie statSerie : s) { TimeSeries ts = new TimeSeries(legend); for (StatPoint point : statSerie.getPoints()) { Date dd = (Date) point.getX(); FixedMillisecond day = new FixedMillisecond(dd); Object index = ts.getDataItem(day); if (null != index) { GregorianCalendar gc = new GregorianCalendar(); gc.setTime(dd);/* w ww .j a v a2 s . c o m*/ gc.add(Calendar.MILLISECOND, 1); day = new FixedMillisecond(gc.getTime()); } if (sqo.getStatYAxisParams().getStatYAxis().equals(StatYAxis.DEPTHS)) { ts.add(day, UnitsAgent.getInstance().convertLengthFromModel((Double) point.getY())); } else if (sqo.getStatYAxisParams().getStatYAxis().equals(StatYAxis.TEMPERATURES)) { ts.add(day, UnitsAgent.getInstance().convertTemperatureFromModel((Double) point.getY())); } else { ts.add(day, point.getY()); } } collection.addSeries(ts); } JFreeChart chart = createLineChart(collection, getXLabel(sqo), getYLabel(sqo)); if (sqo.getStatYAxisParams().getStatYAxis().equals(StatYAxis.DIVE_TIME)) { XYPlot xyp = (XYPlot) chart.getPlot(); ((NumberAxis) xyp.getRangeAxis()).setNumberFormatOverride(new HoursMinutesNumberFormat()); } return chart; }
From source file:com.projity.util.DateTime.java
public static long midnightNextDay(long d) { d = dayFloor(d);//from ww w. ja v a 2 s. c o m GregorianCalendar cal = calendarInstance(); cal.setTimeInMillis(d); cal.add(Calendar.DATE, 1); return cal.getTimeInMillis(); }
From source file:de.escoand.readdaily.ReminderHandler.java
public static void startReminder(final Context context, final int hour, final int minute) { Intent intent = new Intent(context, ReminderHandler.class); PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); AlarmManager am = (AlarmManager) context.getSystemService(Activity.ALARM_SERVICE); GregorianCalendar cal = new GregorianCalendar(); // get next reminder cal.set(Calendar.HOUR_OF_DAY, hour); cal.set(Calendar.MINUTE, minute); cal.set(Calendar.SECOND, 0);//from ww w .j a v a 2 s . c o m cal.set(Calendar.MILLISECOND, 0); if (cal.before(Calendar.getInstance())) cal.add(Calendar.DATE, 1); am.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), 24 * 60 * 60 * 1000, pendingIntent); LogHandler.log(Log.WARN, "activated " + hour + ":" + minute); }
From source file:com.projity.util.DateTime.java
public static long nextDay(long day) { GregorianCalendar d = DateTime.calendarInstance(); d.setTimeInMillis(day);//from w ww. j av a2 s . co m d.add(GregorianCalendar.DAY_OF_MONTH, 1); return d.getTimeInMillis(); }
From source file:org.amanzi.neo.core.period.Period.java
/** * add one period/* w ww . jav a 2 s . c om*/ * * @param time - timestamp * @param period - period @see Calendar * @return timestamp+ 1 period */ private static Long addOnePeriod(final Long time, final int period) { final GregorianCalendar cl = new GregorianCalendar(); cl.setTimeInMillis(time); cl.add(period, 1); return cl.getTimeInMillis(); }
From source file:com.thed.zephyr.jenkins.utils.rest.Cycle.java
public static Long createCycle(ZephyrConfigModel zephyrData) { Long cycleId = 0L;// ww w .j a v a 2 s.c o m HttpResponse response = null; try { String createCycleURL = URL_CREATE_CYCLES.replace("{SERVER}", zephyrData.getRestClient().getUrl()); Date date = new Date(); SimpleDateFormat sdf = new SimpleDateFormat("E dd, yyyy hh:mm a"); String dateFormatForCycleCreation = sdf.format(date); JSONObject jObject = new JSONObject(); String cycleName = zephyrData.getCyclePrefix() + dateFormatForCycleCreation; SimpleDateFormat sdf1 = new SimpleDateFormat("dd/MMM/yy"); String startDate = sdf1.format(date); GregorianCalendar gCal = new GregorianCalendar(); if (zephyrData.getCycleDuration().trim().equalsIgnoreCase("30 days")) { gCal.add(Calendar.DAY_OF_MONTH, +29); } else if (zephyrData.getCycleDuration().trim().equalsIgnoreCase("7 days")) { gCal.add(Calendar.DAY_OF_MONTH, +6); } String endDate = sdf1.format(gCal.getTime()); jObject.put("name", cycleName); jObject.put("projectId", zephyrData.getZephyrProjectId()); jObject.put("versionId", zephyrData.getVersionId()); jObject.put("startDate", startDate); jObject.put("endDate", endDate); StringEntity se = new StringEntity(jObject.toString(), "utf-8"); HttpPost createCycleRequest = new HttpPost(createCycleURL); createCycleRequest.setHeader("Content-Type", "application/json"); createCycleRequest.setEntity(se); response = zephyrData.getRestClient().getHttpclient().execute(createCycleRequest, zephyrData.getRestClient().getContext()); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } int statusCode = response.getStatusLine().getStatusCode(); if (statusCode >= 200 && statusCode < 300) { HttpEntity entity = response.getEntity(); String string = null; try { string = EntityUtils.toString(entity); } catch (ParseException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } try { JSONObject cycleObj = new JSONObject(string); cycleId = cycleObj.getLong("id"); } catch (JSONException e) { e.printStackTrace(); } } else if (statusCode == 405) { try { throw new ClientProtocolException("ZAPI plugin license is invalid" + statusCode); } catch (ClientProtocolException e) { e.printStackTrace(); } } else { try { throw new ClientProtocolException("Unexpected response status: " + statusCode); } catch (ClientProtocolException e) { e.printStackTrace(); } } return cycleId; }
From source file:org.openvpms.web.workspace.workflow.scheduling.SchedulingHelper.java
/** * Returns the time of the slot closest to that of the specified time. * * @param time the time/* w w w . j ava 2 s . c o m*/ * @param slotSize the size of the slot, in minutes * @param roundUp if {@code true} round up to the nearest slot, otherwise round down * @return the nearest slot time to {@code time} */ public static Date getSlotTime(Date time, int slotSize, boolean roundUp) { Date result; int mins = getMinutes(time); int nearestSlot = getNearestSlot(mins, slotSize); if (nearestSlot != mins) { if (roundUp) { nearestSlot += slotSize; } GregorianCalendar calendar = new GregorianCalendar(); calendar.setTime(time); calendar.set(Calendar.HOUR_OF_DAY, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); calendar.add(Calendar.MINUTE, nearestSlot); result = calendar.getTime(); } else { result = time; } return result; }