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:org.kuali.kpme.tklm.time.util.TkTimeBlockAggregate.java

License:Educational Community License

public TkTimeBlockAggregate(List<TimeBlock> timeBlocks, CalendarEntry payCalendarEntry, Calendar payCalendar,
        boolean useUserTimeZone, List<Interval> dayIntervals) {
    this.payCalendarEntry = payCalendarEntry;
    this.payCalendar = payCalendar;

    for (Interval dayInt : dayIntervals) {
        List<TimeBlock> dayTimeBlocks = new ArrayList<TimeBlock>();
        for (TimeBlock timeBlock : timeBlocks) {

            // Assumption: Timezones can only be switched at pay period end boundaries.
            // If the above assumption becomes false, the logic below will need to
            // accommodate virtual chopping of time blocks to have them fit nicely
            // in the "days" that are displayed to users.

            DateTime beginTime = useUserTimeZone ? timeBlock.getBeginTimeDisplay()
                    : timeBlock.getBeginDateTime().withZone(TKUtils.getSystemDateTimeZone());
            DateTime endTime = useUserTimeZone ? timeBlock.getEndTimeDisplay()
                    : timeBlock.getEndDateTime().withZone(TKUtils.getSystemDateTimeZone());
            if (dayInt.contains(beginTime)) {
                if (dayInt.contains(endTime) || endTime.compareTo(dayInt.getEnd()) == 0) {
                    // determine if the time block needs to be pushed forward / backward
                    if (beginTime.getHourOfDay() < dayInt.getStart().getHourOfDay()) {
                        timeBlock.setPushBackward(true);
                    }/*from w  ww  .  ja v a  2 s .  c o  m*/

                    dayTimeBlocks.add(timeBlock);
                }
            }
        }
        dayTimeBlockList.add(dayTimeBlocks);
    }
}

From source file:org.kuali.kpme.tklm.time.util.TkTimeBlockAggregate.java

License:Educational Community License

public TkTimeBlockAggregate(List<TimeBlock> timeBlocks, List<LeaveBlock> leaveBlocks,
        CalendarEntry payCalendarEntry, Calendar payCalendar, boolean useUserTimeZone,
        List<Interval> dayIntervals) {
    this.payCalendarEntry = payCalendarEntry;
    this.payCalendar = payCalendar;

    for (Interval dayInt : dayIntervals) {
        List<TimeBlock> dayTimeBlocks = new ArrayList<TimeBlock>();
        for (TimeBlock timeBlock : timeBlocks) {

            // Assumption: Timezones can only be switched at pay period end boundaries.
            // If the above assumption becomes false, the logic below will need to
            // accommodate virtual chopping of time blocks to have them fit nicely
            // in the "days" that are displayed to users.

            DateTime beginTime = useUserTimeZone ? timeBlock.getBeginTimeDisplay()
                    : new DateTime(timeBlock.getBeginTimestamp(), TKUtils.getSystemDateTimeZone());
            DateTime endTime = useUserTimeZone ? timeBlock.getEndTimeDisplay()
                    : new DateTime(timeBlock.getEndTimestamp(), TKUtils.getSystemDateTimeZone());
            if (dayInt.contains(beginTime)) {
                if (dayInt.contains(endTime) || endTime.compareTo(dayInt.getEnd()) == 0) {
                    // determine if the time block needs to be pushed forward / backward
                    if (beginTime.getHourOfDay() < dayInt.getStart().getHourOfDay()) {
                        timeBlock.setPushBackward(true);
                    }//from   w ww .j  av a2 s  .c  o m

                    dayTimeBlocks.add(timeBlock);
                }
            }
        }
        dayTimeBlockList.add(dayTimeBlocks);

        List<LeaveBlock> dayLeaveBlocks = new ArrayList<LeaveBlock>();
        for (LeaveBlock leaveBlock : leaveBlocks) {

            // Assumption: Timezones can only be switched at pay period end boundaries.
            // If the above assumption becomes false, the logic below will need to
            // accommodate virtual chopping of leave blocks to have them fit nicely
            // in the "days" that are displayed to users.

            DateTimeZone dateTimeZone = HrServiceLocator.getTimezoneService().getUserTimezoneWithFallback();
            DateTime beginTime = new DateTime(leaveBlock.getLeaveDate(),
                    useUserTimeZone ? dateTimeZone : TKUtils.getSystemDateTimeZone());
            DateTime endTime = new DateTime(leaveBlock.getLeaveDate(),
                    useUserTimeZone ? dateTimeZone : TKUtils.getSystemDateTimeZone());
            if (dayInt.contains(beginTime)) {
                if (dayInt.contains(endTime) || endTime.compareTo(dayInt.getEnd()) == 0) {
                    dayLeaveBlocks.add(leaveBlock);
                }
            }
        }
        dayLeaveBlockList.add(dayLeaveBlocks);
    }
}

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  . java  2 s .c o  m

    // 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;
    }//from   w w w.  j  a va2 s.  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  w w . j a  va2 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 ww.  ja v  a  2  s.c  om*/
 */
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");
}

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++;//  w w w .  j  a va2 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 .jav a 2  s .  c om*/
    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.  j  av a 2 s .  c om
 */
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 ww  w.ja v a2  s  .  c  o m
        // create time widget with current time as of right now
        clearAnswer();
    }
}