List of usage examples for org.joda.time DateMidnight minusDays
public DateMidnight minusDays(int days)
From source file:com.atlassian.theplugin.idea.bamboo.tree.DatePeriod.java
License:Apache License
public static DatePeriod getBuilDate(Date aDate) { DateTime date = new DateTime(aDate); DateMidnight midnight = new DateMidnight(); if (date.isAfter(midnight)) { return TODAY; } else if (date.isAfter(midnight.minusDays(1))) { return YESTERDAY; } else if (date.isAfter(midnight.minusDays(DAYS_IN_WEEK))) { return LAST_WEEK; } else if (date.isAfter(midnight.minusMonths(1))) { return LAST_MONTH; } else {/*from ww w . ja v a2 s. c o m*/ return OLDER; } }
From source file:com.cubeia.backoffice.accounting.core.manager.AccountingManagerImpl.java
License:Open Source License
@Override public List<CurrencyRate> listRatesForCurrency(String currencyCode, Date date, int maxAgeDays) { // calculate dates DateMidnight dateMidnight = new DateTime(date).toDateMidnight(); DateMidnight end = dateMidnight.plusDays(1); DateMidnight start = dateMidnight.minusDays(maxAgeDays); // list rates List<CurrencyRate> rates = accountingDAO.listCurrencyRates(currencyCode, start.toDate(), end.toDate()); // remove duplicates Map<String, CurrencyRate> map = new HashMap<String, CurrencyRate>(); for (CurrencyRate rate : rates) { String key = rate.getSourceCurrencyCode() + ":" + rate.getTargetCurrencyCode(); map.put(key, rate);//from w ww.j av a 2 s . c om } // re-sort results List<CurrencyRate> answer = new ArrayList<CurrencyRate>(map.values()); Collections.sort(rates, new Comparator<CurrencyRate>() { @Override public int compare(CurrencyRate o1, CurrencyRate o2) { int i = o1.getTimestamp().compareTo(o2.getTimestamp()); if (i != 0) { return i; } else { return o1.getId().compareTo(o2.getId()); } } }); return answer; }
From source file:com.cubeia.backoffice.accounting.core.manager.AccountingManagerImpl.java
License:Open Source License
private CurrencyRate getCurrencyRate(String sourceCurrencyCode, String targetCurrencyCode, Date date, int fallbackDays, boolean allowSearch) { DateMidnight dateMidnight = new DateTime(date).toDateMidnight(); DateMidnight end = dateMidnight.plusDays(1); DateMidnight start = dateMidnight.minusDays(fallbackDays); CurrencyRate rate = accountingDAO.getCurrencyRate(sourceCurrencyCode, targetCurrencyCode, start.toDate(), end.toDate());/*from ww w .jav a 2s. c o m*/ if (rate == null) { // try opposite direction rate = accountingDAO.getCurrencyRate(targetCurrencyCode, sourceCurrencyCode, start.toDate(), end.toDate()); if (rate != null) { rate = rate.invert(); } } if (rate == null && allowSearch) { // look for a first level chain List<CurrencyRate> chain = accountingDAO.getCurrencyRateChain(targetCurrencyCode, sourceCurrencyCode, start.toDate(), end.toDate()); if (!chain.isEmpty()) { // chain found, now we must put the rates in order and combine them CurrencyRate r0 = chain.get(0); CurrencyRate r1 = chain.get(1); CurrencyRate firstRate; CurrencyRate secondRate; if (r0.getSourceCurrencyCode().equals(sourceCurrencyCode) || r0.getTargetCurrencyCode().equals(sourceCurrencyCode)) { firstRate = r0; secondRate = r1; } else { firstRate = r1; secondRate = r0; } if (!firstRate.getSourceCurrencyCode().equals(sourceCurrencyCode)) { firstRate = firstRate.invert(); } if (!secondRate.getTargetCurrencyCode().equals(targetCurrencyCode)) { secondRate = secondRate.invert(); } rate = firstRate.combine(secondRate); } } return rate; }
From source file:com.github.dbourdette.otto.web.util.IntervalUtils.java
License:Apache License
public static Interval lastWeek() { DateMidnight monday = new DateMidnight().withDayOfWeek(1); return new Interval(monday.minusDays(7), monday); }
From source file:com.google.android.apps.paco.TimeUtil.java
License:Open Source License
public static DateMidnight getMondayOfWeek(DateTime now) { DateMidnight mondayOfWeek = now.toDateMidnight(); int dow = mondayOfWeek.getDayOfWeek(); if (dow != DateTimeConstants.MONDAY) { mondayOfWeek = mondayOfWeek.minusDays(dow - 1); }//w w w . j a va2 s .c o m return mondayOfWeek; }
From source file:com.google.sampling.experiential.server.MapServiceImpl.java
License:Open Source License
/** * @param dateMidnight/*from www.j av a2 s . c om*/ * @return */ private DateMidnight getBeginningOfWeek(DateMidnight dateMidnight) { int dow = dateMidnight.getDayOfWeek(); int daysToBeginning = dow - DateTimeConstants.MONDAY; if (daysToBeginning != 0) { return dateMidnight.minusDays(daysToBeginning); } return dateMidnight; }
From source file:com.liteoc.logic.expressionTree.ArithmeticOpNode.java
License:LGPL
private String calculateGenericDate(String value1, String value2) { DateMidnight dm = new DateMidnight(ExpressionTreeHelper.getDate(value1).getTime()); DateTimeFormatter fmt = ISODateTimeFormat.date(); switch (op) { case PLUS: {/*www. j av a 2 s. c o m*/ dm = dm.plusDays(Double.valueOf(value2).intValue()); return fmt.print(dm); } case MINUS: { dm = dm.minusDays(Double.valueOf(value2).intValue()); return fmt.print(dm); } default: return null; // Bad operator! } }
From source file:edu.wisc.hr.demo.RandomTimeSheetDao.java
License:Apache License
@Override public List<TimeSheet> getTimeSheets(String emplId) { if (emplIdToListOfTimeSheets.containsKey(emplId)) { return emplIdToListOfTimeSheets.get(emplId); }/* w ww . j a v a 2s. com*/ List<TimeSheet> timesheets = new LinkedList<TimeSheet>(); Job primaryJob = this.contactInfoDao.getPersonalData(emplId).getPrimaryJob(); int howManyTimeSheets = random.nextInt(20); for (int i = 0; i < howManyTimeSheets; i++) { TimeSheet timeSheet = new TimeSheet(); int randomNumberOfDaysAgo = random.nextInt(1000); DateMidnight midnightToday = new DateMidnight(); DateMidnight midnightAWhileAgo = midnightToday.minusDays(randomNumberOfDaysAgo); timeSheet.setDate(midnightAWhileAgo); timeSheet.setJob(primaryJob); timeSheet.setStatus("Status?"); int hours = 20 + random.nextInt(30); int quarterHours = random.nextInt(4); double total = hours + (0.25 * quarterHours); timeSheet.setTotal(new BigDecimal(total)); timeSheet.setType("Type?"); timesheets.add(timeSheet); } this.emplIdToListOfTimeSheets.put(emplId, timesheets); return timesheets; }
From source file:io.viewserver.core.BusinessDayCalculator.java
License:Apache License
public int getBusinessDay(ReadableDateTime start, ReadableDateTime end) { DateMidnight startMidnight = new DateMidnight(start); DateMidnight endMidnight = new DateMidnight(end); int weekdayStart = startMidnight.get(DateTimeFieldType.dayOfWeek()); int weekdayEnd = endMidnight.get(DateTimeFieldType.dayOfWeek()); if (weekdayStart == DateTimeConstants.SATURDAY) { startMidnight = startMidnight.plusDays(2); weekdayStart = DateTimeConstants.MONDAY; } else if (weekdayStart == DateTimeConstants.SUNDAY) { startMidnight = startMidnight.plusDays(1); weekdayStart = DateTimeConstants.MONDAY; }//from w ww .j a va 2s. c o m if (weekdayEnd == DateTimeConstants.SATURDAY) { endMidnight = endMidnight.minusDays(1); weekdayEnd = DateTimeConstants.FRIDAY; } else if (weekdayEnd == DateTimeConstants.SUNDAY) { endMidnight = endMidnight.minusDays(2); weekdayEnd = DateTimeConstants.FRIDAY; } int days = Days.daysBetween(startMidnight, endMidnight).getDays(); startMidnight = startMidnight.plusDays(DateTimeConstants.SATURDAY - weekdayStart); endMidnight = endMidnight.plusDays(DateTimeConstants.SATURDAY - weekdayEnd); int daysBetweenWeekends = (int) ((endMidnight.getMillis() - startMidnight.getMillis()) / (24 * 60 * 60 * 1000)); int weekendDays = daysBetweenWeekends * 2 / 7; days -= weekendDays; return days; }
From source file:net.naonedbus.manager.impl.HoraireManager.java
License:Open Source License
/** * Rcuprer les horaires d'un arrt.//w w w .j a v a 2 s . co m * * @throws IOException */ public List<Horaire> getSchedules(final ContentResolver contentResolver, final Arret arret, final DateMidnight date, final DateTime after) throws IOException { // Le cache ne doit stocker que les horaires du jour et du lendemain. final DateMidnight cacheLimit = new DateMidnight().plusDays(DAYS_IN_CACHE); final DateMidnight today = new DateMidnight(); final DateTime now = new DateTime(); List<Horaire> horaires; if (date.isBefore(cacheLimit)) { final ScheduleToken todayToken = new ScheduleToken(date.getMillis(), arret.getId()); // Partie atomique synchronized (mDatabaseLock) { if (!isInDB(contentResolver, todayToken)) { // Charger les horaires depuis le web et les stocker en base if (date.isEqual(today) && now.getHourOfDay() < END_OF_TRIP_HOURS) { // Charger la veille si besoin (pour les horaires aprs // minuit) final ScheduleToken yesterdayToken = new ScheduleToken(date.minusDays(1).getMillis(), arret.getId()); if (isInDB(contentResolver, yesterdayToken)) { horaires = mController.getAllFromWeb(arret, date.minusDays(1)); fillDB(contentResolver, yesterdayToken, horaires); } } horaires = mController.getAllFromWeb(arret, date); fillDB(contentResolver, todayToken, horaires); } // Charger les horaires depuis la base final Uri.Builder builder = HoraireProvider.CONTENT_URI.buildUpon(); builder.path(HoraireProvider.HORAIRE_JOUR_URI_PATH_QUERY); builder.appendQueryParameter(HoraireProvider.PARAM_ARRET_ID, String.valueOf(arret.getId())); builder.appendQueryParameter(HoraireProvider.PARAM_JOUR, mIso8601Format.format(date.toDate())); builder.appendQueryParameter(HoraireProvider.PARAM_INCLUDE_LAST_DAY_TRIP, "true"); // Eviter l'affichage de doublons if (after != null) { builder.appendQueryParameter(HoraireProvider.PARAM_AFTER_TIME, mIso8601Format.format(after.toDate())); } final Cursor cursor = contentResolver.query(builder.build(), null, null, null, null); horaires = getFromCursor(cursor); cursor.close(); } } else { horaires = mController.getAllFromWeb(arret, date); } return horaires; }