Example usage for org.joda.time DateTime getMinuteOfHour

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

Introduction

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

Prototype

public int getMinuteOfHour() 

Source Link

Document

Get the minute of hour field value.

Usage

From source file:org.kalypso.ui.rrm.internal.calccase.CatchmentModelHelper.java

License:Open Source License

private static DateRange modifyWithTimestamp(final LocalTime timestamp, final DateTime simulationStart,
        final DateTime simulationEnd) {
    /* Nothing to do. */
    if (timestamp == null)
        return new DateRange(simulationStart.toDate(), simulationEnd.toDate());

    /* Convert to a date with the kalypso timezone. */
    /* The date fields are ignored. */
    final DateTime timestampUTC = timestamp
            .toDateTimeToday(DateTimeZone.forTimeZone(TimeZone.getTimeZone("UTC"))); //$NON-NLS-1$
    final DateTime timestampDate = new DateTime(timestampUTC.toDate(),
            DateTimeZone.forTimeZone(KalypsoCorePlugin.getDefault().getTimeZone()));

    /* Further adjust range by predefined time. */
    final DateTime startWithTime = simulationStart.withTime(timestampDate.getHourOfDay(),
            timestampDate.getMinuteOfHour(), timestampDate.getSecondOfMinute(),
            timestampDate.getMillisOfSecond());
    final DateTime endWithTime = simulationEnd.withTime(timestampDate.getHourOfDay(),
            timestampDate.getMinuteOfHour(), timestampDate.getSecondOfMinute(),
            timestampDate.getMillisOfSecond());

    return new DateRange(startWithTime.toDate(), endWithTime.toDate());
}

From source file:org.kalypso.ui.rrm.internal.calccase.CatchmentModelHelper.java

License:Open Source License

/**
 * This function calculates the range for the timeseries to be generated. The range equals the range defined in the
 * simulation adjusted as follows:/*  w w  w  .  j  a  v  a 2  s. c  o m*/
 * <ul>
 * <li>1 timestep earlier</li>
 * <li>3 timesteps later</li>
 * </ul>
 *
 * @param control
 *          The na control.
 * @param timestep
 *          The timestep.
 * @param timestamp
 *          The timestamp in UTC.
 * @return The date range.
 */
public static DateRange getRange(final NAControl control, final Period timestep, final LocalTime timestamp) {
    final Date simulationStart = control.getSimulationStart();
    final Date simulationEnd = control.getSimulationEnd();

    final DateTime start = new DateTime(simulationStart);
    final DateTime end = new DateTime(simulationEnd);

    final DateTime adjustedStart = start.minus(timestep);
    final DateTime adjustedEnd = end.plus(timestep).plus(timestep).plus(timestep);

    if (timestep.getDays() == 0 || timestamp == null)
        return new DateRange(adjustedStart.toDate(), adjustedEnd.toDate());

    /* Convert to a date with the kalypso timezone. */
    /* The date fields are ignored. */
    final DateTime timestampUTC = timestamp
            .toDateTimeToday(DateTimeZone.forTimeZone(TimeZone.getTimeZone("UTC"))); //$NON-NLS-1$
    final DateTime timestampDate = new DateTime(timestampUTC.toDate(),
            DateTimeZone.forTimeZone(KalypsoCorePlugin.getDefault().getTimeZone()));

    /* Further adjust range by predefined time. */
    final DateTime startWithTime = adjustedStart.withTime(timestampDate.getHourOfDay(),
            timestampDate.getMinuteOfHour(), timestampDate.getSecondOfMinute(),
            timestampDate.getMillisOfSecond());
    final DateTime endWithTime = adjustedEnd.withTime(timestampDate.getHourOfDay(),
            timestampDate.getMinuteOfHour(), timestampDate.getSecondOfMinute(),
            timestampDate.getMillisOfSecond());

    /* New start must always be before unadjusted start, fix, if this is not the case. */
    DateTime startWithTimeFixed;
    if (startWithTime.isAfter(adjustedStart))
        startWithTimeFixed = startWithTime.minus(timestep);
    else
        startWithTimeFixed = startWithTime;

    /* New end must always be after unadjusted end, fix, if this is not the case. */
    DateTime endWithTimeFixed;
    if (endWithTime.isBefore(adjustedEnd))
        endWithTimeFixed = endWithTime.plus(timestep);
    else
        endWithTimeFixed = endWithTime;

    return new DateRange(startWithTimeFixed.toDate(), endWithTimeFixed.toDate());

}

From source file:org.kitesdk.apps.examples.report.ScheduledReportJob.java

License:Apache License

public void run() {

    // TODO: Switch to parameterized views.
    View<ExampleEvent> view = Datasets.load(ScheduledReportApp.EXAMPLE_DS_URI, ExampleEvent.class);

    RefinableView<GenericRecord> target = Datasets.load(ScheduledReportApp.REPORT_DS_URI, GenericRecord.class);

    // Get the view into which this report will be written.
    DateTime dateTime = getNominalTime().toDateTime(DateTimeZone.UTC);

    View<GenericRecord> output = target.with("year", dateTime.getYear())
            .with("month", dateTime.getMonthOfYear()).with("day", dateTime.getDayOfMonth())
            .with("hour", dateTime.getHourOfDay()).with("minute", dateTime.getMinuteOfHour());

    Pipeline pipeline = getPipeline();//w w  w.  j av a  2  s .c  om

    PCollection<ExampleEvent> events = pipeline.read(CrunchDatasets.asSource(view));

    PTable<Long, ExampleEvent> eventsByUser = events.by(new GetEventId(), Avros.longs());

    // Count of events by user ID.
    PTable<Long, Long> userEventCounts = eventsByUser.keys().count();

    PCollection<GenericData.Record> report = userEventCounts.parallelDo(new ToUserReport(),
            Avros.generics(SCHEMA));

    pipeline.write(report, CrunchDatasets.asTarget(output));

    pipeline.run();
}

From source file:org.kitesdk.apps.spi.oozie.CronConverter.java

License:Apache License

public static Instant nextInstant(String cronSchedule, Instant current) {

    DateTime currentTime = new DateTime(current, DateTimeZone.UTC).withSecondOfMinute(0).withMillisOfSecond(0);

    validate(cronSchedule);/*from  w w  w  .j  av  a  2  s.com*/

    String[] splits = cronSchedule.split(" ");

    String minutePart = splits[0];
    String hourPart = splits[1];
    String dayPart = splits[2];

    // TODO: fold these together like the hour.
    if (isWildCard(minutePart)) {
        return currentTime.plusMinutes(1).toInstant();
    }

    if (isInterval(minutePart)) {

        // Roll minutes forward until we hit a start time
        // that matches the cron interval.
        int interval = getInterval(minutePart);

        DateTime next = currentTime.withSecondOfMinute(0).plusMinutes(1);

        while (!(next.getMinuteOfHour() % interval == 0)) {

            next = next.plusMinutes(1);
        }

        return next.toInstant();
    }

    assert (isConstant(minutePart));

    // The minute part must be a constant, so
    // simply get the value.
    int minute = Integer.parseInt(minutePart);

    // The schedule is based on hours.
    if (!isConstant(hourPart)) {

        int hourModulus = isWildCard(hourPart) ? 1 : getInterval(hourPart);

        DateTime next = currentTime.withMinuteOfHour(minute);

        while (next.isBefore(current) || !(next.getHourOfDay() % hourModulus == 0)) {

            next = next.plusHours(1);
        }

        return next.toInstant();
    }

    int hour = Integer.parseInt(hourPart);

    // The schedule is based on days, and therfore the day cannot
    // be a constant. This is is checked in validation as well.
    assert (!isConstant(dayPart));

    DateTime next = currentTime.withMinuteOfHour(minute).withHourOfDay(hour);

    while (next.isBefore(current)) {

        next = next.plusDays(1);
    }

    return next.toInstant();
}

From source file:org.kuali.kpme.core.util.TKUtils.java

License:Educational Community License

public static boolean isVirtualWorkDay(DateTime beginPeriodDateTime) {
    return (beginPeriodDateTime.getHourOfDay() != 0 || beginPeriodDateTime.getMinuteOfHour() != 0
            && beginPeriodDateTime.get(DateTimeFieldType.halfdayOfDay()) != DateTimeConstants.AM);
}

From source file:org.kuali.kpme.tklm.time.rules.graceperiod.service.GracePeriodServiceImpl.java

License:Educational Community License

public DateTime processGracePeriodRule(DateTime actualDateTime, LocalDate asOfDate) {
    DateTime gracePeriodDateTime = actualDateTime;

    GracePeriodRule gracePeriodRule = getGracePeriodRule(asOfDate);
    if (gracePeriodRule != null) {
        //go ahead and round off seconds
        gracePeriodDateTime = gracePeriodDateTime.withSecondOfMinute(0);

        BigDecimal minuteIncrement = gracePeriodRule.getHourFactor();
        BigDecimal minutes = new BigDecimal(gracePeriodDateTime.getMinuteOfHour());
        int bottomIntervalFactor = minutes.divide(minuteIncrement, 0, BigDecimal.ROUND_FLOOR).intValue();
        BigDecimal bottomInterval = new BigDecimal(bottomIntervalFactor).multiply(minuteIncrement);
        BigDecimal topInterval = new BigDecimal(bottomIntervalFactor + 1).multiply(minuteIncrement);
        if (bottomInterval.subtract(minutes).abs().intValue() < topInterval.subtract(minutes).abs()
                .intValue()) {//from w w w .j a  v  a 2 s. c om
            gracePeriodDateTime = gracePeriodDateTime
                    .withMinuteOfHour(bottomInterval.setScale(0, BigDecimal.ROUND_HALF_UP).intValue());
        } else {
            if (topInterval.equals(new BigDecimal(60))) {
                gracePeriodDateTime = gracePeriodDateTime.withHourOfDay(gracePeriodDateTime.getHourOfDay() + 1)
                        .withMinuteOfHour(0);
            } else {
                gracePeriodDateTime = gracePeriodDateTime
                        .withMinuteOfHour(topInterval.setScale(0, BigDecimal.ROUND_HALF_UP).intValue());
            }
        }
    }
    return gracePeriodDateTime;
}

From source file:org.mamasdelrio.android.widgets.TimeWidget.java

License:Apache License

public TimeWidget(Context context, final FormEntryPrompt prompt) {
    super(context, prompt);

    mTimePicker = new TimePicker(getContext());
    mTimePicker.setId(QuestionWidget.newUniqueId());
    mTimePicker.setFocusable(!prompt.isReadOnly());
    mTimePicker.setEnabled(!prompt.isReadOnly());

    String clockType = android.provider.Settings.System.getString(context.getContentResolver(),
            android.provider.Settings.System.TIME_12_24);
    if (clockType == null || clockType.equalsIgnoreCase("24")) {
        mTimePicker.setIs24HourView(true);
    }/*  w  w  w  .  j  a  v a  2s  .c om*/

    // If there's an answer, use it.
    if (prompt.getAnswerValue() != null) {

        // create a new date time from date object using default time zone
        DateTime ldt = new DateTime(((Date) ((TimeData) prompt.getAnswerValue()).getValue()).getTime());
        System.out.println("retrieving:" + ldt);

        mTimePicker.setCurrentHour(ldt.getHourOfDay());
        mTimePicker.setCurrentMinute(ldt.getMinuteOfHour());

    } else {
        // create time widget with current time as of right now
        clearAnswer();
    }

    mTimePicker.setOnTimeChangedListener(new TimePicker.OnTimeChangedListener() {
        @Override
        public void onTimeChanged(TimePicker view, int hourOfDay, int minute) {
            Collect.getInstance().getActivityLogger().logInstanceAction(TimeWidget.this, "onTimeChanged",
                    String.format("%1$02d:%2$02d", hourOfDay, minute), mPrompt.getIndex());
        }
    });

    setGravity(Gravity.LEFT);
    addAnswerView(mTimePicker);

}

From source file:org.mongoste.util.DateUtil.java

License:Open Source License

public static DateTime toUTC(DateTime fromDate) {
    if (DateTimeZone.UTC.equals(fromDate.getZone())) {
        return fromDate;
    }// ww w .  j  a v a2s .c o  m
    MutableDateTime dt = getDateTimeUTC().toMutableDateTime();
    dt.setDateTime(fromDate.getYear(), fromDate.getMonthOfYear(), fromDate.getDayOfMonth(),
            fromDate.getHourOfDay(), fromDate.getMinuteOfHour(), fromDate.getSecondOfMinute(),
            fromDate.getMillisOfSecond());
    return dt.toDateTime();
}

From source file:org.mrgeo.featurefilter.DateColumnFeatureFilter.java

License:Apache License

private boolean datePassesFilter(DateTime date, DateTime filter) {
    return ((dateFilterGranularity.equals(DateGranularity.AFTER) && date.isAfter(filter))
            || (dateFilterGranularity.equals(DateGranularity.BEFORE) && date.isBefore(filter))
            || (dateFilterGranularity.equals(DateGranularity.SAME_INSTANT) && filter.isEqual(date))
            || (dateFilterGranularity.equals(DateGranularity.WITHIN_A_MINUTE)
                    && (Minutes.minutesBetween(filter, date).getMinutes() == 0))
            || (dateFilterGranularity.equals(DateGranularity.WITHIN_AN_HOUR)
                    && (Hours.hoursBetween(filter, date).getHours() == 0))
            || (dateFilterGranularity.equals(DateGranularity.WITHIN_A_DAY)
                    && (Days.daysBetween(filter, date).getDays() == 0))
            || (dateFilterGranularity.equals(DateGranularity.WITHIN_A_MONTH)
                    && (Months.monthsBetween(filter, date).getMonths() == 0))
            || (dateFilterGranularity.equals(DateGranularity.WITHIN_A_YEAR)
                    && (Years.yearsBetween(filter, date).getYears() == 0))
            || (dateFilterGranularity.equals(DateGranularity.SAME_MINUTE_OF_ANY_HOUR)
                    && (date.getMinuteOfHour() == filter.getMinuteOfHour()))
            || (dateFilterGranularity.equals(DateGranularity.SAME_HOUR_OF_ANY_DAY)
                    && (date.getHourOfDay() == filter.getHourOfDay()))
            || (dateFilterGranularity.equals(DateGranularity.SAME_DAY_OF_ANY_WEEK)
                    && (date.getDayOfWeek() == filter.getDayOfWeek()))
            || (dateFilterGranularity.equals(DateGranularity.SAME_DAY_OF_ANY_MONTH)
                    && (date.getDayOfMonth() == filter.getDayOfMonth()))
            ||//from w  ww . j  ava2 s  .  c  o  m
            //date.getDayOfYear isn't sufficient here, b/c leap years have a different number of days
            (dateFilterGranularity.equals(DateGranularity.SAME_DAY_OF_ANY_YEAR)
                    && ((date.getDayOfMonth() == filter.getDayOfMonth())
                            && (date.getMonthOfYear() == filter.getMonthOfYear())))
            || (dateFilterGranularity.equals(DateGranularity.SAME_MONTH_OF_ANY_YEAR)
                    && (date.getMonthOfYear() == filter.getMonthOfYear())));
}

From source file:org.mythtv.client.ui.dvr.GuideTimeslotsFragment.java

License:Open Source License

/**
 * //from  w w  w  .jav  a  2 s  . com
 */
public GuideTimeslotsFragment() {
    Log.v(TAG, "initialize : enter");

    DateTime now = new DateTime(System.currentTimeMillis());
    startingTimeslot = hourTimeslots.get(now.getHourOfDay());

    if (now.getMinuteOfHour() > 30) {
        startingTimeslot++;
    }
    Log.v(TAG, "initialize : startingTimeslot=" + startingTimeslot);

    Log.v(TAG, "initialize : exit");
}