Example usage for org.joda.time MutablePeriod add

List of usage examples for org.joda.time MutablePeriod add

Introduction

In this page you can find the example usage for org.joda.time MutablePeriod add.

Prototype

public void add(long duration) 

Source Link

Document

Adds a millisecond duration to this one by dividing the duration into fields and calling #add(ReadablePeriod) .

Usage

From source file:de.tshw.worktracker.view.TimeEntriesTableModel.java

License:MIT License

public String update(WorkTracker workTracker) {
    int oldProjectCount = elapsedTimes.size();
    HashMap<Project, MutablePeriod> newTimes = new HashMap<>();
    for (Project p : workTracker.getProjects()) {
        newTimes.put(p, new MutablePeriod());
    }/*from w ww  .  j  a v  a 2  s  . c om*/
    MutablePeriod totalTimeToday = new MutablePeriod();
    for (WorkLogEntry entry : workTracker.getTodaysWorkLogEntries()) {
        if (!newTimes.containsKey(entry.getProject())) {
            newTimes.put(entry.getProject(), new MutablePeriod());
        }
        if (entry.getStartTime().toLocalDate().toDateTimeAtStartOfDay()
                .equals(LocalDate.now().toDateTimeAtStartOfDay())) {
            newTimes.get(entry.getProject()).add(entry.getTimeElapsed());
            if (!entry.getProject().equals(workTracker.getPauseProject())) {
                totalTimeToday.add(entry.getTimeElapsed());
            }
        }
    }
    WorkLogEntry entry = workTracker.getCurrentLogEntry();
    Period period = new Period(entry.getStartTime(), LocalDateTime.now());
    newTimes.get(entry.getProject()).add(period);
    if (!entry.getProject().equals(workTracker.getPauseProject())) {
        totalTimeToday.add(period);
    }

    for (Project p : newTimes.keySet()) {
        elapsedTimes.put(p, newTimes.get(p).toPeriod());
    }

    this.totalTimeElapsedToday = totalTimeToday.toPeriod();
    if (oldProjectCount == elapsedTimes.size()) {
        this.fireTableRowsUpdated(0, elapsedTimes.size());
    } else {
        this.fireTableDataChanged();
    }

    return periodFormatter.print(this.totalTimeElapsedToday.normalizedStandard());
}

From source file:org.oscarehr.common.dao.PopulationReportDao.java

License:Open Source License

public int[] getUsages(int numYears) {

    int[] shelterUsages = new int[3];

    Map<Integer, Set<Stay>> clientIdToStayMap = new HashMap<Integer, Set<Stay>>();

    Calendar instant = Calendar.getInstance();
    Date end = instant.getTime();
    Date start = DateTimeFormatUtils.getPast(instant, numYears);

    for (Object o : getHibernateTemplate().find(HQL_GET_USAGES, start)) {
        Object[] tuple = (Object[]) o;

        Integer clientId = (Integer) tuple[0];
        Date admission = (Date) tuple[1];
        Date discharge = (Date) tuple[2];

        if (!clientIdToStayMap.containsKey(clientId)) {
            clientIdToStayMap.put(clientId, new HashSet<Stay>());
        }//from  w w w  .j a v a  2s  . c  o  m

        try {
            Stay stay = new Stay(admission, discharge, start, end);
            clientIdToStayMap.get(clientId).add(stay);
        } catch (IllegalArgumentException e) {
            logger.error("client id: " + clientId);
        }
    }

    for (Entry<Integer, Set<Stay>> entry : clientIdToStayMap.entrySet()) {
        MutablePeriod period = new MutablePeriod(PeriodType.days());

        for (Stay stay : entry.getValue()) {
            period.add(stay.getInterval());
        }

        int days = Days.standardDaysIn(period).getDays();

        if (days <= 10) {
            shelterUsages[LOW] += 1;
        } else if (11 <= days && days <= 179) {
            shelterUsages[MEDIUM] += 1;
        } else if (180 <= days) {
            shelterUsages[HIGH] += 1;
        }
    }

    return shelterUsages;
}