List of usage examples for java.util Calendar DAY_OF_YEAR
int DAY_OF_YEAR
To view the source code for java.util Calendar DAY_OF_YEAR.
Click Source Link
get
and set
indicating the day number within the current year. From source file:com.panet.imeta.core.row.ValueDataUtil.java
public static Object dayOfYear(ValueMetaInterface metaA, Object dataA) throws KettleValueException { if (dataA == null) return null; if (metaA.isDate()) { Calendar calendar = Calendar.getInstance(); calendar.setTime(metaA.getDate(dataA)); return new Long(calendar.get(Calendar.DAY_OF_YEAR)); }//from w ww. j a va 2s . c om throw new KettleValueException("The 'dayOfYear' function only works with dates"); }
From source file:de.blizzy.backup.backup.BackupRun.java
private List<Date> getBackupRunsDays(int skipDays) { Cursor<Record> cursor = null; try {/*from www.j av a 2s.com*/ // get all days where there are backups (and which are older than skipDays days) Calendar c = Calendar.getInstance(); c.add(Calendar.DAY_OF_YEAR, -skipDays); c.set(Calendar.HOUR_OF_DAY, 0); c.set(Calendar.MINUTE, 0); c.set(Calendar.SECOND, 0); c.set(Calendar.MILLISECOND, 0); cursor = database.factory().select(Tables.BACKUPS.RUN_TIME).from(Tables.BACKUPS) .where(Tables.BACKUPS.RUN_TIME.lessThan(new Timestamp(c.getTimeInMillis()))) .orderBy(Tables.BACKUPS.RUN_TIME).fetchLazy(); List<Date> days = new ArrayList<>(); while (cursor.hasNext()) { Record record = cursor.fetchOne(); c.setTimeInMillis(record.getValue(Tables.BACKUPS.RUN_TIME).getTime()); c.set(Calendar.HOUR_OF_DAY, 0); c.set(Calendar.MINUTE, 0); c.set(Calendar.SECOND, 0); c.set(Calendar.MILLISECOND, 0); days.add(new Date(c.getTimeInMillis())); } return days; } finally { database.closeQuietly(cursor); } }
From source file:com.aurel.track.move.ItemMoveBL.java
public static Integer getNumberOfSaturdaysFromInterval(Date startDateParam, Date endDateParam) { Calendar calendar = Calendar.getInstance(); calendar.setTime(startDateParam);//from w w w .j av a2 s .c o m int numOfSaturdays = 0; while (DateTimeUtils.lessOrEqual(calendar.getTime(), endDateParam)) { if (calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY) { numOfSaturdays++; } calendar.add(Calendar.DAY_OF_YEAR, 1); } return numOfSaturdays; }
From source file:com.alkacon.opencms.v8.commons.CmsTemplateModules.java
/** * Checks if two dates in the page context attributes have the same date and differ only from their time.<p> * //from w w w . j av a 2 s . c o m * @param startDateAttrib the name of the page context attribute containing the start date string * @param endDateAttrib the name of the page context attribute containing the end date string * @return true if the two dates differ only in time, otherwise false */ public boolean isSameDate(String startDateAttrib, String endDateAttrib) { String timeString = (String) getJspContext().getAttribute(startDateAttrib); long timestamp = (new Long(timeString)).longValue(); Calendar calStart = new GregorianCalendar(); calStart.setTimeInMillis(timestamp); timeString = (String) getJspContext().getAttribute(endDateAttrib); timestamp = (new Long(timeString)).longValue(); Calendar calEnd = new GregorianCalendar(); calEnd.setTimeInMillis(timestamp); return ((calStart.get(Calendar.DAY_OF_YEAR) == calEnd.get(Calendar.DAY_OF_YEAR)) && (calStart.get(Calendar.YEAR) == calEnd.get(Calendar.YEAR))); }
From source file:ezbake.data.elastic.ElasticClientTest.java
@Test public void testRangeDateFacets() throws Exception { final SimpleDateFormat dtg = new SimpleDateFormat(EzElasticTestUtils.DATE_FORMAT); Calendar calendar = new GregorianCalendar(); calendar.add(Calendar.DAY_OF_YEAR, -1); long last24Time = DateUtils.round(calendar, Calendar.HOUR).getTimeInMillis(); calendar.add(Calendar.DAY_OF_YEAR, -1); long last48Time = DateUtils.round(calendar, Calendar.HOUR).getTimeInMillis(); calendar.add(Calendar.DAY_OF_YEAR, -1); long last72Time = DateUtils.round(calendar, Calendar.HOUR).getTimeInMillis(); List<Facet> rangeDateFacets = Collections .singletonList(EzElasticTestUtils.generateDateBucketFacet(last24Time, last48Time, last72Time)); final SearchResult results = client.get(QueryBuilders.matchAllQuery().toString(), TEST_TYPE, null, null, rangeDateFacets, null, 0, (short) 10, null, COMMON_USER_TOKEN); assertEquals(4, results.getTotalHits()); assertFalse(results.getFacets().isEmpty()); assertTrue(results.getFacets().containsKey("Report Date")); final FacetResult facetResult = results.getFacets().get("Report Date"); for (final RangeFacetEntry entry : facetResult.getRangeFacetResult().getEntries()) { if (dtg.parse(entry.getRangeFrom()).getTime() >= last24Time || dtg.parse(entry.getRangeFrom()).getTime() >= last48Time || dtg.parse(entry.getRangeFrom()).getTime() >= last72Time) { assertEquals(3, entry.getCount()); } else {//from ww w.java 2s . c om assertEquals(4, entry.getCount()); } } }
From source file:com.dearho.cs.subscriber.service.impl.SubscriberServiceImpl.java
@Override public Page querySubscriberLastSevenDayMember(Page page, Subscriber subscriber) { StringBuffer hql = new StringBuffer(); hql.append(" from Subscriber a where 1=1"); Calendar cal = Calendar.getInstance(); cal.setTime(new Date()); cal.add(Calendar.DAY_OF_YEAR, -7); hql.append(" and a.createDate > '").append(DateUtil.getChar19DateString(cal.getTime())).append("'"); hql.append(" and a.createDate < '").append(DateUtil.getChar19DateString(new Date())).append("'"); hql.append(StringHelper.isEmpty(page.getOrderByString()) ? "order by createDate desc" : page.getOrderByString());//from www . j a va 2 s . c om page = subscriberDao.querySubscriberByPage(page, hql.toString()); return page; }
From source file:de.schildbach.pte.AbstractHafasMobileProvider.java
private final Date parseJsonTime(final Calendar calendar, final Date baseDate, final CharSequence str) { if (str == null) return null; final Matcher m = P_JSON_TIME.matcher(str); if (m.matches()) { calendar.setTime(baseDate);/*from w w w . java2 s .com*/ if (m.group(1) != null) calendar.add(Calendar.DAY_OF_YEAR, Integer.parseInt(m.group(1))); calendar.set(Calendar.HOUR_OF_DAY, Integer.parseInt(m.group(2))); calendar.set(Calendar.MINUTE, Integer.parseInt(m.group(3))); calendar.set(Calendar.SECOND, Integer.parseInt(m.group(4))); return calendar.getTime(); } throw new RuntimeException("cannot parse: '" + str + "'"); }
From source file:org.openmrs.module.orderextension.web.controller.OrderExtensionOrderController.java
private Date adjustDate(Date dateToAdjust, Date startDateComparison, Date endDateComparison) { long milis2 = startDateComparison.getTime(); long milis1 = endDateComparison.getTime(); long diff = milis1 - milis2; long diffDays = diff / (24 * 60 * 60 * 1000); Calendar adjusted = Calendar.getInstance(); adjusted.setTime(dateToAdjust);/*from ww w .jav a2 s.c om*/ adjusted.add(Calendar.DAY_OF_YEAR, (int) diffDays); return adjusted.getTime(); }
From source file:com.adaptris.core.services.jdbc.FirstRowMetadataTranslatorTest.java
private java.util.Date yesterday() { Calendar cal = Calendar.getInstance(); cal.add(Calendar.DAY_OF_YEAR, -1); return cal.getTime(); }
From source file:org.openmrs.module.orderextension.web.controller.OrderExtensionOrderController.java
public Date getCycleDate(Date cycleStart, Integer day) { Calendar cycleDate = Calendar.getInstance(); cycleDate.setTime(cycleStart);/*from w w w . ja va2 s. c o m*/ cycleDate.add(Calendar.DAY_OF_YEAR, day - 1); return cycleDate.getTime(); }