List of usage examples for java.util Calendar clear
public final void clear()
Calendar
undefined. From source file:org.activiti.crystalball.simulator.PlaybackTest.java
@Test public void testPlaybackRun() throws Exception { System.setProperty("_SIM_DB_PATH", System.getProperty("tempDir", "target") + "/Playback-test"); System.setProperty("liveDB", "target/Playback"); ClassPathXmlApplicationContext appContext = new ClassPathXmlApplicationContext( "/org/activiti/crystalball/simulator/PlaybackSimEngine-h2-context.xml"); HistoryService simHistoryService = (HistoryService) appContext.getBean("simHistoryService"); // init identity service IdentityService identityService = (IdentityService) appContext.getBean("simIdentityService"); identityService.saveGroup(identityService.newGroup("Group1")); identityService.saveUser(identityService.newUser("user1")); identityService.createMembership("user1", "Group1"); SimulationRun simRun = (SimulationRun) appContext.getBean(SimulationRun.class); RepositoryService simRepositoryService = (RepositoryService) appContext.getBean("simRepositoryService"); // deploy processes simRepositoryService.createDeployment() .addClasspathResource("org/activiti/crystalball/simulator/Playback.bpmn").deploy(); Calendar c = Calendar.getInstance(); c.clear(); c.set(2013, 3, 3);//from www .j a v a 2 s . c o m Date startDate = c.getTime(); c.add(Calendar.SECOND, 10); Date finishDate = c.getTime(); // run simulation for 10 seconds simRun.execute(startDate, finishDate); assertEquals(3, simHistoryService.createHistoricProcessInstanceQuery().count()); List<HistoricProcessInstance> processInstances = simHistoryService.createHistoricProcessInstanceQuery() .orderByProcessInstanceStartTime().asc().list(); HistoricProcessInstance processInstance = processInstances.get(0); HistoricVariableInstance variableInstance = simHistoryService.createHistoricVariableInstanceQuery() .processInstanceId(processInstance.getId()).variableName("x").singleResult(); assertEquals(3, ((Integer) variableInstance.getValue()).intValue()); processInstance = processInstances.get(1); variableInstance = simHistoryService.createHistoricVariableInstanceQuery() .processInstanceId(processInstance.getId()).variableName("x").singleResult(); assertEquals(2, ((Integer) variableInstance.getValue()).intValue()); processInstance = processInstances.get(2); variableInstance = simHistoryService.createHistoricVariableInstanceQuery() .processInstanceId(processInstance.getId()).variableName("x").singleResult(); assertEquals(3, ((Integer) variableInstance.getValue()).intValue()); appContext.close(); }
From source file:org.wte4j.FormatDateExpressionTest.java
@Test() public void formateTimeShortTest() { Calendar calendar = Calendar.getInstance(LOCALE); calendar.clear(); calendar.set(1977, 01, 15, 22, 33, 44); testFormat(calendar, "format:time(short) value", "22:33"); }
From source file:org.wte4j.FormatDateExpressionTest.java
@Test() public void formateDateTimeShortTest() { Calendar calendar = Calendar.getInstance(LOCALE); calendar.clear(); calendar.set(1977, 01, 15, 22, 33, 44); testFormat(calendar, "format:dateTime(short, short) value", "15.02.1977 22:33"); }
From source file:edu.wisc.my.stats.query.support.UWDataWareHouseInformationProvider.java
public long getTimeStamp(ResultSet rs, TimeResolution resolution) throws SQLException { final Calendar timeStampCal = Calendar.getInstance(); timeStampCal.clear(); switch (resolution) { case MINUTE://from w w w. ja v a 2 s. co m final int minutes = rs.getInt("MINUTE"); timeStampCal.set(Calendar.MINUTE, minutes); case FIVE_MINUTE: if (!timeStampCal.isSet(Calendar.MINUTE)) { final int fiveMinutes = rs.getInt("FIVE_MINUTE_INCREMENT"); timeStampCal.set(Calendar.MINUTE, (fiveMinutes - 1) * 5); } case HOUR: final int hours = rs.getInt("HOUR"); timeStampCal.set(Calendar.HOUR, hours); case DAY: final int days = rs.getInt("CALENDAR_DAY_NUMBER"); timeStampCal.set(Calendar.DAY_OF_MONTH, days); case WEEK: final int week = rs.getInt("CALENDAR_WEEK_NUMBER"); timeStampCal.set(Calendar.WEEK_OF_YEAR, week); case MONTH: final int months = rs.getInt("CALENDAR_MONTH_NUMBER"); timeStampCal.set(Calendar.MONTH, months - 1); //Dang 0 based months case YEAR: final int years = rs.getInt("CALENDAR_YEAR_NUMBER"); timeStampCal.set(Calendar.YEAR, years); } return timeStampCal.getTimeInMillis(); }
From source file:com.frostwire.search.tbp.TPBSearchResult.java
private long parseCreationTime(String group) { //Today or for whatever minutes ago if (group.contains("Today") || group.contains("<b>")) { return System.currentTimeMillis(); } else if (group.contains("Y-day")) { return System.currentTimeMillis() - (24 * 60 * 60 * 1000); }/*w w w. ja v a 2s . c om*/ Matcher OLDER_DATE_PATTERN_MATCHER = OLDER_DATE_PATTERN.matcher(group); Matcher COMMON_DATE_PATTERN_MATCHER = COMMON_DATE_PATTERN.matcher(group); Matcher DATE_TIME_PATTERN_MATCHER = DATE_TIME_PATTERN.matcher(group); Matcher RIGHT_MATCHER = (OLDER_DATE_PATTERN_MATCHER.matches()) ? OLDER_DATE_PATTERN_MATCHER : COMMON_DATE_PATTERN_MATCHER; if (!RIGHT_MATCHER.matches() && DATE_TIME_PATTERN_MATCHER.matches()) { RIGHT_MATCHER = DATE_TIME_PATTERN_MATCHER; } int month = Integer.parseInt(RIGHT_MATCHER.group(1)); int date = Integer.parseInt(RIGHT_MATCHER.group(2)); int year = 0; if (OLDER_DATE_PATTERN_MATCHER.matches() && OLDER_DATE_PATTERN_MATCHER.groupCount() == 3) { year = Integer.parseInt(RIGHT_MATCHER.group(3)); } else if (COMMON_DATE_PATTERN_MATCHER.matches() || DATE_TIME_PATTERN_MATCHER.matches()) { year = Calendar.getInstance().get(Calendar.YEAR); } Calendar instance = Calendar.getInstance(); instance.clear(); instance.set(year, month, date); return instance.getTimeInMillis(); }
From source file:org.apache.olingo.fit.proxy.v3.EntityRetrieveTestITCase.java
@Test public void navigate() { final Order order = getContainer().getOrder().getByKey(-9).load(); assertEquals(-9, order.getOrderId(), 0); final ConcurrencyInfo concurrency = order.getConcurrency(); assertNotNull(concurrency);// www . jav a2s . c o m final Calendar actual = Calendar.getInstance(); actual.clear(); actual.set(2012, 1, 12, 11, 32, 50); actual.set(Calendar.MILLISECOND, 507); assertEquals(actual.getTimeInMillis(), concurrency.getQueriedDateTime().getTime()); assertEquals(78, order.getCustomerId(), 0); }
From source file:com.pagenews.zhihudaily.homepage.DoubanMomentFragment.java
public void showPickDialog() { Calendar now = Calendar.getInstance(); now.set(mYear, mMonth, mDay);/*from w w w.j a va 2 s .c o m*/ DatePickerDialog dialog = DatePickerDialog.newInstance(new DatePickerDialog.OnDateSetListener() { @Override public void onDateSet(DatePickerDialog view, int year, int monthOfYear, int dayOfMonth) { Calendar temp = Calendar.getInstance(); temp.clear(); temp.set(year, monthOfYear, dayOfMonth); mYear = year; mMonth = monthOfYear; mDay = dayOfMonth; presenter.loadPosts(temp.getTimeInMillis(), true); } }, now.get(Calendar.YEAR), now.get(Calendar.MONTH), now.get(Calendar.DAY_OF_MONTH)); dialog.setMaxDate(Calendar.getInstance()); Calendar minDate = Calendar.getInstance(); minDate.set(2014, 5, 12); dialog.setMinDate(minDate); // set the dialog not vibrate when date change, default value is true dialog.vibrate(false); dialog.show(getActivity().getFragmentManager(), "DatePickerDialog"); }
From source file:org.pivotal.gemfire.cache.CacheRegionQueryUsingToDateTest.java
protected Date createDate(final int year, final int month, final int day) { Calendar dateTime = Calendar.getInstance(); dateTime.clear(); dateTime.set(Calendar.YEAR, year); dateTime.set(Calendar.MONTH, month); dateTime.set(Calendar.DAY_OF_MONTH, day); return dateTime.getTime(); }
From source file:org.activiti.crystalball.simulator.PlaybackTest.java
/** * repeat playback 2 times + 2 seconds (2 new processes are started0 * @throws Exception /*w w w. jav a2s . c o m*/ */ @Test public void testPlayback2Run() throws Exception { System.setProperty("_SIM_DB_PATH", System.getProperty("tempDir", "target") + "/Playback-test2"); System.setProperty("liveDB", "target/Playback"); ClassPathXmlApplicationContext appContext = new ClassPathXmlApplicationContext( "/org/activiti/crystalball/simulator/PlaybackSimEngine-h2-context.xml"); // deploy processes RepositoryService simRepositoryService = (RepositoryService) appContext.getBean("simRepositoryService"); simRepositoryService.createDeployment() .addClasspathResource("org/activiti/crystalball/simulator/Playback.bpmn").deploy(); HistoryService historyService = (HistoryService) appContext.getBean("simHistoryService"); // init identity service IdentityService identityService = (IdentityService) appContext.getBean("simIdentityService"); identityService.saveGroup(identityService.newGroup("Group1")); identityService.saveUser(identityService.newUser("user1")); identityService.createMembership("user1", "Group1"); SimulationRun simRun = (SimulationRun) appContext.getBean(SimulationRun.class); PlaybackScheduleStartProcessEventHandler schedule = (PlaybackScheduleStartProcessEventHandler) appContext .getBean("scheduleProcessEventHandler"); schedule.setRepeatPlayback(true); Calendar c = Calendar.getInstance(); c.clear(); c.set(2013, 3, 3); Date startDate = c.getTime(); c.add(Calendar.SECOND, 12); Date finishDate = c.getTime(); // run simulation for 12 seconds simRun.execute(startDate, finishDate); assertEquals(8, historyService.createHistoricProcessInstanceQuery().count()); List<HistoricProcessInstance> processInstances = historyService.createHistoricProcessInstanceQuery() .orderByProcessInstanceStartTime().asc().list(); HistoricProcessInstance processInstance = processInstances.get(0); HistoricVariableInstance variableInstance = historyService.createHistoricVariableInstanceQuery() .processInstanceId(processInstance.getId()).variableName("x").singleResult(); assertEquals(3, ((Integer) variableInstance.getValue()).intValue()); processInstance = processInstances.get(1); variableInstance = historyService.createHistoricVariableInstanceQuery() .processInstanceId(processInstance.getId()).variableName("x").singleResult(); assertEquals(2, ((Integer) variableInstance.getValue()).intValue()); processInstance = processInstances.get(2); variableInstance = historyService.createHistoricVariableInstanceQuery() .processInstanceId(processInstance.getId()).variableName("x").singleResult(); assertEquals(3, ((Integer) variableInstance.getValue()).intValue()); processInstance = processInstances.get(3); variableInstance = historyService.createHistoricVariableInstanceQuery() .processInstanceId(processInstance.getId()).variableName("x").singleResult(); assertEquals(3, ((Integer) variableInstance.getValue()).intValue()); processInstance = processInstances.get(4); variableInstance = historyService.createHistoricVariableInstanceQuery() .processInstanceId(processInstance.getId()).variableName("x").singleResult(); assertEquals(2, ((Integer) variableInstance.getValue()).intValue()); processInstance = processInstances.get(5); variableInstance = historyService.createHistoricVariableInstanceQuery() .processInstanceId(processInstance.getId()).variableName("x").singleResult(); assertEquals(3, ((Integer) variableInstance.getValue()).intValue()); processInstance = processInstances.get(6); variableInstance = historyService.createHistoricVariableInstanceQuery() .processInstanceId(processInstance.getId()).variableName("x").singleResult(); //user task was not finished yet assertEquals(1, ((Integer) variableInstance.getValue()).intValue()); processInstance = processInstances.get(7); variableInstance = historyService.createHistoricVariableInstanceQuery() .processInstanceId(processInstance.getId()).variableName("x").singleResult(); assertEquals(2, ((Integer) variableInstance.getValue()).intValue()); appContext.close(); }
From source file:org.apache.olingo.fit.proxy.EntityUpdateTestITCase.java
@Test public void patchLink() { // 1. create customer Customer customer = getContainer().newEntityInstance(Customer.class); customer.setPersonID(977);/*from ww w . j a v a 2 s .c o m*/ customer.setFirstName("Test"); customer.setLastName("Test"); final Address homeAddress = getContainer().newComplexInstance(CompanyAddress.class); homeAddress.setStreet("V.le Gabriele D'Annunzio"); homeAddress.setCity("Pescara"); homeAddress.setPostalCode("65127"); customer.setHomeAddress(homeAddress); customer.setNumbers(getContainer().newPrimitiveCollection(String.class)); // empty customer.setEmails(getContainer().newPrimitiveCollection(String.class)); // empty customer.setCity("Pescara"); final Calendar birthday = Calendar.getInstance(); birthday.clear(); birthday.set(1977, 8, 8); customer.setBirthday(new Timestamp(birthday.getTimeInMillis())); customer.setTimeBetweenLastTwoOrders(BigDecimal.valueOf(0.0000002)); // 2. create order and set it to customer final int orderId = RandomUtils.nextInt(400, 410); Order order = getContainer().newEntityInstance(Order.class); order.setOrderID(orderId); final OrderCollection orders = getContainer().newEntityCollection(OrderCollection.class); orders.add(order); customer.setOrders(orders); order.setCustomerForOrder(customer); getContainer().getCustomers().add(customer); getContainer().flush(); assertEquals(977, order.getCustomerForOrder().load().getPersonID(), 0); // order.getCustomerForOrder().load() caches Customer ... test server doesn't support something like the following // <service>/Orders(400)/CustomerForOrder/Orders // detach all and check for stored data .. getService().getContext().detachAll(); // 3. check everything after flush order = getContainer().getOrders().getByKey(orderId).load(); assertEquals(orderId, order.getOrderID(), 0); customer = getContainer().getCustomers().getByKey(977); // assertEquals(1, customer.getOrders().size()); int count = 0; for (Order inside : customer.getOrders().execute()) { if (inside.getOrderID() == orderId) { count++; } } assertEquals(1, count); assertEquals(977, order.getCustomerForOrder().load().getPersonID(), 0); // 4. delete customer and order getContainer().getCustomers().delete(977); getContainer().getOrders().delete(orderId); getContainer().flush(); }