List of usage examples for java.util Calendar DAY_OF_MONTH
int DAY_OF_MONTH
To view the source code for java.util Calendar DAY_OF_MONTH.
Click Source Link
get
and set
indicating the day of the month. From source file:net.ceos.project.poi.annotated.bean.ObjectConfigurableBuilder.java
/** * Validate the ObjectConfigurable based on the object build with the method * 'buildObjectConfigurable'// w w w . j a v a 2 s. c om * * @param toValidate * the object to validate */ public static void validateObjectConfigurable(ObjectConfigurable toValidate) { ObjectConfigurable base = buildObjectConfigurable(); assertEquals(base.getBooleanAttribute(), toValidate.getBooleanAttribute()); Calendar calendar = Calendar.getInstance(); calendar.setTime(new Date()); Calendar calendarUnmarshal = Calendar.getInstance(); calendarUnmarshal.setTime(toValidate.getDateAttribute()); assertEquals(calendar.get(Calendar.YEAR), calendarUnmarshal.get(Calendar.YEAR)); assertEquals(calendar.get(Calendar.MONTH), calendarUnmarshal.get(Calendar.MONTH)); assertEquals(calendar.get(Calendar.DAY_OF_MONTH), calendarUnmarshal.get(Calendar.DAY_OF_MONTH)); assertEquals(base.getDoubleAttribute(), toValidate.getDoubleAttribute()); assertEquals(base.getIntegerAttribute(), toValidate.getIntegerAttribute()); assertEquals(base.getLongAttribute(), toValidate.getLongAttribute()); assertEquals(base.getStringAttribute(), toValidate.getStringAttribute()); Calendar calendar1 = Calendar.getInstance(); calendar1.setTime(new Date()); Calendar calendarUnmarshal1 = Calendar.getInstance(); calendarUnmarshal1.setTime(toValidate.getDateAttribute1()); assertEquals(calendar1.get(Calendar.YEAR), calendarUnmarshal1.get(Calendar.YEAR)); assertEquals(calendar1.get(Calendar.MONTH), calendarUnmarshal1.get(Calendar.MONTH)); assertEquals(calendar1.get(Calendar.DAY_OF_MONTH), calendarUnmarshal1.get(Calendar.DAY_OF_MONTH)); assertEquals(base.getJob().getJobCode(), toValidate.getJob().getJobCode()); assertEquals(base.getJob().getJobFamily(), toValidate.getJob().getJobFamily()); assertEquals(base.getJob().getJobName(), toValidate.getJob().getJobName()); // TODO add new validation below }
From source file:com.adobe.acs.commons.http.headers.impl.MonthlyExpiresHeaderFilterTest.java
@Test public void testAdjustExpiresPastDay() throws Exception { Calendar actual = Calendar.getInstance(); actual.set(Calendar.SECOND, 0); actual.set(Calendar.MILLISECOND, 0); Calendar expected = Calendar.getInstance(); expected.setTime(actual.getTime());/*from ww w .j a va 2s. c om*/ expected.add(Calendar.DAY_OF_MONTH, -3); expected.add(Calendar.MONTH, 1); actual.set(Calendar.DAY_OF_MONTH, 15); final int month = expected.get(Calendar.MONTH); properties.put(MonthlyExpiresHeaderFilter.PROP_EXPIRES_DAY_OF_MONTH, expected.get(Calendar.DAY_OF_MONTH)); filter.doActivate(componentContext); filter.adjustExpires(actual); assertTrue(DateUtils.isSameInstant(expected, actual)); assertEquals(month, actual.get(Calendar.MONTH)); }
From source file:com.clican.pluto.dataprocess.dpl.integrated.SubSelectTestCase.java
private List<BeanPrice> getList() { List<Date> dates = new ArrayList<Date>(); Calendar cal = Calendar.getInstance(); cal = DateUtils.truncate(cal, Calendar.DAY_OF_MONTH); for (int i = 0; i < 10; i++) { dates.add(0, new Date(cal.getTime().getTime())); cal.add(Calendar.DAY_OF_MONTH, -1); }/*from www .j a va2s . co m*/ List<BeanPrice> list = new ArrayList<BeanPrice>(); for (int i = 0; i < 10; i++) { BeanPrice price = new BeanPrice(); price.setId(i); price.setDate(dates.get(i)); list.add(price); } return list; }
From source file:com.feilong.core.date.DateUtilTest.java
/** * Test get first date of this day./*from ww w . j a va 2s.co m*/ */ @Test public void testGetFirstDateOfThisDay() { logDate(DateUtil.getFirstDateOfThisDay(NOW)); logDate(DateUtils.truncate(NOW, Calendar.DAY_OF_MONTH)); }
From source file:net.kamhon.ieagle.util.DateUtil.java
/** * erase all time. set all time fields to 0. * /*from w w w . j a v a 2s. c o m*/ * @param date * @return */ public static Date truncateTime(Date date) { return DateUtils.truncate(date, Calendar.DAY_OF_MONTH); }
From source file:net.orpiske.dcd.collector.dataset.impl.MBoxDataSetTest.java
@Test public void testTwoDigitDateWithTZ() { Data data = dataList.get(1);//from w w w. j a va 2 s .c o m Date date = data.getDate(); Calendar cal = Calendar.getInstance(); cal.setTime(date); assertEquals("The year is incorrect", 2013, cal.get(Calendar.YEAR)); assertEquals("The month is incorrect", Calendar.MAY, cal.get(Calendar.MONTH)); assertEquals("The day is incorrect", 20, cal.get(Calendar.DAY_OF_MONTH)); }
From source file:org.wikipedia.nirvana.statistics.ArchiveItem.java
public ArchiveItem(String article, String user, Calendar c) { this.article = article; this.user = user; this.year = c.get(Calendar.YEAR); this.month = c.get(Calendar.MONTH); this.day = c.get(Calendar.DAY_OF_MONTH); }
From source file:Main.java
/** * Parse a date from ISO-8601 formatted string. It expects a format * yyyy-MM-ddThh:mm:ss[.sss][Z|[+-]hh:mm] * * @param date ISO string to parse in the appropriate format. * @return the parsed date//www .j av a2 s . c o m * @throws IllegalArgumentException if the date is not in the appropriate format */ public static Date parse(String date) { try { int offset = 0; // extract year int year = parseInt(date, offset, offset += 4); checkOffset(date, offset, '-'); // extract month int month = parseInt(date, offset += 1, offset += 2); checkOffset(date, offset, '-'); // extract day int day = parseInt(date, offset += 1, offset += 2); checkOffset(date, offset, 'T'); // extract hours, minutes, seconds and milliseconds int hour = parseInt(date, offset += 1, offset += 2); checkOffset(date, offset, ':'); int minutes = parseInt(date, offset += 1, offset += 2); checkOffset(date, offset, ':'); int seconds = parseInt(date, offset += 1, offset += 2); // milliseconds can be optional in the format // always use 0 otherwise returned date will include millis of current time int milliseconds = 0; if (date.charAt(offset) == '.') { checkOffset(date, offset, '.'); int digitCount = 1; while (offset + digitCount < date.length() && digitCount < 3 && date.charAt(offset + 1 + digitCount) != 'Z' && date.charAt(offset + 1 + digitCount) != '+' && date.charAt(offset + 1 + digitCount) != '-') { digitCount++; } String msString = date.substring(offset += 1, offset += digitCount); while (msString.length() < 3) { msString += '0'; } milliseconds = parseInt(msString, 0, 3); } // extract timezone String timezoneId = null; while (offset < date.length()) { char timezoneIndicator = date.charAt(offset); if (timezoneIndicator == '+' || timezoneIndicator == '-') { timezoneId = GMT_ID + date.substring(offset); break; } else if (timezoneIndicator == 'Z') { timezoneId = GMT_ID; break; } offset++; } if (timezoneId == null) { throw new IndexOutOfBoundsException("Invalid time zone indicator "); } TimeZone timezone = TimeZone.getTimeZone(timezoneId); if (!timezone.getID().equals(timezoneId)) { throw new IndexOutOfBoundsException(); } Calendar calendar = new GregorianCalendar(timezone); calendar.setLenient(false); calendar.set(Calendar.YEAR, year); calendar.set(Calendar.MONTH, month - 1); calendar.set(Calendar.DAY_OF_MONTH, day); calendar.set(Calendar.HOUR_OF_DAY, hour); calendar.set(Calendar.MINUTE, minutes); calendar.set(Calendar.SECOND, seconds); calendar.set(Calendar.MILLISECOND, milliseconds); return calendar.getTime(); } catch (IndexOutOfBoundsException | IllegalArgumentException e) { throw new IllegalArgumentException("Failed to parse date " + date, e); } }
From source file:fr.xebia.demo.objectgrid.ticketing.test.AbstractTicketingGridTest.java
protected void loadData(EntityManager entityManager) { Random random = new Random(); Date today = DateUtils.truncate(new Date(), Calendar.DAY_OF_MONTH); // PARIS-MARSEILLE for (int hour = 6; hour <= 24; hour++) { Train train = new Train(random.nextInt(), "PARIS-MARSEILLE-" + hour, Type.HIGH_SPEED); train.getTrainStops()// ww w . ja v a 2s .co m .add(new TrainStop(random.nextInt(), DateUtils.addHours(today, hour), PARIS_GARE_DE_LYON)); train.getTrainStops() .add(new TrainStop(random.nextInt(), DateUtils.addHours(today, 2 + hour), AVIGNON_TGV)); train.getTrainStops().add( new TrainStop(random.nextInt(), DateUtils.addHours(today, 3 + hour), MARSEILLE_SAINT_CHARLES)); for (int seatNumber = 1; seatNumber <= 10; seatNumber++) { train.getSeats().add( new Seat(random.nextInt(), seatNumber, random.nextBoolean(), 100 + random.nextInt(100))); } logger.info("persist " + train); entityManager.getTransaction().begin(); entityManager.persist(train); entityManager.getTransaction().commit(); persistedTrainIds.add(train.getId()); } // MARSEILLE-PARIS for (int hour = 6; hour <= 24; hour++) { Train train = new Train(random.nextInt(), "MARSEILLE-PARIS-" + hour, Type.HIGH_SPEED); train.getTrainStops() .add(new TrainStop(random.nextInt(), DateUtils.addHours(today, hour), MARSEILLE_SAINT_CHARLES)); train.getTrainStops() .add(new TrainStop(random.nextInt(), DateUtils.addHours(today, 1 + hour), AVIGNON_TGV)); train.getTrainStops() .add(new TrainStop(random.nextInt(), DateUtils.addHours(today, 3 + hour), PARIS_GARE_DE_LYON)); for (int seatNumber = 1; seatNumber <= 10; seatNumber++) { train.getSeats().add( new Seat(random.nextInt(), seatNumber, random.nextBoolean(), 200 + random.nextInt(100))); } logger.info("persist " + train); entityManager.getTransaction().begin(); entityManager.persist(train); entityManager.getTransaction().commit(); persistedTrainIds.add(train.getId()); } }
From source file:com.haulmont.cuba.core.sys.querymacro.DateAfterMacroHandler.java
@Override public Map<String, Object> getParams() { Map<String, Object> params = new HashMap<>(); for (Pair<String, TimeZone> pair : paramNames) { String paramName = pair.getFirst(); TimeZone timeZone = pair.getSecond() == null ? TimeZone.getDefault() : pair.getSecond(); Date date = (Date) namedParameters.get(paramName); if (date == null) throw new RuntimeException("Parameter " + paramName + " not found for macro"); Calendar calendar = Calendar.getInstance(timeZone); calendar.setTime(date);//from ww w . j a va2 s .c o m calendar = DateUtils.truncate(calendar, Calendar.DAY_OF_MONTH); params.put(paramName, calendar.getTime()); } return params; }