List of usage examples for java.util Calendar clone
@Override
public Object clone()
From source file:info.raack.appliancedetection.common.util.DateUtils.java
public Calendar getPreviousFiveMinuteIncrement(Calendar calOrig) { Calendar cal = (Calendar) calOrig.clone(); // round start time to 5 minute marker to greatly simplify evaluation cal.add(Calendar.MILLISECOND, -1 * cal.get(Calendar.MILLISECOND)); cal.add(Calendar.SECOND, -1 * cal.get(Calendar.SECOND)); cal.add(Calendar.MINUTE, -1 * cal.get(Calendar.MINUTE) % 5); return cal;/*from ww w . j a v a2 s .com*/ }
From source file:info.raack.appliancedetection.common.util.DateUtils.java
public Calendar getNextFiveMinuteIncrement(Calendar calOrig) { Calendar cal = (Calendar) calOrig.clone(); // round start time to 5 minute marker to greatly simplify evaluation cal.add(Calendar.MILLISECOND, -1 * cal.get(Calendar.MILLISECOND)); cal.add(Calendar.SECOND, -1 * cal.get(Calendar.SECOND)); cal.add(Calendar.MINUTE, 5 + -1 * cal.get(Calendar.MINUTE) % 5); return cal;/* w w w . j a v a2 s. c o m*/ }
From source file:com.bt.sdk.callcontrol.demo.standup.MapHousekeeper.java
private void housekeepConferenceFutures() { for (String key : conferenceFutures.keySet()) { // Test conference 3:1905:2008:01:07 String[] parts = key.split(":"); Calendar now = Calendar.getInstance(); Calendar then = (Calendar) now.clone(); then.set(Integer.parseInt(parts[2]), Integer.parseInt(parts[3]), Integer.parseInt(parts[4])); //System.out.println(now); //System.out.println(then); if (then.before(now)) { log.info(String.format("removing old conferenceFuture: %s", key)); conferenceFutures.remove(key); keysToRemove.add(key);/* w w w .j a va2 s . c o m*/ } } }
From source file:com.clustercontrol.systemlog.bean.SyslogMessage.java
/** * syslog????????SyslogMessage????API<br> * <br>/*from ww w .j a v a 2 s .c om*/ * <b>???</b><br> * 1. ???????????????<br> * 2. ???????????<br> * @param syslog syslog? * @return SyslogMessage * @throws ParseException syslog??????????? * @throws HinemosUnknown */ public static SyslogMessage parse(String syslog) throws ParseException, HinemosUnknown { if (log.isDebugEnabled()) { log.debug("parsing syslog : " + syslog); } // [0]:, [1]:(MMM), [2]:(dd), [3]:(HH), [4]:(mm), [5]:(ss), [6]:??, [7]: // ?{1,date,MMM dd HH:mm:ss}????????????1970???? // ????????2/29???3/1?????(1970???????) MessageFormat syslogFormat = new MessageFormat("<{0,number,integer}>{1} {2} {3}:{4}:{5} {6} {7}", Locale.ENGLISH); // ?????? Object[] syslogArgs = syslogFormat.parse(syslog); // RFC3164?????????????????? if ("".equals(syslogArgs[SYSLOG_FORMAT_DAY])) { syslogFormat = new MessageFormat("<{0,number,integer}>{1} {2} {3}:{4}:{5} {6} {7}", Locale.ENGLISH); syslogArgs = syslogFormat.parse(syslog); } if (syslogArgs == null) throw new HinemosUnknown("different syslog pattern"); if (log.isDebugEnabled()) { int i = 0; for (Object arg : syslogArgs) { log.debug(String.format("syslog args [%d] : %s", i++, arg.toString())); } } // ???????(H) Integer syslogEffectiveTime = HinemosPropertyUtil .getHinemosPropertyNum("monitor.systemlog.period.hour", Long.valueOf(SYSLOG_DEFAULT_PERIOD_HOUR)) .intValue(); // 0??????????? if (syslogEffectiveTime <= 0) { syslogEffectiveTime = SYSLOG_DEFAULT_PERIOD_HOUR; } Calendar nowCal = HinemosTime.getCalendarInstance(); // ??(?) int year = nowCal.get(Calendar.YEAR) + 1; int month = editCalendarMonth((String) syslogArgs[SYSLOG_FORMAT_MONTH]); int dayOfMonth = Integer.parseInt((String) syslogArgs[SYSLOG_FORMAT_DAY]); int hourOfDay = Integer.parseInt((String) syslogArgs[SYSLOG_FORMAT_HH]); int minute = Integer.parseInt((String) syslogArgs[SYSLOG_FORMAT_MM]); int second = Integer.parseInt((String) syslogArgs[SYSLOG_FORMAT_SS]); // ? List<Calendar> checkCalList = new ArrayList<Calendar>(); // (?? Calendar syslogEffectiveCal = (Calendar) nowCal.clone(); syslogEffectiveCal.add(Calendar.HOUR, syslogEffectiveTime); // ??? for (int i = 0; checkCalList.size() < 2; i++) { // ?????? if (LEAPYEAR_CHECK_COUNT <= i) { break; } Calendar syslogCheckCal = new GregorianCalendar(year, month, dayOfMonth, hourOfDay, minute, second); year--; // ???????(??) if (syslogEffectiveCal.compareTo(syslogCheckCal) < 0) { continue; } // ?????????????? if (dayOfMonth != syslogCheckCal.get(Calendar.DAY_OF_MONTH)) { continue; } // ???? checkCalList.add(syslogCheckCal); } Calendar editSyslogCal = null; // ????? if (checkCalList.size() > 0) { long absMinMillis = Long.MAX_VALUE; for (int i = 0; i < checkCalList.size(); i++) { long absDiff = Math.abs(checkCalList.get(i).getTimeInMillis() - nowCal.getTimeInMillis()); if (absDiff < absMinMillis) { // ?????? absMinMillis = absDiff; editSyslogCal = checkCalList.get(i); } } } else { // ?????? editSyslogCal = new GregorianCalendar(nowCal.get(Calendar.YEAR), month, dayOfMonth, hourOfDay, minute, second); log.warn("System log date is invalid : " + syslog); } int pri = ((Long) syslogArgs[SYSLOG_FORMAT_PRIORITY]).intValue(); String hostname = (String) syslogArgs[SYSLOG_FORMAT_HOSTNAME]; String msg = (String) syslogArgs[SYSLOG_FORMAT_MESSAGE]; Date date = editSyslogCal.getTime(); // ?? SyslogMessage instance = new SyslogMessage(getFacility((int) pri), getSeverity((int) pri), date.getTime(), hostname, msg, syslog); if (log.isDebugEnabled()) { log.debug("parsed syslog : " + instance); } return instance; }
From source file:de.lemo.apps.application.DateWorkerImpl.java
public int daysBetween(final Date startDate, final Date endDate) { // TODO see daysBetween(Calendar, Calendar) final Calendar startDateTemp = Calendar.getInstance(); final Calendar endDateTemp = (Calendar) startDateTemp.clone(); endDateTemp.setTime(endDate);/*w w w.j a va2 s. c o m*/ startDateTemp.setTime(startDate); int daysBetween = 0; while (startDateTemp.before(endDateTemp)) { startDateTemp.add(Calendar.DAY_OF_MONTH, 1); daysBetween++; } return daysBetween; }
From source file:org.dataconservancy.dcs.util.stream.fs.ModifiedSinceFileFilter.java
public ModifiedSinceFileFilter(Calendar modifiedSince) { if (modifiedSince == null) { throw new IllegalArgumentException("modified since must not be null."); }/* ww w . j av a 2 s. c om*/ this.modifiedSince = (Calendar) modifiedSince.clone(); }
From source file:info.raack.appliancelabeler.machinelearning.appliancedetection.algorithms.ApplianceEnergyConsumptionDetectionAlgorithm.java
public AlgorithmPredictions calculateApplianceEnergyUsePredictions(EnergyMonitor monitor, Calendar firstMeasurementDate, Calendar lastMeasurementDate, ItemReader<SecondData> dataReader) { logger.debug("First measurement date: " + firstMeasurementDate.getTime() + "; last measurement date: " + lastMeasurementDate.getTime()); // when is the last 5 minute increment before the first measurement Calendar startDate = dateUtils.getPreviousFiveMinuteIncrement(firstMeasurementDate); Calendar endDate = (Calendar) startDate.clone(); endDate.add(Calendar.MINUTE, 5); // get all of the measurements since that point and add them into the measurements list dataReader.addBeginningItems(/*from ww w . j av a2 s .c o m*/ database.getEnergyMeasurementsForMonitor(monitor, startDate.getTime(), endDate.getTime(), 300)); return algorithmCalculateApplianceEnergyUsePredictions(monitor, getEnergyTimesteps(firstMeasurementDate, lastMeasurementDate), dataReader); }
From source file:hubert.team.paragraphs.AdvertsOverviewModel.java
private Calendar getNextMonth(Calendar ankerMonth) { Calendar increment = (Calendar) ankerMonth.clone(); increment.add(Calendar.MONTH, 1); return increment; }
From source file:hubert.team.paragraphs.AdvertsOverviewModel.java
private Calendar getPrevMonth(Calendar ankerMonth) { Calendar decremented = (Calendar) ankerMonth.clone(); decremented.add(Calendar.MONTH, -1); return decremented; }
From source file:com.redhat.rhn.frontend.action.audit.scap.XccdfSearchAction.java
private DateRangePicker setupDatePicker(DynaActionForm form, HttpServletRequest request) { Calendar today = Calendar.getInstance(); today.setTime(new Date()); Calendar yesterday = (Calendar) today.clone(); yesterday.add(Calendar.DAY_OF_YEAR, -1); return new DateRangePicker(form, request, yesterday.getTime(), today.getTime(), DatePicker.YEAR_RANGE_NEGATIVE, "scapsearch.jsp.start_date", "scapsearch.jsp.end_date"); }