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.mythtv.client.ui.dvr.GuideTimeslotsFragment.java

License:Open Source License

public void updateTimeslot(DateTime date) {

    startingTimeslot = hourTimeslots.get(date.getHourOfDay());

    if (date.getMinuteOfHour() > 30) {
        startingTimeslot++;/*from   w w w.  j av a2 s . c  o m*/
    }

    scrollTimeslot();

}

From source file:org.neotree.ui.view.DateTimeFieldView.java

License:Open Source License

@OnClick(R.id.field_time_button)
public void onTimeFieldClick() {
    DateTime pickerTime = (getValue() != null) ? getValue() : DateTime.now();
    TimePickerDialog picker = TimePickerDialog.newInstance(this, pickerTime.getHourOfDay(),
            pickerTime.getMinuteOfHour(), DateFormat.is24HourFormat(getContext()));
    picker.dismissOnPause(true);/*from  w w  w .j  av  a2 s.co  m*/
    picker.vibrate(false);
    picker.show(((Activity) getContext()).getFragmentManager(), "NTTimePickerDialog");
}

From source file:org.numenta.nupic.encoders.DateEncoder.java

License:Open Source License

/**
 * Returns an {@link TDoubleList} containing the sub-field scalar value(s) for
 * each sub-field of the inputData. To get the associated field names for each of
 * the scalar values, call getScalarNames().
 *
 * @param inputData   the input value, in this case a date object
 * @return   a list of one input double/*from   w w  w .  ja va 2 s .c o m*/
 */
public TDoubleList getScalars(DateTime inputData) {
    if (inputData == null) {
        throw new IllegalArgumentException("DateEncoder requires a valid Date object but got null");
    }

    TDoubleList values = new TDoubleArrayList();

    //Get the scalar values for each sub-field

    double timeOfDay = inputData.getHourOfDay() + inputData.getMinuteOfHour() / 60.0;

    // The day of week was 1 based, so convert to 0 based
    int dayOfWeek = inputData.getDayOfWeek() - 1; // + timeOfDay / 24.0

    if (seasonEncoder != null) {
        // The day of year was 1 based, so convert to 0 based
        double dayOfYear = inputData.getDayOfYear() - 1;
        values.add(dayOfYear);
    }

    if (dayOfWeekEncoder != null) {
        values.add(dayOfWeek);
    }

    if (weekendEncoder != null) {

        //saturday, sunday or friday evening
        boolean isWeekend = dayOfWeek == 6 || dayOfWeek == 5 || (dayOfWeek == 4 && timeOfDay > 18);

        int weekend = isWeekend ? 1 : 0;

        values.add(weekend);
    }

    if (customDaysEncoder != null) {
        boolean isCustomDays = customDaysList.contains(dayOfWeek);

        int customDay = isCustomDays ? 1 : 0;

        values.add(customDay);
    }

    if (holidayEncoder != null) {
        // A "continuous" binary value. = 1 on the holiday itself and smooth ramp
        //  0->1 on the day before the holiday and 1->0 on the day after the holiday.

        double holidayness = 0;

        for (Tuple h : holidaysList) {
            //hdate is midnight on the holiday
            DateTime hdate = new DateTime(inputData.getYear(), (int) h.get(0), (int) h.get(1), 0, 0, 0);

            if (inputData.isAfter(hdate)) {
                Duration diff = new Interval(hdate, inputData).toDuration();
                long days = diff.getStandardDays();
                if (days == 0) {
                    //return 1 on the holiday itself
                    holidayness = 1;
                    break;
                } else if (days == 1) {
                    //ramp smoothly from 1 -> 0 on the next day
                    holidayness = 1.0 - ((diff.getStandardSeconds() - 86400.0 * days) / 86400.0);
                    break;
                }

            } else {
                //TODO This is not the same as when date.isAfter(hdate), why?
                Duration diff = new Interval(inputData, hdate).toDuration();
                long days = diff.getStandardDays();
                if (days == 0) {
                    //ramp smoothly from 0 -> 1 on the previous day
                    holidayness = 1.0 - ((diff.getStandardSeconds() - 86400.0 * days) / 86400.0);
                    //TODO Why no break?
                }
            }
        }

        values.add(holidayness);
    }

    if (timeOfDayEncoder != null) {
        values.add(timeOfDay);
    }

    return values;
}

From source file:org.odk.collect.android.widgets.DateTimeWidgettext.java

License:Apache License

private void setAnswer() {

    if (mPrompt.getAnswerValue() != null) {

        DateTime ldt = new DateTime(((Date) ((DateTimeData) mPrompt.getAnswerValue()).getValue()).getTime());
        mDatePicker.init(ldt.getYear(), ldt.getMonthOfYear() - 1, ldt.getDayOfMonth(), mDateListener);
        mTimePicker.setCurrentHour(ldt.getHourOfDay());
        mTimePicker.setCurrentMinute(ldt.getMinuteOfHour());
        textofwidget.setText(String.valueOf(ldt.getDayOfMonth()) + "/"
                + String.valueOf(ldt.getMonthOfYear() - 1) + "/" + String.valueOf((ldt.getYear())));
    } else {//from www . ja v  a  2s .c o  m
        // create time widget with current time as of right now
        clearAnswer();
    }
}

From source file:org.onebusaway.admin.util.VehicleStatusBuilder.java

License:Apache License

private String extractTime(String date) {
    DateTimeFormatter formatter = ISODateTimeFormat.dateTimeNoMillis();
    DateTime dateTime = formatter.parseDateTime(date);
    int hour = dateTime.getHourOfDay();
    String formattedHour = String.format("%02d", hour);
    int minute = dateTime.getMinuteOfHour();
    String formattedMinute = String.format("%02d", minute);
    return formattedHour + ":" + formattedMinute;
}

From source file:org.opencastproject.index.service.catalog.adapter.DublinCoreMetadataUtil.java

License:Educational Community License

/**
 * Gets the current hour, minute and second from a dublin core period if available.
 *
 * @param period/*  www.  ja  v  a 2  s  .  co m*/
 *          The current period from dublin core.
 * @return A new DateTime with the current hour, minute and second.
 */
static DateTime getCurrentStartTime(Opt<DCMIPeriod> period) {
    DateTime currentStartTime = new DateTime();
    currentStartTime = currentStartTime.withZone(DateTimeZone.UTC);
    currentStartTime = currentStartTime.withHourOfDay(0);
    currentStartTime = currentStartTime.withMinuteOfHour(0);
    currentStartTime = currentStartTime.withSecondOfMinute(0);

    if (period.isSome() && period.get().hasStart()) {
        DateTime fromDC = new DateTime(period.get().getStart().getTime());
        fromDC = fromDC.withZone(DateTimeZone.UTC);
        currentStartTime = currentStartTime.withZone(DateTimeZone.UTC);
        currentStartTime = currentStartTime.withHourOfDay(fromDC.getHourOfDay());
        currentStartTime = currentStartTime.withMinuteOfHour(fromDC.getMinuteOfHour());
        currentStartTime = currentStartTime.withSecondOfMinute(fromDC.getSecondOfMinute());
    }
    return currentStartTime;
}

From source file:org.opencastproject.index.service.catalog.adapter.DublinCoreMetadataUtil.java

License:Educational Community License

/**
 * Sets the start date in a dublin core catalog to the right value and keeps the start time and duration the same.
 *
 * @param dc//ww  w  .  j ava  2 s.c  om
 *          The dublin core catalog to adjust
 * @param field
 *          The metadata field that contains the start date.
 * @param ename
 *          The EName in the catalog to identify the property that has the dublin core period.
 */
static void setTemporalStartDate(DublinCoreCatalog dc, MetadataField<?> field, EName ename) {
    if (field.getValue().isNone() || (field.getValue().get() instanceof String
            && StringUtils.isBlank(field.getValue().get().toString()))) {
        logger.debug("No value was set for metadata field with dublin core id '{}' and json id '{}'",
                field.getInputID(), field.getOutputID());
        return;
    }
    try {
        // Get the current date
        SimpleDateFormat dateFormat = MetadataField.getSimpleDateFormatter(field.getPattern().get());
        Date startDate = dateFormat.parse((String) field.getValue().get());
        // Get the current period
        Opt<DCMIPeriod> period = getPeriodFromCatalog(dc, ename);
        // Get the current duration
        Long duration = getDuration(period);
        // Get the current start time hours, minutes and seconds
        DateTime currentStartTime = getCurrentStartTime(period);
        // Setup the new start time
        DateTime startDateTime = new DateTime(startDate.getTime());
        startDateTime = startDateTime.withZone(DateTimeZone.UTC);
        startDateTime = startDateTime.withHourOfDay(currentStartTime.getHourOfDay());
        startDateTime = startDateTime.withMinuteOfHour(currentStartTime.getMinuteOfHour());
        startDateTime = startDateTime.withSecondOfMinute(currentStartTime.getSecondOfMinute());
        // Get the current end date based on new date and duration.
        DateTime endDate = new DateTime(startDateTime.toDate().getTime() + duration);
        dc.set(ename, EncodingSchemeUtils.encodePeriod(new DCMIPeriod(startDateTime.toDate(), endDate.toDate()),
                Precision.Second));
    } catch (ParseException e) {
        logger.error("Not able to parse date {} to update the dublin core because: {}", field.getValue(),
                ExceptionUtils.getStackTrace(e));
    }
}

From source file:org.opencastproject.index.service.catalog.adapter.DublinCoreMetadataUtil.java

License:Educational Community License

/**
 * Gets the current hour, minute and second from a dublin core period if available.
 *
 * @param period// www.  ja v a2  s .  c  o m
 *          The current period from dublin core.
 * @return A new DateTime with the current hour, minute and second.
 */
private static DateTime getCurrentStartDateTime(Opt<DCMIPeriod> period) {
    DateTime currentStartTime = new DateTime();
    currentStartTime = currentStartTime.withZone(DateTimeZone.UTC);
    currentStartTime = currentStartTime.withYear(2001);
    currentStartTime = currentStartTime.withMonthOfYear(1);
    currentStartTime = currentStartTime.withDayOfMonth(1);
    currentStartTime = currentStartTime.withHourOfDay(0);
    currentStartTime = currentStartTime.withMinuteOfHour(0);
    currentStartTime = currentStartTime.withSecondOfMinute(0);

    if (period.isSome() && period.get().hasStart()) {
        DateTime fromDC = new DateTime(period.get().getStart().getTime());
        fromDC = fromDC.withZone(DateTimeZone.UTC);
        currentStartTime = currentStartTime.withZone(DateTimeZone.UTC);
        currentStartTime = currentStartTime.withYear(fromDC.getYear());
        currentStartTime = currentStartTime.withMonthOfYear(fromDC.getMonthOfYear());
        currentStartTime = currentStartTime.withDayOfMonth(fromDC.getDayOfMonth());
        currentStartTime = currentStartTime.withHourOfDay(fromDC.getHourOfDay());
        currentStartTime = currentStartTime.withMinuteOfHour(fromDC.getMinuteOfHour());
        currentStartTime = currentStartTime.withSecondOfMinute(fromDC.getSecondOfMinute());
    }
    return currentStartTime;
}

From source file:org.openehr.rm.datatypes.quantity.datetime.DvDateTimeParser.java

License:LGPL

public static DateTime defaultTime() {
    DateTime time = new DateTime();
    return new DateTime(1970, 1, 1, time.getHourOfDay(), time.getMinuteOfHour(), time.getSecondOfMinute(),
            time.getMillisOfSecond());/* w  w w. j ava2 s. c  o  m*/
}

From source file:org.openehr.rm.datatypes.quantity.datetime.DvTime.java

License:LGPL

/**
 * Parses a string value and return a DvTime
 *//*from w w w.j  ava  2  s.  co m*/
public DvTime parse(String value) {
    DateTime time = DvDateTimeParser.parseTime(value);
    return new DvTime(time.getHourOfDay(), time.getMinuteOfHour(), time.getSecondOfMinute(),
            time.getMillisOfSecond(), time.getZone().toTimeZone());
}