List of usage examples for java.util Calendar clone
@Override
public Object clone()
From source file:com.xpn.xwiki.plugin.calendar.CalendarData.java
public void addCalendarData(CalendarEvent event) { SimpleDateFormat df = new SimpleDateFormat("yyMMdd"); Calendar cdateStart = event.getDateStart(); String dateEnd = df.format(event.getDateEnd().getTime()); Calendar crtDate = (Calendar) cdateStart.clone(); List evtList;/*from w w w. ja v a 2s. co m*/ do { evtList = (List) this.cdata.get(df.format(crtDate.getTime())); if (evtList == null) { evtList = new ArrayList(); } evtList.add(event); this.cdata.put(df.format(crtDate.getTime()), evtList); crtDate.add(Calendar.DATE, 1); } while (df.format(crtDate.getTime()).compareTo(dateEnd) <= 0); }
From source file:fr.paris.lutece.plugins.calendar.service.Utils.java
/** * Returns the Week as a formatted string corresponding to the date code * @return The week label//from w w w . ja v a 2 s. c o m * @param locale The locale used for display settings * @param strDate The date code */ public static String getWeekLabel(String strDate, Locale locale) { Calendar calendar = new GregorianCalendar(); Calendar calendarFirstDay = new GregorianCalendar(); Calendar calendarLastDay = new GregorianCalendar(); calendar.set(Utils.getYear(strDate), Utils.getMonth(strDate), Utils.getDay(strDate)); int nDayOfWeek = calendar.get(Calendar.DAY_OF_WEEK); if (nDayOfWeek == 1) { nDayOfWeek = 8; } calendarFirstDay = calendar; calendarFirstDay.add(Calendar.DATE, Calendar.MONDAY - nDayOfWeek); calendarLastDay = (GregorianCalendar) calendarFirstDay.clone(); calendarLastDay.add(Calendar.DATE, 6); String strFormat = AppPropertiesService.getProperty(Constants.PROPERTY_LABEL_FORMAT_DATE_OF_DAY); DateFormat formatDate = new SimpleDateFormat(strFormat, locale); String strLabelFirstDay = formatDate.format(calendarFirstDay.getTime()); String strLabelLastDay = formatDate.format(calendarLastDay.getTime()); calendarFirstDay.clear(); calendarLastDay.clear(); return strLabelFirstDay + "-" + strLabelLastDay; }
From source file:org.apache.flume.sink.customhdfs.add.ImpalaTableFill.java
private TimeStage getTimeStage(String nowTimeStr) { TimeStage timestage = new TimeStage(); try {/*from w w w . j a va 2s . c o m*/ Date date = new SimpleDateFormat(this.partitionFormat).parse(nowTimeStr); Calendar calendar = Calendar.getInstance(); calendar.setTime(date); timestage.end = calendar.getTimeInMillis(); Calendar calendarStart = (Calendar) calendar.clone(); setLastTime(calendarStart); timestage.start = calendarStart.getTimeInMillis(); } catch (ParseException e) { LOG.error("impalaTableFillError:" + e.getMessage()); } LOG.info("time range:" + timestage.toString()); return timestage; }
From source file:info.raack.appliancelabeler.service.DefaultDataServiceTest.java
@Test public void userLabelsWithoutDownSpikeAreNotAccepted() { // off label is now, on label was 30 seconds ago Calendar userOffLabelCal = new GregorianCalendar(); Calendar userOnLabelCal = (Calendar) userOffLabelCal.clone(); userOnLabelCal.add(Calendar.SECOND, -30); // ted time is 2 minutes ahead of actual time Calendar tedEndCal = (Calendar) userOffLabelCal.clone(); tedEndCal.add(Calendar.SECOND, 120); Calendar tedStartCal = (Calendar) tedEndCal.clone(); tedStartCal.add(Calendar.SECOND, -30); Map<String, OAuthConsumerToken> map = mock(Map.class); when(database.getOAuthTokensForUserId("theuserid")).thenReturn(map); when(energyMonitor.getCurrentMonitorTime(argThat(new IsMatchingOAuthData(map)))) .thenReturn(tedEndCal.getTime()); UserAppliance userAppliance = mock(UserAppliance.class); when(database.getUserApplianceById(1)).thenReturn(userAppliance); when(detectionManager.detectAcceptableUserTraining(energyMonitor, tedStartCal.getTime(), tedEndCal.getTime())).thenReturn(LabelResult.NO_POWER_DECREASE); // run test/* w w w. j a v a 2 s. co m*/ LabelResult result = dataService.createUserGeneratedLabelsForUserApplianceId(energyMonitor, 1, userOnLabelCal.getTime(), userOffLabelCal.getTime(), false); assertEquals(LabelResult.NO_POWER_DECREASE, result); }
From source file:info.raack.appliancelabeler.service.DefaultDataServiceTest.java
@Test public void userLabelsWithoutUpSpikeAreNotAccepted() { // off label is now, on label was 30 seconds ago Calendar userOffLabelCal = new GregorianCalendar(); Calendar userOnLabelCal = (Calendar) userOffLabelCal.clone(); userOnLabelCal.add(Calendar.SECOND, -30); // ted time is 2 minutes ahead of actual time Calendar tedEndCal = (Calendar) userOffLabelCal.clone(); tedEndCal.add(Calendar.SECOND, 120); Calendar tedStartCal = (Calendar) tedEndCal.clone(); tedStartCal.add(Calendar.SECOND, -30); Map<String, OAuthConsumerToken> map = mock(Map.class); when(database.getOAuthTokensForUserId("theuserid")).thenReturn(map); when(energyMonitor.getCurrentMonitorTime(argThat(new IsMatchingOAuthData(map)))) .thenReturn(tedEndCal.getTime()); UserAppliance userAppliance = mock(UserAppliance.class); when(database.getUserApplianceById(1)).thenReturn(userAppliance); when(detectionManager.detectAcceptableUserTraining(energyMonitor, tedStartCal.getTime(), tedEndCal.getTime())).thenReturn(LabelResult.NO_POWER_INCREASE); // run test//from w w w.j av a2 s. c o m LabelResult result = dataService.createUserGeneratedLabelsForUserApplianceId(energyMonitor, 1, userOnLabelCal.getTime(), userOffLabelCal.getTime(), false); assertEquals(LabelResult.NO_POWER_INCREASE, result); }
From source file:info.raack.appliancelabeler.service.DefaultDataServiceTest.java
@Test public void userLabelsWithoutGoingDownToNormalPowerAreNotAccepted() { // off label is now, on label was 30 seconds ago Calendar userOffLabelCal = new GregorianCalendar(); Calendar userOnLabelCal = (Calendar) userOffLabelCal.clone(); userOnLabelCal.add(Calendar.SECOND, -30); // ted time is 2 minutes ahead of actual time Calendar tedEndCal = (Calendar) userOffLabelCal.clone(); tedEndCal.add(Calendar.SECOND, 120); Calendar tedStartCal = (Calendar) tedEndCal.clone(); tedStartCal.add(Calendar.SECOND, -30); Map<String, OAuthConsumerToken> map = mock(Map.class); when(database.getOAuthTokensForUserId("theuserid")).thenReturn(map); when(energyMonitor.getCurrentMonitorTime(argThat(new IsMatchingOAuthData(map)))) .thenReturn(tedEndCal.getTime()); UserAppliance userAppliance = mock(UserAppliance.class); when(database.getUserApplianceById(1)).thenReturn(userAppliance); when(detectionManager.detectAcceptableUserTraining(energyMonitor, tedStartCal.getTime(), tedEndCal.getTime())).thenReturn(LabelResult.NOT_TURNED_OFF); // run test/*w w w . j av a2 s . com*/ LabelResult result = dataService.createUserGeneratedLabelsForUserApplianceId(energyMonitor, 1, userOnLabelCal.getTime(), userOffLabelCal.getTime(), false); assertEquals(LabelResult.NOT_TURNED_OFF, result); }
From source file:nl.strohalm.cyclos.services.transactions.TicketServiceImpl.java
@Override public int processExpiredTickets(final Calendar time) { // Get tickets that expired before the last hour final Calendar createdBefore = (Calendar) time.clone(); createdBefore.add(Calendar.HOUR_OF_DAY, -1); // Search tickets final TicketQuery query = new TicketQuery(); query.setResultType(ResultType.ITERATOR); query.setStatus(Ticket.Status.PENDING); query.setCreatedBefore(createdBefore); int count = 0; // Expire each one final List<? extends Ticket> expired = ticketDao.search(query); for (final Ticket ticket : expired) { ticket.setStatus(Ticket.Status.EXPIRED); ticketDao.update(ticket);//from w ww . j a v a 2s . c om count++; } return count; }
From source file:info.raack.appliancelabeler.service.DefaultDataServiceTest.java
@Test public void goodUserLabelsAreAccepted() { // off label is now, on label was 30 seconds ago Calendar userOffLabelCal = new GregorianCalendar(); Calendar userOnLabelCal = (Calendar) userOffLabelCal.clone(); userOnLabelCal.add(Calendar.SECOND, -30); // ted time is 2 minutes ahead of actual time Calendar tedEndCal = (Calendar) userOffLabelCal.clone(); tedEndCal.add(Calendar.SECOND, 120); Calendar tedStartCal = (Calendar) tedEndCal.clone(); tedStartCal.add(Calendar.SECOND, -30); Map<String, OAuthConsumerToken> map = mock(Map.class); when(database.getOAuthTokensForUserId("theuserid")).thenReturn(map); when(energyMonitor.getCurrentMonitorTime(argThat(new IsMatchingOAuthData(map)))) .thenReturn(tedEndCal.getTime()); UserAppliance userAppliance = mock(UserAppliance.class); when(database.getUserApplianceById(1)).thenReturn(userAppliance); when(detectionManager.detectAcceptableUserTraining(energyMonitor, tedStartCal.getTime(), tedEndCal.getTime())).thenReturn(LabelResult.OK); // run test/*from w ww .j a v a 2s .c o m*/ LabelResult result = dataService.createUserGeneratedLabelsForUserApplianceId(energyMonitor, 1, userOnLabelCal.getTime(), userOffLabelCal.getTime(), false); assertEquals(LabelResult.OK, result); Calendar onLabelCal = (Calendar) userOnLabelCal.clone(); // go five seconds into start date onLabelCal.add(Calendar.SECOND, 120); Calendar offLabelCal = (Calendar) userOffLabelCal.clone(); offLabelCal.add(Calendar.SECOND, 120); List<ApplianceStateTransition> transitions = new ArrayList<ApplianceStateTransition>(); GenericStateTransition on = new GenericStateTransition(-1, userAppliance, 0, true, onLabelCal.getTimeInMillis()); GenericStateTransition off = new GenericStateTransition(-1, userAppliance, 0, false, offLabelCal.getTimeInMillis()); transitions.add(on); transitions.add(off); // verify that labels were added verify(database, times(1)).storeUserOnOffLabels(transitions); }
From source file:org.apache.beehive.controls.system.jdbc.JdbcControlImpl.java
/** * Sets the {@link Calendar} used when working with time/date types *///from w ww . j av a 2 s . co m public void setDataSourceCalendar(Calendar cal) { _cal = (Calendar) cal.clone(); }
From source file:org.nuxeo.ecm.core.test.StorageConfiguration.java
private Calendar convertToStoredCalendar(Calendar calendar) { if (isVCSMySQL() || isVCSSQLServer()) { Calendar result = (Calendar) calendar.clone(); result.setTimeInMillis(convertToStoredTimestamp(result.getTimeInMillis())); return result; }//from w w w . jav a2 s .c om return calendar; }