List of usage examples for java.util GregorianCalendar add
@Override public void add(int field, int amount)
From source file:com.eryansky.common.utils.DateUtil.java
/** * ? ?2009-08-01/*from w w w . ja v a 2 s. com*/ */ public static String subMonth(String strdate) { Date date = new Date(); // ?? String dateresult = null; // // ?? SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); // ? GregorianCalendar gc = new GregorianCalendar(); try { date = df.parse(strdate); // ? } catch (ParseException e) { e.printStackTrace(); } gc.setTime(date); // gc? gc.add(2, -1); // 2?1?(,) // ? gc.set(gc.get(gc.YEAR), gc.get(gc.MONTH), gc.get(gc.DATE)); // ? dateresult = df.format(gc.getTime()); return dateresult; }
From source file:com.eryansky.common.utils.DateUtil.java
/** * ? ?2009-08-01//from w w w. j a v a2s.co m */ public static String subDay(String strdate) { Date date = new Date(); // ?? String dateresult = null; // // ?? SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); // ? GregorianCalendar gc = new GregorianCalendar(); try { date = df.parse(strdate); // ? } catch (ParseException e) { e.printStackTrace(); } gc.setTime(date); // gc? gc.add(5, -1); // 2?1?(....5) // ? gc.set(gc.get(gc.YEAR), gc.get(gc.MONTH), gc.get(gc.DATE)); // ? dateresult = df.format(gc.getTime()); return dateresult; }
From source file:com.eryansky.common.utils.DateUtil.java
/** * ?2009-08-01//from w ww. j a v a 2 s . c o m */ public static String addDay(String strdate) { Date date = new Date(); // ?? String dateresult = null; // // ?? SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); // ? GregorianCalendar gc = new GregorianCalendar(); try { date = df.parse(strdate); // ? } catch (ParseException e) { e.printStackTrace(); } gc.setTime(date); // gc? gc.add(5, 1); // 2?1?(....5) // ? gc.set(gc.get(gc.YEAR), gc.get(gc.MONTH), gc.get(gc.DATE)); // ? dateresult = df.format(gc.getTime()); return dateresult; }
From source file:es.tid.fiware.rss.expenditureLimit.processing.test.ProcessingLimitServiceTest.java
/** * Update control dates//from ww w . j av a 2s . c o m * * @param controls */ private void updateDate(List<DbeExpendControl> controls) { GregorianCalendar cal = (GregorianCalendar) Calendar.getInstance(); cal.setTime(new Date()); cal.add(Calendar.DAY_OF_MONTH, 1); DefaultTransactionDefinition def = new DefaultTransactionDefinition(); def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW); TransactionStatus status = transactionManager.getTransaction(def); for (DbeExpendControl control : controls) { control.setDtNextPeriodStart(cal.getTime()); controlService.createOrUpdate(control); } transactionManager.commit(status); }
From source file:org.eclipse.dirigible.repository.local.FileSystemRepository.java
@Override public void cleanupOldVersions() throws IOException { String versionsRoot = getVersionsPath(); synchronized (this.getClass()) { GregorianCalendar last = new GregorianCalendar(); last.add(Calendar.WEEK_OF_YEAR, -1); thresholdDate = last.getTime();/*from w w w . ja va2s .c om*/ cleanOlderFiles(new File(versionsRoot)); } }
From source file:com.advdb.footballclub.FootBallClub.java
private void generateFactMatch(int opponentIndex, GregorianCalendar cal, int competitionKy, Session session) { int randomDay = randomWithRange(1, 3); cal.add(Calendar.DATE, randomDay); //Random tactic String hqlDT = "from DimTactic dt"; List resultDT = session.createQuery(hqlDT).list(); int tacticIndex = randomWithRange(0, resultDT.size()); //Random player String hqlDP = "from DimPlayer dp"; List resultDP = session.createQuery(hqlDP).list(); HashMap<Integer, FactMatch> playerMap = new HashMap<Integer, FactMatch>(); FactMeasure matchMeasure = new FactMeasure(); matchMeasure.setHalfTimeGoals(randomWithRange(0, 2)); matchMeasure.setFullTimeGoals(// w w w .j a va2 s . c o m randomWithRange(matchMeasure.getHalfTimeGoals(), matchMeasure.getHalfTimeGoals() + 2)); matchMeasure.setShot(randomWithRange(10, 25)); matchMeasure.setFoul(randomWithRange(2, 10)); matchMeasure.setCornner(randomWithRange(5, 15)); matchMeasure.setYellowCard(randomWithRange(0, 5)); int playerIndex; do { playerIndex = randBetween(0, resultDP.size()); if (!playerMap.containsKey(playerIndex)) { FactMeasure m = new FactMeasure(); m.setHalfTimeGoals(randomWithRange(0, matchMeasure.getHalfTimeGoals())); matchMeasure.setHalfTimeGoals(matchMeasure.getHalfTimeGoals() - m.getHalfTimeGoals()); m.setFullTimeGoals(randomWithRange(m.getHalfTimeGoals(), matchMeasure.getFullTimeGoals())); matchMeasure.setFullTimeGoals(matchMeasure.getFullTimeGoals() - m.getFullTimeGoals()); if (matchMeasure.getShot() != 0) { m.setShot(randomWithRange(m.getFullTimeGoals(), matchMeasure.getShot() / 2)); matchMeasure.setShot(matchMeasure.getShot() - m.getShot()); m.setOnTarget(randomWithRange(m.getFullTimeGoals(), m.getShot())); m.setOffTarget(m.getShot() - m.getOnTarget()); } m.setFoul(randomWithRange(0, matchMeasure.getFoul())); matchMeasure.setFoul(matchMeasure.getFoul() - m.getFoul()); int cornnerWeight = 0; if (matchMeasure.getCornner() != 0) { cornnerWeight = randomWithRange(1, matchMeasure.getCornner()); } m.setCornner(randomWithRangeAndWeight(0, matchMeasure.getCornner(), cornnerWeight)); matchMeasure.setCornner(matchMeasure.getCornner() - m.getCornner()); if (matchMeasure.getYellowCard() != 0 && matchMeasure.getYellowCard() >= 2) { m.setYellowCard(randomWithRangeAndWeight(0, matchMeasure.getYellowCard(), matchMeasure.getYellowCard() - 2)); matchMeasure.setYellowCard(matchMeasure.getYellowCard() - m.getYellowCard()); if (m.getYellowCard() == 2) { m.setRedCard(1); matchMeasure.setRedCard(matchMeasure.getRedCard() - 1); } } createDate(session, cal); FactMatch factMatch = new FactMatch(competitionKy, cal.getTime(), opponentIndex, tacticIndex, playerIndex, m.getFullTimeGoals(), m.getHalfTimeGoals(), m.getShot(), m.getOnTarget(), m.getOffTarget(), m.getCornner(), m.getFoul(), m.getYellowCard(), m.getRedCard()); playerMap.put(playerIndex, factMatch); session.save(factMatch); } } while (playerMap.size() != 13); }
From source file:org.apache.tuscany.sca.binding.rest.provider.RESTBindingInvoker.java
public Message invoke(Message msg) { Object entity = null;/*from ww w .j a v a 2 s . c o m*/ Object[] args = msg.getBody(); URI uri = URI.create(endpointReference.getDeployedURI()); UriBuilder uriBuilder = UriBuilder.fromUri(uri); Method method = ((JavaOperation) operation).getJavaMethod(); if (method.isAnnotationPresent(Path.class)) { // Only for resource method uriBuilder.path(method); } if (!JAXRSHelper.isResourceMethod(method)) { // This is RPC over GET uriBuilder.replaceQueryParam("method", method.getName()); } Map<String, Object> pathParams = new HashMap<String, Object>(); Map<String, Object> matrixParams = new HashMap<String, Object>(); Map<String, Object> queryParams = new HashMap<String, Object>(); Map<String, Object> headerParams = new HashMap<String, Object>(); Map<String, Object> formParams = new HashMap<String, Object>(); Map<String, Object> cookieParams = new HashMap<String, Object>(); for (int i = 0; i < method.getParameterTypes().length; i++) { boolean isEntity = true; Annotation[] annotations = method.getParameterAnnotations()[i]; PathParam pathParam = getAnnotation(annotations, PathParam.class); if (pathParam != null) { isEntity = false; pathParams.put(pathParam.value(), args[i]); } MatrixParam matrixParam = getAnnotation(annotations, MatrixParam.class); if (matrixParam != null) { isEntity = false; matrixParams.put(matrixParam.value(), args[i]); } QueryParam queryParam = getAnnotation(annotations, QueryParam.class); if (queryParam != null) { isEntity = false; queryParams.put(queryParam.value(), args[i]); } HeaderParam headerParam = getAnnotation(annotations, HeaderParam.class); if (headerParam != null) { isEntity = false; headerParams.put(headerParam.value(), args[i]); } FormParam formParam = getAnnotation(annotations, FormParam.class); if (formParam != null) { isEntity = false; formParams.put(formParam.value(), args[i]); } CookieParam cookieParam = getAnnotation(annotations, CookieParam.class); if (cookieParam != null) { isEntity = false; cookieParams.put(cookieParam.value(), args[i]); } isEntity = (getAnnotation(annotations, Context.class) == null); if (isEntity) { entity = args[i]; } } for (Map.Entry<String, Object> p : queryParams.entrySet()) { uriBuilder.replaceQueryParam(p.getKey(), p.getValue()); } for (Map.Entry<String, Object> p : matrixParams.entrySet()) { uriBuilder.replaceMatrixParam(p.getKey(), p.getValue()); } uri = uriBuilder.buildFromMap(pathParams); Resource resource = restClient.resource(uri); for (Map.Entry<String, Object> p : headerParams.entrySet()) { resource.header(p.getKey(), String.valueOf(p.getValue())); } for (Map.Entry<String, Object> p : cookieParams.entrySet()) { Cookie cookie = new Cookie(p.getKey(), String.valueOf(p.getValue())); resource.cookie(cookie); } resource.contentType(getContentType()); resource.accept(getAccepts()); //handles declarative headers configured on the composite for (HTTPHeader header : binding.getHttpHeaders()) { //treat special headers that need to be calculated if (header.getName().equalsIgnoreCase("Expires")) { GregorianCalendar calendar = new GregorianCalendar(); calendar.setTime(new Date()); calendar.add(Calendar.HOUR, Integer.parseInt(header.getValue())); resource.header("Expires", HTTPCacheContext.RFC822DateFormat.format(calendar.getTime())); } else { //default behaviour to pass the header value to HTTP response resource.header(header.getName(), header.getValue()); } } Object result = resource.invoke(httpMethod, responseType, entity); msg.setBody(result); return msg; }
From source file:org.vanbest.xmltv.RTL.java
@Override public List<Programme> getProgrammes(List<Channel> channels, int day) throws Exception { List<Programme> result = new LinkedList<Programme>(); Map<String, Channel> channelMap = new HashMap<String, Channel>(); for (Channel c : channels) { if (c.enabled && c.source.equals(getName())) channelMap.put(c.id, c);/*from www .j a va 2 s . c o m*/ } GregorianCalendar now = new GregorianCalendar(); GregorianCalendar date = new GregorianCalendar(now.get(Calendar.YEAR), now.get(Calendar.MONTH), now.get(Calendar.DAY_OF_MONTH)); date.add(Calendar.DAY_OF_MONTH, day); // Note: this fetches all programmes up to and including the // requested date! URL url = programmeUrl(0, day); JSONObject json = fetchJSON(url); // First parse the library JSONArray library = json.getJSONArray("library"); parseLibrary(library); // Then the schedules JSONArray schedules = json.getJSONArray("schedule"); for (int i = 0; i < schedules.size(); i++) { JSONObject schedule = schedules.getJSONObject(i); // Skip programme if station not in channel list String station = schedule.getString("station"); if (!channelMap.containsKey(station)) { if (!config.quiet) logger.trace("Skipping programmes for channel " + station); continue; } Programme prog = createProgramme(schedule, channelMap); if (!prog.startTime.before(date.getTime())) result.add(prog); } return result; }
From source file:org.getobjects.ofs.OFSResourceFileRenderer.java
/** * Stream the given OFSResourceFile object to the response. *//*from w ww. j a va 2 s.c o m*/ public Exception renderObjectInContext(Object _object, final WOContext _ctx) { if (_object == null) return new GoInternalErrorException("got no object to render"); /* retrieve basic info */ final OFSResourceFile doc = (OFSResourceFile) _object; final String mimeType = doc.defaultDeliveryMimeType(); /* start response */ final WOResponse r = _ctx.response(); r.setStatus(WOMessage.HTTP_STATUS_OK); r.setHeaderForKey(mimeType, "content-type"); /* setup caching headers */ final Date now = new Date(); final GregorianCalendar cal = new GregorianCalendar(); cal.setTime(doc.lastModified()); r.setHeaderForKey(WOMessage.httpFormatDate(cal), "last-modified"); cal.setTime(now); r.setHeaderForKey(WOMessage.httpFormatDate(cal), "date"); // TBD: document if (mimeType.startsWith("image/")) cal.add(Calendar.HOUR, 1); else if (mimeType.startsWith("text/css")) cal.add(Calendar.MINUTE, 10); else cal.add(Calendar.SECOND, 5); r.setHeaderForKey(WOMessage.httpFormatDate(cal), "expires"); /* transfer content */ r.setHeaderForKey("" + doc.size(), "content-length"); /* remember that no headers can be set after streaming got activated */ // TODO: this should be ensured by WOResponse if (!r.enableStreaming()) log.warn("could not enable streaming for doc: " + doc); final InputStream is = doc.openStream(); if (is == null) return new GoInternalErrorException("could not open resource stream"); r.resetLastException(); try { byte[] buffer = new byte[0xFFFF]; for (int len; (len = is.read(buffer)) != -1;) r.appendContentData(buffer, len); } catch (IOException e) { return new GoInternalErrorException("failed to read from resource stream"); } finally { try { if (is != null) is.close(); } catch (IOException e) { log.warn("could not close input stream"); } } return r.lastException(); /* WOResponse might have caught an issue */ }
From source file:org.colombbus.tangara.Main.java
private static void checkForUpdate() { Configuration conf = Configuration.instance(); // Check for updates if the feature is enabled in conf if (conf.getInteger("checkUpdate.activation") == 1) { boolean checkUpdate = false; GregorianCalendar today = new GregorianCalendar(); GregorianCalendar lastLaunch = new GregorianCalendar(); lastLaunch.setTimeInMillis(0);//from w w w . j av a 2 s. c o m Properties properties = conf.loadUpdateProperties(); // Read last Launch date if ((properties != null) && (properties.containsKey("checkUpdate.lastLaunch"))) { String strValue = properties.getProperty("checkUpdate.lastLaunch"); long longValue = Long.parseLong(strValue); lastLaunch.setTimeInMillis(longValue); } else { LOG.warn("Failed to load lastLaunch property"); properties = new Properties(); } // Write last Launch date properties.setProperty("checkUpdate.lastLaunch", Long.toString(today.getTimeInMillis())); conf.saveUpdateProperties(properties); String intervalText = Configuration.instance().getProperty("checkUpdate.interval"); if (intervalText.equals("ALWAYS")) { checkUpdate = true; } else if (intervalText.equals("WEEK")) { lastLaunch.add(GregorianCalendar.DAY_OF_MONTH, 7); checkUpdate = (today.after(lastLaunch)); } else if (intervalText.equals("MONTH")) { lastLaunch.add(GregorianCalendar.MONTH, 1); checkUpdate = (today.after(lastLaunch)); } if (checkUpdate) { SoftwareUpdate.launchVersionCheck(); } } }