Example usage for org.joda.time DateTime getHourOfDay

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

Introduction

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

Prototype

public int getHourOfDay() 

Source Link

Document

Get the hour of day field value.

Usage

From source file:kr.debop4j.timeperiod.tools.Times.java

License:Apache License

/**
 * ? ?? (Hour)   true  false ./*from w  ww  . j  ava  2  s .  co  m*/
 *
 * @param left  the left
 * @param right the right
 * @return the boolean
 */
public static boolean isSameHour(DateTime left, DateTime right) {
    return isSameDay(left, right) && left.getHourOfDay() == right.getHourOfDay();
}

From source file:kr.debop4j.timeperiod.tools.Times.java

License:Apache License

/**
 * Sets minute./*from w  w w  . j av a2 s.c  o  m*/
 *
 * @param moment       the moment
 * @param minuteOfHour the minute of hour
 * @return the minute
 */
public static DateTime setMinute(DateTime moment, int minuteOfHour) {
    return setTime(moment, moment.getHourOfDay(), minuteOfHour, moment.getSecondOfMinute(),
            moment.getMillisOfSecond());
}

From source file:kr.debop4j.timeperiod.tools.Times.java

License:Apache License

/**
 * Sets second./*from   w  w w.j a va 2 s  . c  om*/
 *
 * @param moment         the moment
 * @param secondOfMinute the second of minute
 * @return the second
 */
public static DateTime setSecond(DateTime moment, int secondOfMinute) {
    return setTime(moment, moment.getHourOfDay(), moment.getMinuteOfHour(), secondOfMinute,
            moment.getMillisOfSecond());
}

From source file:kr.debop4j.timeperiod.tools.Times.java

License:Apache License

/**
 * Sets millisecond./*from  ww  w .j  a  v a2 s.  c  o  m*/
 *
 * @param moment         the moment
 * @param millisOfSecond the millis of second
 * @return the millisecond
 */
public static DateTime setMillisecond(DateTime moment, int millisOfSecond) {
    return setTime(moment, moment.getHourOfDay(), moment.getMinuteOfHour(), moment.getSecondOfMinute(),
            millisOfSecond);
}

From source file:kr.debop4j.timeperiod.tools.Times.java

License:Apache License

/**
 * Trim to minute.//www . j a v  a2s  .  c  o m
 *
 * @param moment       the moment
 * @param minuteOfHour the minute of hour
 * @return the date time
 */
public static DateTime trimToMinute(DateTime moment, int minuteOfHour) {
    return trimToHour(moment, moment.getHourOfDay()).withMinuteOfHour(minuteOfHour);
}

From source file:kr.debop4j.timeperiod.tools.Times.java

License:Apache License

/**  ? (Hour)  . */
public static List<ITimePeriod> foreachHours(ITimePeriod period) {
    shouldNotBeNull(period, "period");

    if (isTraceEnabled)
        log.trace("[{}]?  (Hour)  ...", period);

    List<ITimePeriod> hours = Lists.newArrayList();
    if (period.isAnytime())
        return hours;

    assertHasPeriod(period);/*w w  w. jav a2 s . c  o m*/

    if (Times.isSameHour(period.getStart(), period.getEnd())) {
        hours.add(new TimeRange(period));
        return hours;
    }

    hours.add(new TimeRange(period.getStart(), Times.endTimeOfHour(period.getStart())));

    DateTime endHour = period.getEnd();
    DateTime current = Times.trimToHour(period.getStart(), period.getStart().getHourOfDay() + 1);
    ITimeCalendar calendar = TimeCalendar.getDefault();

    DateTime maxHour = endHour.minusHours(1);
    while (current.compareTo(maxHour) <= 0) {
        hours.add(Times.getHourRange(current, calendar));
        current = current.plusHours(1);
    }

    if (endHour.minusHours(endHour.getHourOfDay()).getMillisOfDay() > 0) {
        hours.add(new TimeRange(Times.startTimeOfHour(endHour), endHour));
    }

    return hours;
}

From source file:li.klass.fhem.adapter.devices.core.generic.detail.actions.devices.fht.HolidayShort.java

License:Open Source License

public void showDialog(final Context context, final ViewGroup parent, final LayoutInflater layoutInflater,
        final SpinnerActionRow spinnerActionRow, final XmlListDevice device, final Intent switchIntent) {
    final DateTime now = dateService.now();
    final TableLayout contentView = (TableLayout) handleColorStateBug(new AndroidBug.BugHandler() {
        @Override//from w w  w .  j ava  2 s .  c  o m
        public View bugEncountered() {
            final TableLayout contentView = (TableLayout) layoutInflater
                    .inflate(R.layout.fht_holiday_short_dialog_android_bug, parent, false);

            final FallbackTimePicker timePicker = (FallbackTimePicker) contentView
                    .findViewById(R.id.timePicker);
            timePicker.setMinutes(0);
            timePicker.setHours(now.getHourOfDay());

            timePicker.setOnValueChangedListener(new FallbackTimePicker.OnValueChangedListener() {
                @Override
                public void onValueChanged(int hours, int minutes) {
                    HolidayShort.this.hour = hours;
                    HolidayShort.this.minute = minutes;

                    updateHolidayShortEndTime(contentView);
                }
            });

            return contentView;
        }

        @Override
        public View defaultAction() {
            final TableLayout contentView = (TableLayout) layoutInflater
                    .inflate(R.layout.fht_holiday_short_dialog, parent, false);

            final TimePicker timePicker = (TimePicker) contentView.findViewById(R.id.timePicker);
            timePicker.setIs24HourView(true);
            timePicker.setCurrentMinute(0);
            timePicker.setCurrentHour(now.getHourOfDay());

            timePicker.setOnTimeChangedListener(new TimePicker.OnTimeChangedListener() {
                @Override
                public void onTimeChanged(TimePicker timePicker, int hourOfDay, int minute) {
                    HolidayShort.this.hour = hourOfDay;
                    HolidayShort.this.minute = minute;

                    updateHolidayShortEndTime(contentView);
                }
            });

            return contentView;
        }
    });
    updateHolidayShortEndTime(contentView);

    final AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(context);

    TableRow temperatureUpdateRow = (TableRow) contentView.findViewById(R.id.updateTemperatureRow);
    final TemperatureChangeTableRow temperatureChangeTableRow = new TemperatureChangeTableRow(context,
            MINIMUM_TEMPERATURE, temperatureUpdateRow, MINIMUM_TEMPERATURE, MAXIMUM_TEMPERATURE,
            applicationProperties);
    contentView.addView(temperatureChangeTableRow.createRow(layoutInflater, device));

    dialogBuilder.setNegativeButton(R.string.cancelButton, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialogInterface, int i) {
            spinnerActionRow.revertSelection();
            dialogInterface.dismiss();
        }
    });

    dialogBuilder.setPositiveButton(R.string.okButton, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialogInterface, int item) {
            DateTime switchDate = holiday1SwitchTimeFor(hour, minute);

            @SuppressWarnings("unchecked")
            List<StateToSet> states = (List<StateToSet>) switchIntent
                    .getSerializableExtra(BundleExtraKeys.STATES);
            states.add(new StateToSet("desired-temp", "" + temperatureChangeTableRow.getTemperature()));
            states.add(new StateToSet("holiday1", "" + extractHolidayShortHoliday1ValueFrom(switchDate)));
            states.add(new StateToSet("holiday2", "" + switchDate.getDayOfMonth()));
            context.startService(switchIntent);

            spinnerActionRow.commitSelection();
            dialogInterface.dismiss();
        }
    });
    dialogBuilder.setView(contentView);
    dialogBuilder.show();
}

From source file:li.klass.fhem.adapter.devices.core.generic.detail.actions.devices.fht.HolidayShort.java

License:Open Source License

int extractHolidayShortHoliday1ValueFrom(DateTime dateTime) {
    return calculateHolidayShortHoliday1ValueFrom(dateTime.getHourOfDay(), dateTime.getMinuteOfHour());
}

From source file:li.klass.fhem.adapter.devices.core.generic.detail.actions.devices.fht.HolidayShort.java

License:Open Source License

boolean holidayShortIsTomorrow(DateTime switchTime, DateTime baseline) {
    int currentMinute = baseline.getHourOfDay() * 60 + baseline.getMinuteOfHour();
    int switchMinute = switchTime.getHourOfDay() * 60 + switchTime.getMinuteOfHour();

    return switchMinute < currentMinute;
}

From source file:li.klass.fhem.domain.AtDevice.java

License:Open Source License

private void parseDateContent(String dateContent) {
    if (dateContent.length() < "00:00:00".length()) {
        dateContent += ":00";
    }/*from w  ww  .  j  a  va 2s  .  c  o  m*/
    try {
        DateTime date = DATE_TIME_FORMAT.parseDateTime(dateContent);
        hours = date.getHourOfDay();
        minutes = date.getMinuteOfHour();
        seconds = date.getSecondOfMinute();

    } catch (Exception e) {
        Log.e(AtDevice.class.getName(), "cannot parse dateContent " + dateContent);
    }
}