List of usage examples for org.apache.commons.lang3.time DateUtils truncate
public static Date truncate(final Object date, final int field)
Truncates a date, leaving the field specified as the most significant field.
For example, if you had the date-time of 28 Mar 2002 13:45:01.231, if you passed with HOUR, it would return 28 Mar 2002 13:00:00.000.
From source file:ru.mystamps.web.service.CronServiceImpl.java
@Override @Scheduled(cron = EVERY_DAY_AT_00_00)/*from ww w. j a va 2s . c om*/ @Transactional(readOnly = true) public void sendDailyStatistics() { Date today = DateUtils.truncate(new Date(), Calendar.DAY_OF_MONTH); Date yesterday = DateUtils.addDays(today, -1); AdminDailyReport report = new AdminDailyReport(); report.setStartDate(yesterday); report.setEndDate(today); report.setAddedCategoriesCounter(categoryService.countAddedSince(yesterday)); report.setAddedCountriesCounter(countryService.countAddedSince(yesterday)); long untranslatedCategories = categoryService.countUntranslatedNamesSince(yesterday); report.setUntranslatedCategoriesCounter(untranslatedCategories); long untranslatedCountries = countryService.countUntranslatedNamesSince(yesterday); report.setUntranslatedCountriesCounter(untranslatedCountries); report.setAddedSeriesCounter(seriesService.countAddedSince(yesterday)); report.setUpdatedSeriesCounter(seriesService.countUpdatedSince(yesterday)); report.setUpdatedCollectionsCounter(collectionService.countUpdatedSince(yesterday)); report.setRegistrationRequestsCounter(usersActivationService.countCreatedSince(yesterday)); report.setRegisteredUsersCounter(userService.countRegisteredSince(yesterday)); long notFoundCounter = suspiciousActivityService.countByTypeSince(SiteServiceImpl.PAGE_NOT_FOUND, yesterday); report.setNotFoundCounter(notFoundCounter); long failedAuthCounter = suspiciousActivityService.countByTypeSince(SiteServiceImpl.AUTHENTICATION_FAILED, yesterday); report.setFailedAuthCounter(failedAuthCounter); long missingCsrfCounter = suspiciousActivityService.countByTypeSince(SiteServiceImpl.MISSING_CSRF_TOKEN, yesterday); report.setMissingCsrfCounter(missingCsrfCounter); long invalidCsrfCounter = suspiciousActivityService.countByTypeSince(SiteServiceImpl.INVALID_CSRF_TOKEN, yesterday); report.setInvalidCsrfCounter(invalidCsrfCounter); mailService.sendDailyStatisticsToAdmin(report); }
From source file:siddur.solidtrust.bi.data.DataPump.java
public void pump(String tablename) { webSources = em.createQuery("from WebSource", WebSource.class).getResultList(); List<CurrencyRate> rates = em.createQuery("from CurrencyRate", CurrencyRate.class).getResultList(); for (CurrencyRate r : rates) { currencyRates.put(r.getCurrency(), r.getRate()); }/* ww w .ja v a 2 s . c o m*/ Date d = new Date(); d = DateUtils.addDays(DateUtils.truncate(d, Calendar.DATE), -1); yesterday = sdf.format(d); for (WebSource webSource : webSources) { if (tablename == null || tablename.equalsIgnoreCase(webSource.getTablename())) { log4j.info("Start to synchronize " + webSource.getTablename()); int total = pumpEach(webSource); log4j.info("Synchronized " + total + " records"); } } }
From source file:siddur.solidtrust.scrape.ScrapeMonitor.java
public void alert() { Date start = DateUtils.truncate(new Date(), Calendar.DATE); //NewMarktplaats String ql = "from ScrapeLog where endAt > :start"; List<ScrapeLog> logs = em.createQuery(ql, ScrapeLog.class).setParameter("start", start).getResultList(); int marktplaats = 0, autoscout = 0; for (ScrapeLog log : logs) { String table = log.getTablename(); if (table.equals("NewMarktplaats")) { marktplaats = log.getAmount(); } else if (table.equals("AutoscoutNl")) { autoscout = log.getAmount(); }/* w w w .j ava 2s . c o m*/ } boolean alert1 = marktplaats < DAILY_MARKTPLAATS; boolean alert2 = autoscout < DAILY_AUTOSCOUT_NL; send(alert1, alert2, marktplaats, autoscout); }
From source file:siddur.solidtrust.wok.WokController.java
private void generateFile(int year, int month, File file) { log4j.info("Not found file: " + file.getAbsolutePath() + ", to generate it"); Calendar cal = Calendar.getInstance(); cal.set(Calendar.YEAR, year); cal.set(Calendar.MONTH, month - 1); cal.set(Calendar.DAY_OF_MONTH, 1); Date from = DateUtils.truncate(cal.getTime(), Calendar.MONTH); Date to = DateUtils.ceiling(from, Calendar.MONTH); String ql = "select new siddur.solidtrust.wok.WokModel(w.licensePlate, m.brand, m.type, w.addedAt, w.removedAt) from Wachtopkeuren w, AzureCar m where w.licensePlate = m.licensePlate and w.addedAt between :from and :to"; List<WokModel> results = em.createQuery(ql, WokModel.class).setParameter("from", from) .setParameter("to", to).getResultList(); Workbook wb = new XSSFWorkbook(); Sheet sheet1 = wb.createSheet("sheet1"); Row row = sheet1.createRow(0);/*from w w w . j a v a2 s.c om*/ int i = 0; row.createCell(i++).setCellValue("License Plate"); row.createCell(i++).setCellValue("Brand Model"); row.createCell(i++).setCellValue("WOK STATUS BEGIN"); row.createCell(i++).setCellValue("WOK STATUS END"); for (int j = 0; j < results.size(); j++) { row = sheet1.createRow(j + 1); WokModel w = results.get(j); i = 0; row.createCell(i++).setCellValue(w.getLicensePlate()); row.createCell(i++).setCellValue(w.getBrand() + " " + w.getModel()); row.createCell(i++).setCellValue(DateUtil.date2String(w.getAddedAt())); if (w.getRemovedAt() != null) { row.createCell(i++).setCellValue(DateUtil.date2String(w.getRemovedAt())); } } OutputStream os = null; try { os = new FileOutputStream(file); wb.write(os); } catch (IOException e) { log4j.error(e.getMessage(), e); } finally { IOUtils.closeQuietly(os); } }
From source file:ubic.gemma.core.analysis.preprocess.batcheffects.BatchInfoPopulationHelperServiceImpl.java
private String formatBatchName(int batchNum, DateFormat df, Date d) { String batchDateString;//w w w .j a v a 2 s . c o m batchDateString = ExperimentalDesignUtils.BATCH_FACTOR_NAME_PREFIX + StringUtils.leftPad(Integer.toString(batchNum), 2, "0") + "_" + df.format(DateUtils.truncate(d, Calendar.HOUR)); return batchDateString; }
From source file:uk.gov.hscic.common.util.DateFormatter.java
public static Date toDateOnly(final String input) { final Date date = toDate(input); if (date != null) { return DateUtils.truncate(date, Calendar.DAY_OF_MONTH); }// w w w .j a va 2s.c o m return null; }
From source file:uk.gov.hscic.patient.details.search.LegacyPatientSearch.java
private BooleanBuilder generateAdvancedSearchPredicate(final PatientQueryParams params) { final QPatientEntity blueprint = QPatientEntity.patientEntity; final BooleanBuilder predicate = new BooleanBuilder(); final String nhsNumber = params.getNhsNumber(); if (nhsNumber != null) { predicate.and(blueprint.nhsNumber.eq(nhsNumber)); } else {// w w w.j a va2 s. com final String surname = StringUtils.stripToNull(params.getSurname()); final String forename = StringUtils.stripToNull(params.getForename()); final Date dateOfBirth = params.getDateOfBirth(); final String gender = StringUtils.stripToNull(params.getGender()); if (surname != null) { predicate.and(blueprint.lastName.like(surname)); } if (forename != null) { predicate.and(blueprint.firstName.like(forename)); } if (dateOfBirth != null) { final Date truncatedDateOfBirth = DateUtils.truncate(dateOfBirth, Calendar.DATE); predicate.and(blueprint.dateOfBirth.eq(truncatedDateOfBirth)); } if (gender != null) { predicate.and(blueprint.gender.eq(gender)); } } return predicate; }