Example usage for org.joda.time DateMidnight DateMidnight

List of usage examples for org.joda.time DateMidnight DateMidnight

Introduction

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

Prototype

public DateMidnight(Object instant) 

Source Link

Document

Constructs an instance from an Object that represents a datetime.

Usage

From source file:com.google.sampling.experiential.server.PacoServiceImpl.java

License:Open Source License

/**
 * @param experimentId/*  w ww  . j a  v a2 s .  c om*/
 * @param justUser
 * @return
 */
private void getDailyResponseRateFor(Long experimentId, List<EventDAO> events, ExperimentStatsDAO accum,
        boolean justUser) {
    Map<DateMidnight, DateStat> dateStatsMap = Maps.newHashMap();
    Map<DateMidnight, Set<String>> sevenDayMap = Maps.newHashMap();

    int missedSignals = 0;
    long totalMillisToRespond = 0;
    for (EventDAO event : events) {
        if (event.isJoinEvent()) {
            continue;
        }
        if (event.isMissedSignal()) {
            missedSignals++;
            continue;
        }
        totalMillisToRespond += event.responseTime();
        Date date = event.getResponseTime();
        if (date == null) {
            date = event.getWhen();
        }
        DateMidnight dateMidnight = new DateMidnight(date);

        // Daily response count
        DateStat currentStat = dateStatsMap.get(dateMidnight);
        if (currentStat == null) {
            currentStat = new DateStat(dateMidnight.toDate());
            currentStat.addValue(new Double(1));
            dateStatsMap.put(dateMidnight, currentStat);
        } else {
            List<Double> values = currentStat.getValues();
            values.set(0, values.get(0) + 1);
        }

        // 7 day counts
        DateMidnight beginningOfWeekDateMidnight = getBeginningOfWeek(dateMidnight);
        Set<String> current7Day = sevenDayMap.get(beginningOfWeekDateMidnight);
        if (current7Day == null) {
            current7Day = Sets.newHashSet();
            sevenDayMap.put(beginningOfWeekDateMidnight, current7Day);
        }
        current7Day.add(event.getWho());
    }
    // daily response
    ArrayList<DateStat> dateStats = Lists.newArrayList(dateStatsMap.values());
    Collections.sort(dateStats);
    for (DateStat dateStat : dateStats) {
        dateStat.computeStats();
    }
    // 7 day count
    ArrayList<DateStat> sevenDayDateStats = Lists.newArrayList();
    for (DateMidnight dateKey : sevenDayMap.keySet()) {
        int count = sevenDayMap.get(dateKey).size();
        DateStat dateStat = new DateStat(dateKey.toDate());
        dateStat.addValue(new Double(count));
        sevenDayDateStats.add(dateStat);
        dateStat.computeStats();
    }
    Collections.sort(sevenDayDateStats);

    DateStat[] dsArray = new DateStat[dateStats.size()];
    accum.setDailyResponseRate(dateStats.toArray(dsArray));
    dsArray = new DateStat[sevenDayDateStats.size()];
    accum.setSevenDayDateStats(sevenDayDateStats.toArray(dsArray));

    String responseRateStr = "0%";
    int respondedSignals = events.size() - missedSignals;
    if (events.size() > 0) {
        float responseRate = ((float) respondedSignals / (float) events.size()) * 100;
        responseRateStr = Float.toString(responseRate) + "%";
    }
    accum.setResponseRate(responseRateStr);
    float avgResponseTime = (float) totalMillisToRespond / (float) respondedSignals / 60000;
    accum.setResponseTime(Float.toString(Math.round(avgResponseTime)));
}

From source file:com.inkubator.common.util.DateTimeUtil.java

/**
 * get total times (Age) based on date parameter
 *
 * @param birthDate input date type/*from w w w  .j a  v a 2  s  . c  om*/
 * @return Integer age that calculate from today
 * @throws java.lang.Exception
 *
 */
public static Integer getAge(Date birthDate) throws Exception {
    if (birthDate.after(new Date())) {
        throw new Exception("Mr DHFR say :Your birthdate is newer than to day. Can't be born in the future!");
    } else {
        DateMidnight date1 = new DateMidnight(birthDate);
        DateTime now = new DateTime();
        Years years = Years.yearsBetween(date1, now);
        return years.getYears();
    }
}

From source file:com.inkubator.common.util.DateTimeUtil.java

/**
 * get total days difference, between two date type
 *
 * @return Integer/*from   w  w  w  .jav  a  2 s.c  o m*/
 * @param date1 Date reference
 * @param date2 Date reference
 */
public static Integer getTotalDayDifference(Date date1, Date date2) {
    Days days = Days.daysBetween(new DateMidnight(date1), new DateMidnight(date2));
    return days.getDays();
}

From source file:com.inkubator.common.util.DateTimeUtil.java

/**
 * get total months difference, between two date type
 *
 * @return Integer/*from   ww w . j a  v a2 s  .  c om*/
 * @param date1 Date reference
 * @param date2 Date reference
 */
public static Integer getTotalMonthDifference(Date date1, Date date2) {
    Months months = Months.monthsBetween(new DateMidnight(date1), new DateMidnight(date2));
    return months.getMonths();
}

From source file:com.inkubator.common.util.DateTimeUtil.java

/**
 * get total years difference, between two date type
 *
 * @return Integer/*from   w w w  .  j  av  a 2 s .c  o  m*/
 * @param date1 Date reference
 * @param date2 Date reference
 */
public static Integer getTotalYearDifference(Date date1, Date date2) {
    return Years.yearsBetween(new DateMidnight(date1), new DateMidnight(date2)).getYears();
}

From source file:com.inkubator.hrm.web.payroll.SalaryConfirmationDetailController.java

@PostConstruct
@Override//from w  ww .  j ava2 s  . co  m
public void initialization() {
    try {
        super.initialization();
        ResourceBundle messages = ResourceBundle.getBundle("Messages",
                new Locale(FacesUtil.getSessionAttribute(HRMConstant.BAHASA_ACTIVE).toString()));
        String empDataId = FacesUtil.getRequestParameter("execution");
        selectedPayTempKalkulasi = payTempKalkulasiService
                .getEntityByEmpIdAndModelTakeHomePayId(Long.parseLong(empDataId.substring(1)));
        WtPeriode wtPeriode = wtPeriodeService.getEntityByPayrollTypeActive();
        DateMidnight date1 = new DateMidnight(selectedPayTempKalkulasi.getEmpData().getJoinDate());
        DateTime now = new DateTime(wtPeriode.getUntilPeriode());
        // mencari total tahun
        Years years = Years.yearsBetween(date1, now);
        //mencari total bulan
        Integer totalMonth = DateTimeUtil.getTotalMonthDifference(
                selectedPayTempKalkulasi.getEmpData().getJoinDate(), wtPeriode.getUntilPeriode());
        //mencari total sisa bulan
        Integer totalMonthDifference = totalMonth - (12 * years.getYears());
        yearMonth = years.getYears() + " " + messages.getString("global.year") + " " + totalMonthDifference
                + " " + messages.getString("global.month");

        //list pay temp kalkulasi
        listPayTempKalkulasi = payTempKalkulasiService
                .getAllDataByEmpDataIdAndExcludeCompTHP(Long.valueOf(empDataId.substring(1)));
        listTempKalkulasiPajak = payTempKalkulasiEmpPajakService
                .getAllDataByEmpDataId(Long.valueOf(empDataId.substring(1)));
        listPayReceiverAccountModel = payReceiverBankAccountService
                .getAllDataByEmpDataId(Long.valueOf(empDataId.substring(1)));
    } catch (Exception ex) {
        LOGGER.error("Error", ex);

    }
}

From source file:com.intuit.wasabi.analytics.impl.Rollup.java

License:Apache License

DateMidnight fetchLatestRollupDate() {
    @SuppressWarnings("rawtypes")
    List<Map> dayRow = queryDatabase();
    if (dayRow.isEmpty()) {
        return null;
    }/*  ww w  .  j a v a  2  s  .c  om*/
    return new DateMidnight(dayRow.get(0).get("day"));
}

From source file:com.intuit.wasabi.analytics.impl.Rollup.java

License:Apache License

DateMidnight today() {
    return new DateMidnight(DateTimeZone.UTC);
}

From source file:com.intuit.wasabi.experimentobjects.Experiment.java

License:Apache License

/**
 * Calculates the last day of the experiment.
 *
 * This is generally the experiment end date, but may be an earlier date if
 * the experiment was TERMINATED early. In this case the modification date
 * is used.//from   ww w .  j ava 2s. co  m
 *
 * @return earliestDay
 */
@JsonIgnore
public DateMidnight calculateLastDay() {
    DateMidnight earliestDay = new DateMidnight(endTime);
    if (state.equals(State.TERMINATED)) {
        DateMidnight modifiedDay = new DateMidnight(modificationTime);
        if (modifiedDay.isBefore(earliestDay)) {
            earliestDay = modifiedDay;
        }
    }
    return earliestDay;
}

From source file:com.liteoc.logic.expressionTree.ArithmeticOpNode.java

License:LGPL

private String calculateDaysBetween(String value1, String value2) {
    DateMidnight dm1 = new DateMidnight(ExpressionTreeHelper.getDate(value1).getTime());
    DateMidnight dm2 = new DateMidnight(ExpressionTreeHelper.getDate(value2).getTime());
    switch (op) {
    case MINUS: {
        Days d = Days.daysBetween(dm1, dm2);
        int days = d.getDays();
        return String.valueOf(Math.abs(days));
    }//from  w  w  w  .  j  ava2  s  .  com
    default:
        return null; // Bad operator!
    }
}