Example usage for org.joda.time DateTime minusDays

List of usage examples for org.joda.time DateTime minusDays

Introduction

In this page you can find the example usage for org.joda.time DateTime minusDays.

Prototype

public DateTime minusDays(int days) 

Source Link

Document

Returns a copy of this datetime minus the specified number of days.

Usage

From source file:com.salesmanBuddy.dao.JDBCSalesmanBuddyDAO.java

License:Open Source License

private String generateEmailContentForDealershipIdReportType(Integer dealershipId, Integer type) {
    DateTime now = new DateTime(DateTimeZone.forID("America/Denver"));
    final Integer BACK_MINUTES = 10;
    DateTime dayPrevious = now.minusDays(1).minusMinutes(BACK_MINUTES);
    DateTime weekPrevious = now.minusWeeks(1).minusMinutes(BACK_MINUTES);
    DateTime monthPrevious = now.minusMonths(1).minusMinutes(BACK_MINUTES);
    switch (type) {

    case DAILY_TEST_DRIVE_SUMMARY_EMAIL_TYPE:
        return this.testDriveSummaryReport(dealershipId, dayPrevious, now);

    case DAILY_ALL_SALESMAN_SUMMARY_EMAIL_TYPE:
        return this.allSalesmanSummaryReport(dealershipId, dayPrevious, now);

    case DAILY_DEALERSHIP_SUMMARY_EMAIL_TYPE:
        return this.dealershipSummaryReport(dealershipId, dayPrevious, now);

    case DAILY_STOCK_NUMBERS_EMAIL_TYPE:
        return this.stockNumberSummaryReport(dealershipId, dayPrevious, now);

    case WEEKLY_TEST_DRIVE_SUMMARY_EMAIL_TYPE:
        return this.testDriveSummaryReport(dealershipId, weekPrevious, now);

    case WEEKLY_ALL_SALESMAN_SUMMARY_EMAIL_TYPE:
        return this.allSalesmanSummaryReport(dealershipId, weekPrevious, now);

    case WEEKLY_DEALERSHIP_SUMMARY_EMAIL_TYPE:
        return this.dealershipSummaryReport(dealershipId, weekPrevious, now);

    case WEEKLY_STOCK_NUMBERS_EMAIL_TYPE:
        return this.stockNumberSummaryReport(dealershipId, weekPrevious, now);

    case MONTHLY_TEST_DRIVE_SUMMARY_EMAIL_TYPE:
        return this.testDriveSummaryReport(dealershipId, monthPrevious, now);

    case MONTHLY_ALL_SALESMAN_SUMMARY_EMAIL_TYPE:
        return this.allSalesmanSummaryReport(dealershipId, monthPrevious, now);

    case MONTHLY_DEALERSHIP_SUMMARY_EMAIL_TYPE:
        return this.dealershipSummaryReport(dealershipId, monthPrevious, now);

    case MONTHLY_STOCK_NUMBERS_EMAIL_TYPE:
        return this.stockNumberSummaryReport(dealershipId, monthPrevious, now);

    //      case DAILY_SALESMAN_SUMMARY_EMAIL_TYPE:
    //         // w ww  . j a v  a  2  s  . co m
    //         break;
    //
    //      case WEEKLY_SALESMAN_SUMMARY_EMAIL_TYPE:
    //         
    //         break;
    //
    //      case MONTHLY_SALESMAN_SUMMARY_EMAIL_TYPE:
    //         
    //         break;

    default:
        return "Error, couldn't find correct report type";
    }
}

From source file:com.sector.servicios.AvisoSucursalFacade.java

@Override
public List<AvisoSucursal> findAllPorSucursal(int idSucursal) {

    Date hoy = new Date();

    final DateTime dateTime = new DateTime(hoy);

    Date fechaInicio = dateTime.minusDays(30).toDate();

    List<AvisoSucursal> lista = getEntityManager().createNamedQuery("AvisoSucursal.findAllBySucursal")
            .setParameter("idSucursal", idSucursal).setParameter("fecha_inicio", fechaInicio)
            .setParameter("fecha_fin", hoy).getResultList();
    return lista;
}

From source file:com.sonicle.webtop.calendar.rpt.AbstractAgenda.java

License:Open Source License

public void setDataSource(CalendarManager manager, DateTime fromDate, DateTime toDate, DateTimeZone utz,
        Map<Integer, Calendar> calendars, Collection<SchedEventInstance> instances) throws WTException {
    int days = -1;
    if (DateTimeUtils.isEndOfDay(toDate, true)) {
        days = Days.daysBetween(fromDate, toDate).getDays() + 1;
    } else if (DateTimeUtils.isMidnight(toDate)) {
        days = Days.daysBetween(fromDate, toDate).getDays();
    }/*from  www. ja  va 2s. c o m*/

    DateTime dayDateFrom = null;
    ArrayList<Date> dayDates = new ArrayList<>();
    ArrayList<ArrayList<RBAgendaEvent>> daysSpanningEvents = new ArrayList<>();
    ArrayList<ArrayList<RBAgendaEvent>> daysEvents = new ArrayList<>();

    // Prepare structures...
    for (int i = 0; i < days; i++) {
        dayDateFrom = fromDate.plusDays(i);
        dayDates.add(dayDateFrom.toDate());
        daysSpanningEvents.add(new ArrayList<RBAgendaEvent>());
        daysEvents.add(new ArrayList<RBAgendaEvent>());
    }

    // Arranges events by day...
    for (SchedEventInstance sei : instances) {
        for (int i = 0; i < days; i++) {
            dayDateFrom = fromDate.plusDays(i);
            if (isInDay(utz, dayDateFrom, sei.getStartDate(), sei.getEndDate())) {
                Calendar calendar = calendars.get(sei.getCalendarId());
                boolean spanning = true;
                Integer spanLeft = null, spanRight = null;
                if (!sei.getAllDay() && startsInDay(utz, dayDateFrom, sei.getStartDate())
                        && endsInDay(utz, dayDateFrom, sei.getEndDate())) {
                    spanning = false;
                } else {
                    if (startsInDay(utz, dayDateFrom, sei.getStartDate())) {
                        spanRight = DateTimeUtils.datesBetween(dayDateFrom, sei.getEndDate().withZone(utz));
                    }
                    if (endsInDay(utz, dayDateFrom, sei.getEndDate())) {
                        spanLeft = DateTimeUtils.datesBetween(sei.getStartDate().withZone(utz), dayDateFrom);
                    }
                    if (!startsInDay(utz, dayDateFrom, sei.getStartDate())
                            && !endsInDay(utz, dayDateFrom, sei.getEndDate())) {
                        spanLeft = DateTimeUtils.datesBetween(sei.getStartDate().withZone(utz), dayDateFrom);
                        spanRight = DateTimeUtils.datesBetween(dayDateFrom, sei.getEndDate().withZone(utz));
                    }
                }
                if (spanning) {
                    daysSpanningEvents.get(i).add(new RBAgendaEvent(calendar, sei, spanLeft, spanRight));
                } else {
                    daysEvents.get(i).add(new RBAgendaEvent(calendar, sei, spanLeft, spanRight));
                }
            }
        }
    }

    setDataSource(createBeanCollection(new Data(utz, fromDate.toLocalDate(), toDate.minusDays(1).toLocalDate(),
            dayDates, daysSpanningEvents, daysEvents)));
}

From source file:com.sos.scheduler.model.objects.JSObjHolidays.java

License:Apache License

public DateTime getPreviousNonHoliday(DateTime date) {
    DateTime result = date;
    while (isHoliday(result)) {
        result = result.minusDays(1);
    }//  w  ww.  j  a  v a2 s  .c  o  m
    return result;
}

From source file:com.splicemachine.derby.utils.SpliceDateFunctions.java

License:Apache License

/**
 * Implements the trunc_date function//from ww  w .  j  a va 2s.  c om
 */
public static Timestamp TRUNC_DATE(Timestamp source, String field) throws SQLException {
    if (source == null || field == null)
        return null;
    DateTime dt = new DateTime(source);
    field = field.toLowerCase();
    String lowerCaseField = field.toLowerCase();
    if ("microseconds".equals(lowerCaseField)) {
        int nanos = source.getNanos();
        nanos = nanos - nanos % 1000;
        source.setNanos(nanos);
        return source;
    } else if ("milliseconds".equals(lowerCaseField)) {
        int nanos = source.getNanos();
        nanos = nanos - nanos % 1000000;
        source.setNanos(nanos);
        return source;
    } else if ("second".equals(lowerCaseField)) {
        source.setNanos(0);
        return source;

    } else if ("minute".equals(lowerCaseField)) {
        DateTime modified = dt.minusSeconds(dt.getSecondOfMinute());
        Timestamp ret = new Timestamp(modified.getMillis());
        ret.setNanos(0);
        return ret;
    } else if ("hour".equals(lowerCaseField)) {
        DateTime modified = dt.minusMinutes(dt.getMinuteOfHour()).minusSeconds(dt.getSecondOfMinute());
        Timestamp ret = new Timestamp(modified.getMillis());
        ret.setNanos(0);
        return ret;
    } else if ("day".equals(lowerCaseField)) {
        DateTime modified = dt.minusHours(dt.getHourOfDay()).minusMinutes(dt.getMinuteOfHour())
                .minusSeconds(dt.getSecondOfMinute());
        Timestamp ret = new Timestamp(modified.getMillis());
        ret.setNanos(0);
        return ret;
    } else if ("week".equals(lowerCaseField)) {
        DateTime modified = dt.minusDays(dt.getDayOfWeek()).minusHours(dt.getHourOfDay())
                .minusMinutes(dt.getMinuteOfHour()).minusSeconds(dt.getSecondOfMinute());
        Timestamp ret = new Timestamp(modified.getMillis());
        ret.setNanos(0);
        return ret;
    } else if ("month".equals(lowerCaseField)) {
        DateTime modified = dt.minusDays(dt.get(DateTimeFieldType.dayOfMonth()) - 1)
                .minusHours(dt.getHourOfDay()).minusMinutes(dt.getMinuteOfHour())
                .minusSeconds(dt.getSecondOfMinute());
        Timestamp ret = new Timestamp(modified.getMillis());
        ret.setNanos(0);
        return ret;
    } else if ("quarter".equals(lowerCaseField)) {
        int month = dt.getMonthOfYear();
        DateTime modified = dt;
        if ((month + 1) % 3 == 1) {
            modified = dt.minusMonths(2);
        } else if ((month + 1) % 3 == 0) {
            modified = dt.minusMonths(1);
        }
        DateTime fin = modified.minusDays(dt.get(DateTimeFieldType.dayOfMonth()) - 1)
                .minusHours(dt.getHourOfDay()).minusMinutes(dt.getMinuteOfHour())
                .minusSeconds(dt.getSecondOfMinute());
        Timestamp ret = new Timestamp(fin.getMillis());
        ret.setNanos(0);
        return ret;
    } else if ("year".equals(lowerCaseField)) {
        DateTime modified = dt.minusDays(dt.get(DateTimeFieldType.dayOfMonth()) - 1)
                .minusHours(dt.getHourOfDay()).minusMonths(dt.getMonthOfYear() - 1)
                .minusMinutes(dt.getMinuteOfHour()).minusSeconds(dt.getSecondOfMinute());
        Timestamp ret = new Timestamp(modified.getMillis());
        ret.setNanos(0);
        return ret;
    } else if ("decade".equals(lowerCaseField)) {
        DateTime modified = dt.minusDays(dt.get(DateTimeFieldType.dayOfMonth()) - 1)
                .minusYears(dt.getYear() % 10).minusHours(dt.getHourOfDay())
                .minusMonths(dt.getMonthOfYear() - 1).minusMinutes(dt.getMinuteOfHour())
                .minusSeconds(dt.getSecondOfMinute());
        Timestamp ret = new Timestamp(modified.getMillis());
        ret.setNanos(0);
        return ret;
    } else if ("century".equals(lowerCaseField)) {
        DateTime modified = dt.minusDays(dt.get(DateTimeFieldType.dayOfMonth()) - 1)
                .minusHours(dt.getHourOfDay()).minusYears(dt.getYear() % 100)
                .minusMonths(dt.getMonthOfYear() - 1).minusMinutes(dt.getMinuteOfHour())
                .minusSeconds(dt.getSecondOfMinute());
        Timestamp ret = new Timestamp(modified.getMillis());
        ret.setNanos(0);
        return ret;
    } else if ("millennium".equals(lowerCaseField)) {
        int newYear = dt.getYear() - dt.getYear() % 1000;
        //noinspection deprecation (converstion from joda to java.sql.Timestamp did not work for millennium < 2000)
        return new Timestamp(newYear - 1900, Calendar.JANUARY, 1, 0, 0, 0, 0);
    } else {
        throw new SQLException(String.format("invalid time unit '%s'", field));
    }
}

From source file:com.splout.db.examples.PageCountsDataGenerator.java

License:Apache License

public void generate(File namesFile, int days, File outFolder) throws IOException {
    if (outFolder.exists()) {
        FileUtils.deleteDirectory(outFolder);
    }// w w w .j a v a 2 s  . c o  m
    outFolder.mkdirs();

    if (!namesFile.exists()) {
        throw new IllegalArgumentException("Provided names file doesn't exist (" + namesFile + ")");
    }

    List<String> names = Files.readLines(namesFile, Charset.forName("UTF-8"));

    DateTime today = new DateTime();
    DateTime someDaysBefore = today.minusDays(days);

    someDaysBefore = someDaysBefore.withMinuteOfHour(0);
    someDaysBefore = someDaysBefore.withSecondOfMinute(0);

    while (someDaysBefore.isBefore(today)) {
        for (int hour = 0; hour < 24; hour++) {

            someDaysBefore = someDaysBefore.withHourOfDay(hour);

            File currentFile = new File(outFolder, "pagecounts-" + format.print(someDaysBefore));
            BufferedWriter writer = new BufferedWriter(new FileWriter(currentFile));

            for (String name : names) {
                int pageviews = (int) (Math.random() * 10000) + 1;
                writer.write("en " + name + " " + pageviews + " 0" + "\n");
            }

            writer.close();
        }
        someDaysBefore = someDaysBefore.plusDays(1);
    }
}

From source file:com.tango.BucketSyncer.MirrorOptions.java

License:Apache License

private long initMaxAge() {

    DateTime dateTime = new DateTime(nowTime);

    // all digits -- assume "days"
    if (ctime.matches("^[0-9]+$"))
        return dateTime.minusDays(Integer.parseInt(ctime)).getMillis();

    // ensure there is at least one digit, and exactly one character suffix, and the suffix is a legal option
    if (!ctime.matches("^[0-9]+[yMwdhms]$"))
        throw new IllegalArgumentException("Invalid option for ctime: " + ctime);

    if (ctime.endsWith("y"))
        return dateTime.minusYears(getCtimeNumber(ctime)).getMillis();
    if (ctime.endsWith("M"))
        return dateTime.minusMonths(getCtimeNumber(ctime)).getMillis();
    if (ctime.endsWith("w"))
        return dateTime.minusWeeks(getCtimeNumber(ctime)).getMillis();
    if (ctime.endsWith("d"))
        return dateTime.minusDays(getCtimeNumber(ctime)).getMillis();
    if (ctime.endsWith("h"))
        return dateTime.minusHours(getCtimeNumber(ctime)).getMillis();
    if (ctime.endsWith("m"))
        return dateTime.minusMinutes(getCtimeNumber(ctime)).getMillis();
    if (ctime.endsWith("s"))
        return dateTime.minusSeconds(getCtimeNumber(ctime)).getMillis();
    throw new IllegalArgumentException("Invalid option for ctime: " + ctime);
}

From source file:com.tikal.tallerWeb.modelo.alerta.RangoAlertaVerificacion.java

License:Apache License

private DateTime armaFechaRangoIzquierdo(int mes, int yearSwift) {
    DateTime r = new DateTime();
    r = new DateTime(r.getYear() + yearSwift, mes, r.dayOfMonth().getMinimumValue(),
            r.hourOfDay().getMinimumValue(), r.minuteOfHour().getMinimumValue(),
            r.secondOfMinute().getMinimumValue(), r.millisOfSecond().getMinimumValue(), r.getZone());
    r = r.minusDays(diasAntesDelMes);
    return r;//from   www  . ja va 2s . c  o m
}

From source file:com.uber.hoodie.cli.utils.HiveUtil.java

License:Apache License

public static long countRecords(String jdbcUrl, HoodieTableMetaClient source, String srcDb, int partitions,
        String user, String pass) throws SQLException {
    DateTime dateTime = DateTime.now();
    String endDateStr = dateTime.getYear() + "-" + String.format("%02d", dateTime.getMonthOfYear()) + "-"
            + String.format("%02d", dateTime.getDayOfMonth());
    dateTime = dateTime.minusDays(partitions);
    String startDateStr = dateTime.getYear() + "-" + String.format("%02d", dateTime.getMonthOfYear()) + "-"
            + String.format("%02d", dateTime.getDayOfMonth());
    System.out.println("Start date " + startDateStr + " and end date " + endDateStr);
    return countRecords(jdbcUrl, source, srcDb, startDateStr, endDateStr, user, pass);
}

From source file:com.ut.tekir.report.RetrospectiveDebtorContactReportBean.java

License:LGPL

private Date getRolledTime(int interval) {
    log.debug("gelen param : #0", interval);

    DateTime dt = new DateTime(filterModel.getDate());
    log.debug("rapor gunu  : #0", dt.toDate());

    dt = dt.minusDays(interval);
    log.debug("dt edilen : #0", dt.toDate());

    return dt.toDate();
}