Example usage for org.joda.time DateTime hourOfDay

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

Introduction

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

Prototype

public Property hourOfDay() 

Source Link

Document

Get the hour of day field property which provides access to advanced functionality.

Usage

From source file:org.apereo.portal.events.aggr.AggregationInterval.java

License:Apache License

/**
 * Determine the ending DateTime (exclusive) of an interval based on an instant in time
 *
 * @param instant The start of an instant
 * @return//from  w ww  . j  a  v a2 s .c o m
 */
public DateTime determineEnd(DateTime instant) {
    if (this.dateTimeFieldType != null) {
        final DateTime start = instant.property(this.dateTimeFieldType).roundFloorCopy();
        return start.property(this.dateTimeFieldType).addToCopy(1);
    }

    if (this == AggregationInterval.FIVE_MINUTE) {
        final DateTime start = instant.hourOfDay().roundFloorCopy()
                .plusMinutes((instant.getMinuteOfHour() / 5) * 5);
        return start.plusMinutes(5);
    }

    throw new IllegalArgumentException(
            "Cannot compute interval end time for " + this + " please use " + AggregationIntervalHelper.class);
}

From source file:org.cosmo.common.util.Util.java

License:Apache License

public static Date firstHourOfDay() {
    DateTime d = new DateTime();
    return d.hourOfDay().setCopy(0).toDate();
}

From source file:org.hawkular.metrics.core.impl.DateTimeService.java

License:Apache License

public DateTime getTimeSlice(DateTime dt, Duration duration) {
    Period p = duration.toPeriod();

    if (p.getYears() != 0) {
        return dt.yearOfEra().roundFloorCopy().minusYears(dt.getYearOfEra() % p.getYears());
    } else if (p.getMonths() != 0) {
        return dt.monthOfYear().roundFloorCopy().minusMonths((dt.getMonthOfYear() - 1) % p.getMonths());
    } else if (p.getWeeks() != 0) {
        return dt.weekOfWeekyear().roundFloorCopy().minusWeeks((dt.getWeekOfWeekyear() - 1) % p.getWeeks());
    } else if (p.getDays() != 0) {
        return dt.dayOfMonth().roundFloorCopy().minusDays((dt.getDayOfMonth() - 1) % p.getDays());
    } else if (p.getHours() != 0) {
        return dt.hourOfDay().roundFloorCopy().minusHours(dt.getHourOfDay() % p.getHours());
    } else if (p.getMinutes() != 0) {
        return dt.minuteOfHour().roundFloorCopy().minusMinutes(dt.getMinuteOfHour() % p.getMinutes());
    } else if (p.getSeconds() != 0) {
        return dt.secondOfMinute().roundFloorCopy().minusSeconds(dt.getSecondOfMinute() % p.getSeconds());
    }//from w ww. j a va  2 s  .  c  o m
    return dt.millisOfSecond().roundCeilingCopy().minusMillis(dt.getMillisOfSecond() % p.getMillis());
}

From source file:org.hawkular.metrics.datetime.DateTimeService.java

License:Apache License

public static DateTime getTimeSlice(DateTime dt, Duration duration) {
    Period p = duration.toPeriod();

    if (p.getYears() != 0) {
        return dt.yearOfEra().roundFloorCopy().minusYears(dt.getYearOfEra() % p.getYears());
    } else if (p.getMonths() != 0) {
        return dt.monthOfYear().roundFloorCopy().minusMonths((dt.getMonthOfYear() - 1) % p.getMonths());
    } else if (p.getWeeks() != 0) {
        return dt.weekOfWeekyear().roundFloorCopy().minusWeeks((dt.getWeekOfWeekyear() - 1) % p.getWeeks());
    } else if (p.getDays() != 0) {
        return dt.dayOfMonth().roundFloorCopy().minusDays((dt.getDayOfMonth() - 1) % p.getDays());
    } else if (p.getHours() != 0) {
        return dt.hourOfDay().roundFloorCopy().minusHours(dt.getHourOfDay() % p.getHours());
    } else if (p.getMinutes() != 0) {
        return dt.minuteOfHour().roundFloorCopy().minusMinutes(dt.getMinuteOfHour() % p.getMinutes());
    } else if (p.getSeconds() != 0) {
        return dt.secondOfMinute().roundFloorCopy().minusSeconds(dt.getSecondOfMinute() % p.getSeconds());
    }/*from ww w . ja  v  a 2 s .c om*/
    return dt.millisOfSecond().roundCeilingCopy().minusMillis(dt.getMillisOfSecond() % p.getMillis());
}

From source file:org.hawkular.metrics.tasks.api.AbstractTrigger.java

License:Apache License

protected DateTime getExecutionTime(long time, Duration duration) {
    DateTime dt = new DateTime(time);
    Period p = duration.toPeriod();

    if (p.getYears() != 0) {
        return dt.yearOfEra().roundFloorCopy().minusYears(dt.getYearOfEra() % p.getYears());
    } else if (p.getMonths() != 0) {
        return dt.monthOfYear().roundFloorCopy().minusMonths((dt.getMonthOfYear() - 1) % p.getMonths());
    } else if (p.getWeeks() != 0) {
        return dt.weekOfWeekyear().roundFloorCopy().minusWeeks((dt.getWeekOfWeekyear() - 1) % p.getWeeks());
    } else if (p.getDays() != 0) {
        return dt.dayOfMonth().roundFloorCopy().minusDays((dt.getDayOfMonth() - 1) % p.getDays());
    } else if (p.getHours() != 0) {
        return dt.hourOfDay().roundFloorCopy().minusHours(dt.getHourOfDay() % p.getHours());
    } else if (p.getMinutes() != 0) {
        return dt.minuteOfHour().roundFloorCopy().minusMinutes(dt.getMinuteOfHour() % p.getMinutes());
    } else if (p.getSeconds() != 0) {
        return dt.secondOfMinute().roundFloorCopy().minusSeconds(dt.getSecondOfMinute() % p.getSeconds());
    }/*from w  w  w . j a v a 2  s.co  m*/
    return dt.millisOfSecond().roundCeilingCopy().minusMillis(dt.getMillisOfSecond() % p.getMillis());
}

From source file:org.jevis.commons.driver.DataSourceHelper.java

License:Open Source License

private static DateTime getFolderTime(String name, String[] pathStream) {
    String compactDateString = getCompactDateString(name, pathStream);
    String compactDataFormatString = getCompactDateFormatString(name, pathStream);

    DateTimeFormatter dtf = DateTimeFormat.forPattern(compactDataFormatString);

    DateTime parseDateTime = dtf.parseDateTime(compactDateString);
    if (parseDateTime.year().get() == parseDateTime.year().getMinimumValue()) {
        parseDateTime = parseDateTime.year().withMaximumValue();
    }/*www . ja  v a 2 s . c o m*/
    if (parseDateTime.monthOfYear().get() == parseDateTime.monthOfYear().getMinimumValue()) {
        parseDateTime = parseDateTime.monthOfYear().withMaximumValue();
    }
    if (parseDateTime.dayOfMonth().get() == parseDateTime.dayOfMonth().getMinimumValue()) {
        parseDateTime = parseDateTime.dayOfMonth().withMaximumValue();
    }
    if (parseDateTime.hourOfDay().get() == parseDateTime.hourOfDay().getMinimumValue()) {
        parseDateTime = parseDateTime.hourOfDay().withMaximumValue();
    }
    if (parseDateTime.minuteOfHour().get() == parseDateTime.minuteOfHour().getMinimumValue()) {
        parseDateTime = parseDateTime.minuteOfHour().withMaximumValue();
    }
    if (parseDateTime.secondOfMinute().get() == parseDateTime.secondOfMinute().getMinimumValue()) {
        parseDateTime = parseDateTime.secondOfMinute().withMaximumValue();
    }
    if (parseDateTime.millisOfSecond().get() == parseDateTime.millisOfSecond().getMinimumValue()) {
        parseDateTime = parseDateTime.millisOfSecond().withMaximumValue();
    }
    return parseDateTime;
}

From source file:org.kuali.kpme.tklm.utils.TkTestUtils.java

License:Educational Community License

public static Map<DateTime, BigDecimal> getDateToHoursMap(TimeBlock timeBlock, TimeHourDetail timeHourDetail) {
    Map<DateTime, BigDecimal> dateToHoursMap = new HashMap<DateTime, BigDecimal>();
    DateTime beginTime = timeBlock.getBeginDateTime();
    DateTime endTime = timeBlock.getEndDateTime();

    Days d = Days.daysBetween(beginTime, endTime);
    int numberOfDays = d.getDays();
    if (numberOfDays < 1) {
        dateToHoursMap.put(timeBlock.getBeginDateTime(), timeHourDetail.getHours());
        return dateToHoursMap;
    }/*from ww w .  ja  v a2 s  . c o  m*/
    DateTime currentTime = beginTime;
    for (int i = 0; i < numberOfDays; i++) {
        DateTime nextDayAtMidnight = currentTime.plusDays(1);
        nextDayAtMidnight = nextDayAtMidnight.hourOfDay().setCopy(12);
        nextDayAtMidnight = nextDayAtMidnight.minuteOfDay().setCopy(0);
        nextDayAtMidnight = nextDayAtMidnight.secondOfDay().setCopy(0);
        nextDayAtMidnight = nextDayAtMidnight.millisOfSecond().setCopy(0);
        Duration dur = new Duration(currentTime, nextDayAtMidnight);
        long duration = dur.getStandardSeconds();
        BigDecimal hrs = new BigDecimal(duration / 3600, HrConstants.MATH_CONTEXT);
        dateToHoursMap.put(currentTime, hrs);
        currentTime = nextDayAtMidnight;
    }
    Duration dur = new Duration(currentTime, endTime);
    long duration = dur.getStandardSeconds();
    BigDecimal hrs = new BigDecimal(duration / 3600, HrConstants.MATH_CONTEXT);
    dateToHoursMap.put(currentTime, hrs);

    return dateToHoursMap;
}

From source file:org.nekorp.workflow.backend.service.reporte.global.RenglonFactoryRG.java

License:Apache License

@Override
public RenglonRG build(Servicio data) {
    RenglonRG r = new RenglonRG();
    r.setDatosAuto(factoryAuto.build(data));
    r.setDatosBitacora(factoryBitacora.build(data));
    r.setDatosCliente(factoryCliente.build(data));
    r.setDatosCosto(factoryCosto.build(data));
    r.setDatosServicio(factoryServicio.build(data));
    Date entradaAutoRaw = r.getDatosBitacora().getFechaIngresoAuto();
    if (entradaAutoRaw != null) {
        DateTime entradaAuto = new DateTime(entradaAutoRaw);
        entradaAuto = new DateTime(entradaAuto.getYear(), entradaAuto.getMonthOfYear(),
                entradaAuto.getDayOfMonth(), entradaAuto.hourOfDay().getMinimumValue(),
                entradaAuto.minuteOfHour().getMinimumValue(), entradaAuto.secondOfMinute().getMinimumValue(),
                entradaAuto.millisOfSecond().getMinimumValue(), entradaAuto.getZone());
        DateTime iniServ = new DateTime(data.getMetadata().getFechaInicio());
        iniServ = new DateTime(iniServ.getYear(), iniServ.getMonthOfYear(), iniServ.getDayOfMonth(),
                iniServ.hourOfDay().getMinimumValue(), iniServ.minuteOfHour().getMinimumValue(),
                iniServ.secondOfMinute().getMinimumValue(), iniServ.millisOfSecond().getMinimumValue(),
                iniServ.getZone());// w  w w.j  av a2s  . c  o  m
        if (iniServ.isBefore(entradaAuto)) {
            r.getDatosServicio().setProgramado("X");
        }
    }
    return r;
}

From source file:org.nekorp.workflow.desktop.view.AppLayoutView.java

License:Apache License

private void reporteGlobalButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_reporteGlobalButtonActionPerformed
    try {/*  w  ww.  j  a  v a2s.  c  om*/
        parametrosReporteGlobal.setFechaInicial(new Date());
        parametrosReporteGlobal.setFechaFinal(new Date());
        parametrosReporteGlobalDialogFactory.createDialog(mainFrame, true).setVisible(true);
        if (parametrosReporteGlobal.isEjecutar()) {
            JFileChooser chooser = new JFileChooser();
            FileNameExtensionFilter filter = new FileNameExtensionFilter("Hojas de clculo", "xlsx");
            chooser.setFileFilter(filter);
            String homePath = System.getProperty("user.home");
            File f = new File(new File(homePath + "/Reporte-Global" + ".xlsx").getCanonicalPath());
            chooser.setSelectedFile(f);
            int returnVal = chooser.showSaveDialog(this.mainFrame);
            if (returnVal == JFileChooser.APPROVE_OPTION) {
                this.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
                ParametrosReporteGlobal param = new ParametrosReporteGlobal();
                param.setDestination(chooser.getSelectedFile());
                DateTime fechaInicial = new DateTime(parametrosReporteGlobal.getFechaInicial());
                DateTime fechaFinal = new DateTime(parametrosReporteGlobal.getFechaFinal());
                fechaFinal = new DateTime(fechaFinal.getYear(), fechaFinal.getMonthOfYear(),
                        fechaFinal.getDayOfMonth(), fechaFinal.hourOfDay().getMaximumValue(),
                        fechaFinal.minuteOfHour().getMaximumValue(),
                        fechaFinal.secondOfMinute().getMaximumValue(),
                        fechaFinal.millisOfSecond().getMaximumValue(), fechaFinal.getZone());
                param.setFechaInicial(fechaInicial);
                param.setFechaFinal(fechaFinal);
                this.aplication.generaReporteGlobal(param);
            }
        }
    } catch (IOException ex) {
        AppLayoutView.LOGGER.error("Exploto al tratar de generar el reporte global", ex);
    } finally {
        this.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.DEFAULT_CURSOR));
    }
}

From source file:org.powertac.hamweather.XmlOutputStructure.java

License:Apache License

private boolean timeToStart(DateTime current) {
    if (null == batchStartHour)
        return true;
    int hour = current.hourOfDay().get();
    if (current.minuteOfHour().get() >= 30)
        hour += 1;/*from w w  w  .j  a va 2 s .  co m*/
    if (hour == batchStartHour)
        return true;
    return false;
}