List of usage examples for java.util Calendar clear
public final void clear()
Calendar
undefined. From source file:org.apache.olingo.fit.proxy.APIBasicDesignTestITCase.java
/** * Java client should support the deletion based on locally created entity. * See also <a href="https://issues.apache.org/jira/browse/OLINGO-395">Olingo Issue 395</a>. *///from ww w . j a va2 s .c o m @Test public void issueOLINGO395() { Order order = getContainer().newEntityInstance(Order.class); order.setOrderID(1105); final Calendar orderDate = Calendar.getInstance(TimeZone.getTimeZone("GMT")); orderDate.clear(); orderDate.set(2011, 3, 4, 16, 3, 57); order.setOrderDate(new Timestamp(orderDate.getTimeInMillis())); order.setShelfLife(BigDecimal.ZERO); final PrimitiveCollection<BigDecimal> osl = getContainer().newPrimitiveCollection(BigDecimal.class); osl.add(BigDecimal.TEN.negate()); osl.add(BigDecimal.TEN); order.setOrderShelfLifes(osl); getContainer().getOrders().add(order); getContainer().getOrders().delete(order); getContainer().flush(); service.getContext().detachAll(); try { getContainer().getOrders().getByKey(1105).load(); fail(); } catch (IllegalArgumentException e) { // Expected Exception } service.getContext().detachAll(); // avoid influences order = getContainer().newEntityInstance(Order.class); order.setOrderID(1105); getContainer().getOrders().delete(order); getContainer().flush(); // test service doesn't fail for delete requests about unexisting objects service.getContext().detachAll(); try { getContainer().getOrders().getByKey(1105).load(); fail(); } catch (IllegalArgumentException e) { // Expected Exception } service.getContext().detachAll(); // avoid influences }
From source file:org.apache.olingo.fit.proxy.v4.APIBasicDesignTestITCase.java
@Test public void createDelete() { // Create order .... final Order order = getContainer().newEntityInstance(Order.class); order.setOrderID(1105);//from w ww .j ava 2s . co m final Calendar orderDate = Calendar.getInstance(TimeZone.getTimeZone("GMT")); orderDate.clear(); orderDate.set(2011, 3, 4, 16, 3, 57); order.setOrderDate(new Timestamp(orderDate.getTimeInMillis())); order.setShelfLife(BigDecimal.ZERO); final PrimitiveCollection<BigDecimal> osl = getContainer().newPrimitiveCollection(BigDecimal.class); osl.add(BigDecimal.TEN.negate()); osl.add(BigDecimal.TEN); order.setOrderShelfLifes(osl); getContainer().getOrders().add(order); getContainer().flush(); Order actual = getContainer().getOrders().getByKey(1105); assertNull(actual.getOrderID()); actual.load(); assertEquals(1105, actual.getOrderID(), 0); assertEquals(orderDate.getTimeInMillis(), actual.getOrderDate().getTime()); assertEquals(BigDecimal.ZERO, actual.getShelfLife()); assertEquals(2, actual.getOrderShelfLifes().size()); service.getContext().detachAll(); // (1) Delete by key (see EntityCreateTestITCase) getContainer().getOrders().delete(1105); assertNull(getContainer().getOrders().getByKey(1105)); service.getContext().detachAll(); // detach to show the second delete case // (2) Delete by object (see EntityCreateTestITCase) getContainer().getOrders().delete(getContainer().getOrders().getByKey(1105)); assertNull(getContainer().getOrders().getByKey(1105)); // (3) Delete by invoking delete method on the object itself service.getContext().detachAll(); // detach to show the third delete case getContainer().getOrders().getByKey(1105).delete(); assertNull(getContainer().getOrders().getByKey(1105)); getContainer().flush(); service.getContext().detachAll(); try { getContainer().getOrders().getByKey(1105).load(); fail(); } catch (IllegalArgumentException e) { } service.getContext().detachAll(); // avoid influences }
From source file:com.clustercontrol.calendar.factory.SelectCalendar.java
/** * ??????//from w w w . j ava 2s. c om * @param info * @param year * @param month * @return */ public ArrayList<Integer> getCalendarMonth(CalendarInfo info, Integer year, Integer month) { ArrayList<Integer> ret = new ArrayList<Integer>(); ArrayList<CalendarDetailInfo> list24 = new ArrayList<CalendarDetailInfo>(); for (CalendarDetailInfo d : info.getCalendarDetailList()) { list24.addAll(CalendarUtil.getDetail24(d)); } long validFrom = info.getValidTimeFrom(); long validTo = info.getValidTimeTo(); Calendar cal = HinemosTime.getCalendarInstance(); cal.set(year, month - 1, 1); int lastDate = cal.getActualMaximum(Calendar.DATE) + 1; m_log.debug("maxDate=" + year + "/" + month + "/" + lastDate); for (int i = 1; i < lastDate; i++) { Calendar startCalendar = HinemosTime.getCalendarInstance(); startCalendar.clear(); startCalendar.set(year, month - 1, i, 0, 0, 0); long dayStartTime = startCalendar.getTimeInMillis(); Calendar endCalendar = HinemosTime.getCalendarInstance(); endCalendar.clear(); endCalendar.set(year, month - 1, i + 1, 0, 0, 0); long dayEndTime = endCalendar.getTimeInMillis(); m_log.debug("i=" + i + " ==== start=" + new Date(dayStartTime) + ",end=" + new Date(dayEndTime)); // 1???????? // ???true?????????? boolean isContainInvalidPeriod = false; // ???????? long dayValidStart; if (dayStartTime < validFrom) { dayValidStart = validFrom; isContainInvalidPeriod = true; } else { dayValidStart = dayStartTime; } long dayValidEnd; if (validTo < dayEndTime) { dayValidEnd = validTo; isContainInvalidPeriod = true; } else { dayValidEnd = dayEndTime; } // ???????????? dayValidEnd--; // ????????????????? if (dayValidStart > dayValidEnd) { ret.add(2); continue; } /** * ?????? * ?????????????? * ?CalendarDetailInfo?From?To??????? */ Set<Long> borderTimeSet = new HashSet<Long>(); borderTimeSet.add(dayValidStart); borderTimeSet.add(dayValidEnd); // detail for (CalendarDetailInfo detail : list24) { long detailStart = dayStartTime + detail.getTimeFrom() + TIMEZONE; if (dayValidStart < detailStart && detailStart < dayValidEnd) { borderTimeSet.add(detailStart); } long detailEnd = dayStartTime + detail.getTimeTo() + TIMEZONE; if (dayValidStart < detailEnd && detailEnd < dayValidEnd) { borderTimeSet.add(detailEnd); } } /** * ????? * [0]???????OK * [2]???????NG * [1]?OK??NG * ?? */ boolean isAllNG = true; // OK????false?? boolean isAllOK = true; // NG????false?? for (Long borderTime : borderTimeSet) { // ???????? // ????????? m_log.debug("date:" + new Date(borderTime)); boolean retRun = CalendarUtil.isRun(info, new Date(borderTime)); if (retRun) { isAllNG = false; } else { isAllOK = false; } // OKNG??????????????????? if (isAllNG == false && isAllOK == false) { break; } } if (isAllNG == true) { // NG ret.add(2); } else { if (isAllOK == true) { if (isContainInvalidPeriod) { // OKNG ??OK???????????? ret.add(1); } else { // ?OK ret.add(0); } } else { // OKNG ret.add(1); } } } return ret; }
From source file:org.apache.olingo.fit.proxy.APIBasicDesignTestITCase.java
@Test public void createDelete() { // Create order .... final Order order = getContainer().newEntityInstance(Order.class); order.setOrderID(1105);/*from w w w. j a v a 2 s.c om*/ final Calendar orderDate = Calendar.getInstance(TimeZone.getTimeZone("GMT")); orderDate.clear(); orderDate.set(2011, 3, 4, 16, 3, 57); order.setOrderDate(new Timestamp(orderDate.getTimeInMillis())); order.setShelfLife(BigDecimal.ZERO); final PrimitiveCollection<BigDecimal> osl = getContainer().newPrimitiveCollection(BigDecimal.class); osl.add(BigDecimal.TEN.negate()); osl.add(BigDecimal.TEN); order.setOrderShelfLifes(osl); getContainer().getOrders().add(order); getContainer().flush(); Order actual = getContainer().getOrders().getByKey(1105); assertNull(actual.getOrderID()); actual.load(); assertEquals(1105, actual.getOrderID(), 0); assertEquals(orderDate.getTimeInMillis(), actual.getOrderDate().getTime()); assertEquals(BigDecimal.ZERO, actual.getShelfLife()); assertEquals(2, actual.getOrderShelfLifes().size()); service.getContext().detachAll(); // (1) Delete by key (see EntityCreateTestITCase) getContainer().getOrders().delete(1105); assertNull(getContainer().getOrders().getByKey(1105)); service.getContext().detachAll(); // detach to show the second delete case // (2) Delete by object (see EntityCreateTestITCase) getContainer().getOrders().delete(getContainer().getOrders().getByKey(1105)); assertNull(getContainer().getOrders().getByKey(1105)); // (3) Delete by invoking delete method on the object itself service.getContext().detachAll(); // detach to show the third delete case getContainer().getOrders().getByKey(1105).delete(); assertNull(getContainer().getOrders().getByKey(1105)); getContainer().flush(); service.getContext().detachAll(); try { getContainer().getOrders().getByKey(1105).load(); fail(); } catch (IllegalArgumentException e) { // Test } service.getContext().detachAll(); // avoid influences }
From source file:org.apache.logging.log4j.core.util.datetime.FastDateParserTest.java
@Test public void testMilleniumBug() throws ParseException { final DateParser parser = getInstance(DMY_DOT); final Calendar cal = Calendar.getInstance(); cal.clear(); cal.set(1000, Calendar.JANUARY, 1); assertEquals(cal.getTime(), parser.parse("01.01.1000")); }
From source file:org.apache.logging.log4j.core.util.datetime.FastDateParserTest.java
@Test public void testParseOffset() { final DateParser parser = getInstance(YMD_SLASH); final Date date = parser.parse("Today is 2015/07/04", new ParsePosition(9)); final Calendar cal = Calendar.getInstance(); cal.clear(); cal.set(2015, Calendar.JULY, 4); Assert.assertEquals(cal.getTime(), date); }
From source file:com.greenline.guahao.web.module.home.controllers.expert.FastOrderProcess.java
/** * ?//from w ww . ja v a 2 s . c om * * @return String */ public String getInitClinicDateScope() { String clinicDateScope = ""; Calendar now = Calendar.getInstance(); Calendar time = Calendar.getInstance(); time.clear(); time.set(Calendar.YEAR, now.get(Calendar.YEAR)); time.set(Calendar.MONTH, now.get(Calendar.MONTH)); time.set(Calendar.DAY_OF_YEAR, now.get(Calendar.DAY_OF_YEAR)); time.add(Calendar.DAY_OF_YEAR, 1); // clinicDateScope += time.getTime().getTime(); clinicDateScope = clinicDateScope + "-"; time.add(Calendar.DAY_OF_YEAR, 15); // clinicDateScope += time.getTime().getTime(); return clinicDateScope; }
From source file:org.apache.logging.log4j.core.util.datetime.FastDateParserTest.java
/** * Test case for {@link FastDateParser#FastDateParser(String, TimeZone, Locale)}. * @throws ParseException so we don't have to catch it *//*from w ww. j a v a 2s.co m*/ @Test public void testShortDateStyleWithLocales() throws ParseException { DateParser fdf = getDateInstance(FastDateFormat.SHORT, Locale.US); final Calendar cal = Calendar.getInstance(); cal.clear(); cal.set(2004, Calendar.FEBRUARY, 3); assertEquals(cal.getTime(), fdf.parse("2/3/04")); fdf = getDateInstance(FastDateFormat.SHORT, SWEDEN); assertEquals(cal.getTime(), fdf.parse("2004-02-03")); }
From source file:org.apache.logging.log4j.core.util.datetime.FastDateParserTest.java
/** * Tests that pre-1000AD years get padded with yyyy * @throws ParseException so we don't have to catch it *///from w w w . j a va 2 s .co m @Test public void testLowYearPadding() throws ParseException { final DateParser parser = getInstance(YMD_SLASH); final Calendar cal = Calendar.getInstance(); cal.clear(); cal.set(1, Calendar.JANUARY, 1); assertEquals(cal.getTime(), parser.parse("0001/01/01")); cal.set(10, Calendar.JANUARY, 1); assertEquals(cal.getTime(), parser.parse("0010/01/01")); cal.set(100, Calendar.JANUARY, 1); assertEquals(cal.getTime(), parser.parse("0100/01/01")); cal.set(999, Calendar.JANUARY, 1); assertEquals(cal.getTime(), parser.parse("0999/01/01")); }
From source file:org.apache.logging.log4j.core.util.datetime.FastDateParserTest.java
@Test public void testJpLocales() { final Calendar cal = Calendar.getInstance(GMT); cal.clear(); cal.set(2003, Calendar.FEBRUARY, 10); cal.set(Calendar.ERA, GregorianCalendar.BC); final Locale locale = LocaleUtils.toLocale("zh"); {/* w w w .j a va 2 s . c o m*/ // ja_JP_JP cannot handle dates before 1868 properly final SimpleDateFormat sdf = new SimpleDateFormat(LONG_FORMAT, locale); final DateParser fdf = getInstance(LONG_FORMAT, locale); try { checkParse(locale, cal, sdf, fdf); } catch (final ParseException ex) { Assert.fail("Locale " + locale + " failed with " + LONG_FORMAT + "\n" + trimMessage(ex.toString())); } } }