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.aliakseipilko.flightdutytracker.presenter.impl.HourPresenter.java

License:Open Source License

@Override
public void getFlightHoursInPastDays(int days) {

    DateTime dateTime = DateTime.now();
    Date startDate = dateTime.minusDays(days).toDate();

    repository.getMultipleFlightsByDateRange(startDate, new Date(), Sort.DESCENDING,
            getMultipleFlightsFlightHoursCallback);
}

From source file:com.aurel.track.util.DateTimeUtils.java

License:Open Source License

/**
 * Add numberOfDays to a date //from   w ww .  jav a 2s.  c o m
 * @param date
 * @param numberOfDays
 * @param jumpOverWeekend
 * @return
 */
public static Date moveByDays(Date date, int numberOfDays, boolean add, boolean onlyWorkdays) {
    DateTime dateTime = new DateTime(getZeroTimeDate(date));
    if (onlyWorkdays) {
        int i = 0;
        while (i < numberOfDays) {
            if (add) {
                dateTime = dateTime.plusDays(1);
            } else {
                dateTime = dateTime.minusDays(1);
            }
            if (dateTime.getDayOfWeek() <= 5) {
                i++;
            }
        }
    } else {
        if (add) {
            dateTime = dateTime.plusDays(numberOfDays);
        } else {
            dateTime = dateTime.minusDays(numberOfDays);
        }
    }
    return dateTime.toDate();
}

From source file:com.boha.golfkids.util.NewGolfGroupUtil.java

private static void generateExampleTournament(boolean isLive, GolfGroup gg, List<Player> pList, int clubID,
        String tournamentName, int rounds, boolean useAgeGroups, int holesPerRound, int gender,
        DataUtil dataUtil, PlatformUtil platformUtil) throws DataException {
    DateTime dt = new DateTime();
    dt = dt.minusDays(7);
    ////from w w  w. j a  v a 2s  .c o m
    TournamentDTO t = new TournamentDTO();
    t.setTourneyName(tournamentName);
    t.setGolfRounds(rounds);
    t.setStartDate(dt.getMillis());
    t.setClubID(clubID);
    t.setGolfGroupID(gg.getGolfGroupID());
    t.setHolesPerRound(holesPerRound);
    t.setExampleFlag(1);
    t.setTournamentType(RequestDTO.STROKE_PLAY_INDIVIDUAL);

    if (holesPerRound == 9) {
        t.setPar(36);
    } else {
        t.setPar(72);
    }
    if (rounds > 1) {
        for (int i = 0; i < rounds; i++) {
            dt = dt.plusDays(i);
        }
        t.setEndDate(dt.getMillis());
    } else {
        t.setEndDate(t.getStartDate());
    }
    if (useAgeGroups) {
        t.setUseAgeGroups(1);
    }
    ResponseDTO r = dataUtil.addTournament(t, platformUtil);
    Tournament tournament = new Tournament();
    List<TournamentDTO> tList = r.getTournaments();
    for (TournamentDTO tn : tList) {
        if (tn.getTourneyName().equalsIgnoreCase(t.getTourneyName())) {
            tournament = dataUtil.getTournamentByID(tn.getTournamentID());
            break;
        }
    }
    List<LeaderBoard> list = addPlayersToTournament(pList, tournament, gender, dataUtil, platformUtil);
    log.log(Level.INFO, "LeaderBoard items generated, about to score: {0}", list.size());

    List<TourneyScoreByRound> tsbrList = generateScores(list, tournament.getTournamentID(), dataUtil,
            tournament.getGolfRounds());
    if (isLive) {
        generateScoresForLiveLeaderBoard(tsbrList, list, tournament, dataUtil, rounds);
    }

    log.log(Level.OFF, "Sample Tournament generated: {0} - {1}",
            new Object[] { gg.getGolfGroupName(), tournamentName });
}

From source file:com.boha.monitor.utilx.ListUtil.java

public static ResponseDTO getLocationTracksByMonitorInPeriod(EntityManager em, Integer monitorID, Long df,
        Long dx) {/*from   w  w w .  j  a  v  a 2  s  . co  m*/
    Date dateFrom, dateTo;
    if (df == null) {
        DateTime dt = new DateTime();
        DateTime xx = dt.minusDays(1);
        dateFrom = xx.toDate();
        dateTo = dt.toDate();
        log.log(Level.INFO, "Get Location tracks from {0} to {1}",
                new Object[] { dateFrom.toString(), dateTo.toString() });
    } else {
        dateFrom = new Date(df);
        dateTo = new Date(dx);
    }
    ResponseDTO resp = new ResponseDTO();
    Query q = em.createNamedQuery("LocationTracker.findByMonitorInPeriod", LocationTracker.class);
    q.setParameter("monitorID", monitorID);
    q.setParameter("dateFrom", dateFrom);
    q.setParameter("dateTo", dateTo);
    q.setMaxResults(5);
    List<LocationTracker> list = q.getResultList();
    resp.setLocationTrackerList(new ArrayList<>());
    for (LocationTracker t : list) {
        resp.getLocationTrackerList().add(new LocationTrackerDTO(t));
    }
    return resp;
}

From source file:com.boha.monitor.utilx.ListUtil.java

public static ResponseDTO getLocationTracksByStaffInPeriod(EntityManager em, Integer companyStaffID, Long df,
        Long dx) {/*w  w  w.  j  a va  2s.co  m*/
    Date dateFrom, dateTo;
    if (df == null) {
        DateTime dt = new DateTime();
        DateTime xx = dt.minusDays(1);
        dateFrom = xx.toDate();
        dateTo = dt.toDate();
        log.log(Level.INFO, "Get Location tracks from {0} to {1}",
                new Object[] { dateFrom.toString(), dateTo.toString() });
    } else {
        dateFrom = new Date(df);
        dateTo = new Date(dx);
    }
    ResponseDTO resp = new ResponseDTO();
    Query q = em.createNamedQuery("LocationTracker.findByStaffInPeriod", LocationTracker.class);
    q.setParameter("staffID", companyStaffID);
    q.setParameter("dateFrom", dateFrom);
    q.setParameter("dateTo", dateTo);
    List<LocationTracker> list = q.getResultList();
    resp.setLocationTrackerList(new ArrayList<>());
    for (LocationTracker t : list) {
        resp.getLocationTrackerList().add(new LocationTrackerDTO(t));
    }
    return resp;
}

From source file:com.boha.monitor.utilx.ListUtil.java

public static ResponseDTO getLocationTracksByCompany(EntityManager em, Integer companyID, Long df, Long dx) {

    Date dateFrom, dateTo;/* ww  w .jav a  2 s  . c o m*/
    if (df == null) {
        DateTime dt = new DateTime();
        DateTime xx = dt.minusDays(7);
        dateFrom = xx.toDate();
        dateTo = dt.toDate();
        log.log(Level.INFO, "Get Location tracks from {0} to {1}",
                new Object[] { dateFrom.toString(), dateTo.toString() });
    } else {
        dateFrom = new Date(df);
        dateTo = new Date(dx);
    }
    ResponseDTO resp = new ResponseDTO();
    Query q = em.createNamedQuery("LocationTracker.findByCompanyInPeriod", LocationTracker.class);
    q.setParameter("companyID", companyID);
    q.setParameter("dateFrom", dateFrom);
    q.setParameter("dateTo", dateTo);

    List<LocationTracker> list = q.getResultList();
    resp.setLocationTrackerList(new ArrayList<>());
    list.stream().forEach((t) -> {
        resp.getLocationTrackerList().add(new LocationTrackerDTO(t));
    });

    log.log(Level.INFO, "LocationTrackers found, db: {0} out: {1}",
            new Object[] { list.size(), resp.getLocationTrackerList().size() });
    return resp;
}

From source file:com.boha.monitor.utilx.ListUtil.java

public static ResponseDTO getProjectStatusData(EntityManager em, Integer projectID, int days)
        throws DataException {
    long s = System.currentTimeMillis();
    if (days == 0) {
        days = 30;//  w  w  w .ja  v  a2 s  . c  o  m
    }
    ResponseDTO resp = new ResponseDTO();
    try {
        Project p = em.find(Project.class, projectID);
        ProjectDTO project = new ProjectDTO(p);

        DateTime now = new DateTime();
        DateTime then = now.minusDays(days);
        then = then.withHourOfDay(0);
        then = then.withMinuteOfHour(0);
        then = then.withSecondOfMinute(0);

        project.setProjectTaskList(
                ListUtil.getProjectStatus(em, projectID, then.toDate(), now.toDate()).getProjectTaskList());
        project.setPhotoUploadList(
                getPhotosByProject(em, projectID, then.toDate(), now.toDate()).getPhotoUploadList());

        resp.setProjectList(new ArrayList<>());
        resp.getProjectList().add(project);

        long e = System.currentTimeMillis();
        log.log(Level.INFO, "############---------- project data retrieved: {0} seconds",
                Elapsed.getElapsed(s, e));
    } catch (OutOfMemoryError e) {
        log.log(Level.SEVERE, "Failed", e);
        throw new DataException("Failed to get project data: OUT OF MEMORY!\n");
    }

    return resp;
}

From source file:com.boha.vodacom.util.PoliceStationLoader.java

private Date getDate() {
    DateTime dt = DateTime.now();
    int days = random.nextInt(6);
    DateTime then = dt.minusDays(days);
    return then.toDate();
}

From source file:com.citruspay.JDateUtil.java

License:Open Source License

public static Interval getISTPreviousDay() {
    DateTimeZone ISTTimeZone = DateTimeZone.forID(Asia_Kolkata);
    DateTime dateTime = new DateTime(ISTTimeZone);
    DateTime from = JDateUtil.startOfDay(dateTime.minusDays(1));
    DateTime to = JDateUtil.startOfDay(dateTime);
    return new Interval(from, to);
}

From source file:com.cronutils.model.time.generator.OnDayOfMonthValueGenerator.java

License:Apache License

private int generateValue(On on, int year, int month) throws NoSuchValueException {
    int time = on.getTime().getValue();
    switch (on.getSpecialChar().getValue()) {
    case L://from w w w  .j ava2 s .c  om
        return new DateTime(year, month, 1, 1, 1).dayOfMonth().getMaximumValue();
    case W:
        DateTime doM = new DateTime(year, month, time, 1, 1);
        if (doM.getDayOfWeek() == 6) {//dayOfWeek is Saturday!
            if (time == 1) {//first day in month is Saturday! We execute on Monday
                return 3;
            }
            return time - 1;
        }
        if (doM.getDayOfWeek() == 7) {
            if ((time + 1) <= doM.dayOfMonth().getMaximumValue()) {
                return time + 1;
            }
        }
        break;
    case LW:
        DateTime lastDayOfMonth = new DateTime(year, month,
                new DateTime(year, month, 1, 1, 1).dayOfMonth().getMaximumValue(), 1, 1);
        int dow = lastDayOfMonth.getDayOfWeek();
        int diff = dow - 5;
        if (diff > 0) {
            return lastDayOfMonth.minusDays(diff).dayOfMonth().get();
        }
        return lastDayOfMonth.dayOfMonth().get();
    }
    throw new NoSuchValueException();
}