List of usage examples for java.util GregorianCalendar get
public int get(int field)
From source file:iSoron.HistoryChart.java
private void drawSquare(Canvas canvas, RectF location, GregorianCalendar date, int checkmarkOffset) { if (checkmarkOffset >= checkmarks.length) pSquareBg.setColor(colors[0]);//ww w .j av a 2 s . com else pSquareBg.setColor(colors[checkmarks[checkmarkOffset]]); pSquareFg.setColor(reverseTextColor); canvas.drawRect(location, pSquareBg); String text = Integer.toString(date.get(Calendar.DAY_OF_MONTH)); canvas.drawText(text, location.centerX(), location.centerY() + squareTextOffset, pSquareFg); }
From source file:org.openhab.binding.powermax.internal.message.PowermaxCommManager.java
/** * Send a message to set the alarm time and date using the system time and date * * @return true if the message was sent or false if not *///from w w w. jav a 2 s .c om public boolean sendSetTime() { logger.debug("sendSetTime()"); boolean done = false; if (autoSyncTime) { GregorianCalendar cal = new GregorianCalendar(); if (cal.get(Calendar.YEAR) >= 2000) { logger.debug("sendSetTime(): sync time {}", String.format("%02d/%02d/%04d %02d:%02d:%02d", cal.get(Calendar.DAY_OF_MONTH), cal.get(Calendar.MONTH) + 1, cal.get(Calendar.YEAR), cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.MINUTE), cal.get(Calendar.SECOND))); byte[] dynPart = new byte[6]; dynPart[0] = (byte) cal.get(Calendar.SECOND); dynPart[1] = (byte) cal.get(Calendar.MINUTE); dynPart[2] = (byte) cal.get(Calendar.HOUR_OF_DAY); dynPart[3] = (byte) cal.get(Calendar.DAY_OF_MONTH); dynPart[4] = (byte) (cal.get(Calendar.MONTH) + 1); dynPart[5] = (byte) (cal.get(Calendar.YEAR) - 2000); done = sendMessage(new PowermaxBaseMessage(PowermaxSendType.SETTIME, dynPart), false, 0); cal.set(Calendar.MILLISECOND, 0); syncTimeCheck = cal.getTimeInMillis(); } else { logger.info( "Powermax alarm binding: time not synchronized; please correct the date/time of your openHAB server"); syncTimeCheck = null; } } else { syncTimeCheck = null; } return done; }
From source file:edu.stanford.muse.index.IndexUtils.java
public static List<MultiDoc> partitionDocsByInterval(Collection<? extends DatedDocument> allDocs, boolean monthsNotYears) { List<MultiDoc> result = new ArrayList<MultiDoc>(); if (allDocs.size() == 0) return result; Pair<Date, Date> p = EmailUtils.getFirstLast(allDocs); Date first = p.getFirst();//from w w w. j av a 2s . c o m Date last = p.getSecond(); // compute the monthly intervals List<Date> intervals; if (monthsNotYears) intervals = Util.getMonthlyIntervals(first, last); else intervals = Util.getYearlyIntervals(first, last); int nIntervals = intervals.size() - 1; for (int i = 0; i < nIntervals; i++) { String clusterDescription; Date d = intervals.get(i); GregorianCalendar c = new GregorianCalendar(); c.setTime(d); if (!monthsNotYears) clusterDescription = Integer.toString(c.get(Calendar.YEAR)); else clusterDescription = CalendarUtil.getDisplayMonth(c) + " " + c.get(Calendar.YEAR); result.add(new MultiDoc(i, clusterDescription)); } for (DatedDocument ed : allDocs) { // find which interval this email belongs to int selectedInterval = -1; // TODO: if all this API does is either partition by month or year then no need to "search". Date c = ed.date; for (int i = 0; i < nIntervals; i++) { Date intervalStart = intervals.get(i); Date intervalEnd = intervals.get(i + 1); if (!c.before(intervalStart) && c.before(intervalEnd)) { selectedInterval = i; break; } } // this doc goes into interval # selectedInterval MultiDoc whichList = result.get(selectedInterval); whichList.add(ed); } return result; }
From source file:org.jbpm.formModeler.core.processing.formProcessing.Functions.java
public Map getValidDays(String value) { GregorianCalendar gc = new GregorianCalendar(); gc.set(GregorianCalendar.DAY_OF_MONTH, 1); if (value == null || value.equals("") || value.startsWith("/")) { gc.set(GregorianCalendar.MONTH, 0); } else if (value.endsWith("/")) { int month = Integer.decode(value.substring(0, value.indexOf("/"))).intValue(); gc.set(GregorianCalendar.MONTH, month); } else {/*from w ww . ja va 2 s . co m*/ SimpleDateFormat sdf = new SimpleDateFormat("MM/yyyy"); try { gc.setTime(sdf.parse(value)); gc.set(GregorianCalendar.MONTH, gc.get(GregorianCalendar.MONTH) + 1); } catch (Exception e) { log.warn("Error parsing date " + value + " : ", e); } } Map days = new TreeMap(); int month = gc.get(GregorianCalendar.MONTH); while (gc.get(GregorianCalendar.MONTH) == month) { int intValue = gc.get(GregorianCalendar.DAY_OF_MONTH); String key = java.lang.String.valueOf(intValue); if (key.length() == 1) key = "0" + key; days.put(key, key); gc.set(GregorianCalendar.DAY_OF_MONTH, intValue + 1); } return days; }
From source file:TimePeriod.java
/** * Gibt zurck, wie oft der bergebene Wochentag im Zeitraum vorkommt. * //from w w w . j a va 2 s . c o m * @param wochentag * Sonntag = 1 * @return */ public int getNumberOfWeekdays(int wochentag) { int ergebnis = 0; GregorianCalendar temp = new GregorianCalendar(); temp.setTime(from.getTime()); // Schleife ber alle Tage int aktuellerTag; while (temp.before(to)) { aktuellerTag = temp.get(Calendar.DAY_OF_WEEK); if (aktuellerTag == wochentag) ergebnis++; temp.setTimeInMillis(temp.getTimeInMillis() + ONE_DAY); } return ergebnis; }
From source file:org.accada.epcis.repository.query.Schedule.java
/** * Returns true if the hour and all smaller units have been successfully set * to valid values within the set day./*from w w w. java 2 s . c o m*/ * * @param nextSchedule * The current candidate for the result. * @return True if hour and smaller units successfully set to valid values. * @throws ImplementationException * Almost any error. */ private boolean hourMadeValid(final GregorianCalendar nextSchedule) throws ImplementationExceptionResponse { if (!hours.contains(Integer.valueOf(nextSchedule.get(HOUR_OF_DAY))) && !hours.isEmpty()) { if (!setFieldToNextValidRoll(nextSchedule, HOUR_OF_DAY, MINUTE)) { return false; } } // Now we're in a valid hour, make smaller units // valid as well or go to next hour. while (!minuteMadeValid(nextSchedule)) { // No valid minute for this hour, try next hour. if (!setFieldToNextValidRoll(nextSchedule, HOUR_OF_DAY, MINUTE)) { return false; } // Reset all smaller units to min. if (!setFieldsToMinimum(nextSchedule, MINUTE)) { return false; } } return true; }
From source file:oracle.retail.stores.pos.ado.utility.Utility.java
/** This method validates the expiration date. @param expirationDate//from w w w .j av a2 s . c o m @throws TenderException if not a valid expiration date **/ //---------------------------------------------------------------------- public synchronized void validateExpirationDate(String expDate) throws TenderException { GregorianCalendar gc = (GregorianCalendar) Calendar.getInstance(); // get today's date and from that get the current // Month and Year. Date today = new Date(); gc.setTime(today); int thisMonth = gc.get(Calendar.MONTH); int thisYear = gc.get(Calendar.YEAR); gc.clear(); EYSDate expirationDate = parseEncryptedExpirationDate(expDate); // reset the calendar with this tend;er's Exp. Date Calendar c = expirationDate.calendarValue(); gc.setTime(c.getTime()); // if expiration date is before today and // the month and year both do not match the // current month and year, the card must be expired. EYSDate todayEYS = new EYSDate(today); if (expirationDate.before(todayEYS) && !((thisMonth == gc.get(Calendar.MONTH)) && (thisYear == gc.get(Calendar.YEAR)))) { throw new TenderException("Expired", TenderErrorCodeEnum.EXPIRED); } // set the object to nul expirationDate = null; }
From source file:org.accada.epcis.repository.query.Schedule.java
/** * Returns true if the minute and all smaller units have been successfully * set to valid values within the set hour. * /* w ww. j a va 2 s. co m*/ * @param nextSchedule * The current candidate for the result. * @return True if minute and smaller units successfully set to valid * values. * @throws ImplementationException * Almost any error. */ private boolean minuteMadeValid(final GregorianCalendar nextSchedule) throws ImplementationExceptionResponse { if (!minutes.contains(Integer.valueOf(nextSchedule.get(MINUTE))) && !minutes.isEmpty()) { if (!setFieldToNextValidRoll(nextSchedule, MINUTE, SECOND)) { return false; } } // Now we're in a valid minute, make smaller units // valid as well or go to next minute. while (!secondMadeValid(nextSchedule)) { // No valid second for this minute, try next minute. if (!setFieldToNextValidRoll(nextSchedule, MINUTE, SECOND)) { return false; } // Reset all smaller units to min. if (!setFieldToMinimum(nextSchedule, SECOND)) { return false; } } return true; }
From source file:org.accada.epcis.repository.query.Schedule.java
/** * Returns true if the day and all smaller units have been successfully set * to valid values within the set month. * //from www.j a va 2 s . com * @param nextSchedule * The current candidate for the result. * @return True if day and smaller units successfully set to valid values. * @throws ImplementationException * Almost any kind of error. */ private boolean dayMadeValid(final GregorianCalendar nextSchedule) throws ImplementationExceptionResponse { if (!daysOfMonth.contains(Integer.valueOf(nextSchedule.get(DAY_OF_MONTH))) && !daysOfMonth.isEmpty()) { if (!setFieldToNextValidRoll(nextSchedule, DAY_OF_MONTH, HOUR_OF_DAY)) { return false; } } // Check and make this also a valid day of week. while (!daysOfWeek.contains(Integer.valueOf(nextSchedule.get(DAY_OF_WEEK))) && !daysOfWeek.isEmpty()) { if (!setFieldToNextValidRoll(nextSchedule, DAY_OF_MONTH, HOUR_OF_DAY)) { return false; } else if (!daysOfWeek.contains(Integer.valueOf(nextSchedule.get(DAY_OF_WEEK)))) { dayMadeValid(nextSchedule); } } // Now we're in a valid day, make smaller units // valid as well or go to next day. while (!hourMadeValid(nextSchedule)) { // No valid hour for this day, try next day. if (!setFieldToNextValidRoll(nextSchedule, DAY_OF_MONTH, HOUR_OF_DAY)) { return false; } // Reset all smaller units to min. if (!setFieldsToMinimum(nextSchedule, HOUR_OF_DAY)) { return false; } } return true; }
From source file:nl.minbzk.dwr.zoeken.enricher.uploader.ElasticSearchResultUploader.java
/** * Determine the database name, based on the composite key, or null if any of the composite key replacements could not be resolved. * //from ww w .j a va 2 s . c o m * XXX: We only consider the replacement values from the first document given. * * @param name * @param nameComposition * @param namePrerequisitesExpression * @param documents * @return String */ private String determineAlternateDatabaseName(final String name, final String nameComposition, final String namePrerequisitesExpression, final List<Map<String, Object>> documents) { GregorianCalendar calendar = new GregorianCalendar(); calendar.setTime(new Date()); String result; result = nameComposition.replace("{name}", name).trim(); result = result.replace("{year}", format("%04d", calendar.get(calendar.YEAR))); result = result.replace("{month}", format("%02d", calendar.get(calendar.MONTH))); if (documents.size() > 0) { final Map<String, Object> document = documents.get(0); while (result.contains("{") && result.indexOf("}") > result.indexOf("{")) { String fieldName = result.substring(result.indexOf("{") + 1, result.indexOf("}")); if (document.containsKey(fieldName) && !document.get(fieldName).getClass().isArray()) result = result.replace("{" + fieldName + "}", document.get(fieldName).toString()); else { if (logger.isDebugEnabled()) logger.debug(format( "Field '%s' was missing from document with ID '%s' - will revert back to default collection '%s'", fieldName, getReference(document), name)); return null; } } // Also check the pre-requisite expression - only return a composite database name if it's met if (StringUtils.hasText(namePrerequisitesExpression)) { ExpressionParser parser = new SpelExpressionParser(); final Map<String, Object> values = new HashMap<String, Object>(); // XXX: Always get just the first value for (Map.Entry<String, Object> entry : document.entrySet()) if (entry.getValue().getClass().isArray()) values.put(entry.getKey(), ((Object[]) entry.getValue())[0]); else if (entry.getValue() instanceof List) values.put(entry.getKey(), ((List<Object>) entry.getValue()).get(0)); else values.put(entry.getKey(), entry.getValue()); StandardEvaluationContext context = new StandardEvaluationContext(new Object() { public Map<String, Object> getValues() { return values; } }); if (!parser.parseExpression(namePrerequisitesExpression).getValue(context, Boolean.class)) { if (logger.isDebugEnabled()) logger.debug(format( "Pre-requisite expression '%s' failed to match against document with ID '%s' - will revert back to default collection '%s'", namePrerequisitesExpression, getReference(document), name)); return null; } } } return result; }