Example usage for org.joda.time MutableDateTime setHourOfDay

List of usage examples for org.joda.time MutableDateTime setHourOfDay

Introduction

In this page you can find the example usage for org.joda.time MutableDateTime setHourOfDay.

Prototype

public void setHourOfDay(final int hourOfDay) 

Source Link

Document

Set the hour of the day to the specified value.

Usage

From source file:nz.al4.airclock.MainActivity.java

License:Open Source License

@Override
public void onAlarmTimePicked(int hour, int minute) {

    DateTime currentTime = DateTime.now().toDateTime(mTimeCalculator.getTimeZone());
    Log.v("alarmCalc", "current time" + currentTime.toString());
    MutableDateTime desiredTime = currentTime.toMutableDateTime();
    desiredTime.setHourOfDay(hour);
    desiredTime.setMinuteOfHour(minute);

    // if after we set the hour + minute we get an earlier time, user probably means next day
    if (desiredTime.isBefore(currentTime)) {
        desiredTime.addDays(1);// w  w  w . j a  v  a2s.co m
    }

    DateTime alarmTime = mTimeCalculator.timeForAlarm(desiredTime.toDateTime().toLocalDateTime());

    DateTime originAlarm = alarmTime.toDateTime(mTimeCalculator.mOriginTime.getZone());
    DateTime destAlarm = alarmTime.toDateTime(mTimeCalculator.mDestTime.getZone());

    String msg = String.format("You should set your alarm for:\n%s (origin)\nor\n%s (destination)",
            dateTimeFormatter.print(originAlarm) + " " + originAlarm.getZone().toString(),
            dateTimeFormatter.print(destAlarm) + " " + destAlarm.getZone().toString());

    new AlertDialog.Builder(this).setTitle("Alarm").setMessage(msg).setCancelable(false)
            .setPositiveButton("ok", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    // Whatever...
                }
            }).show();
}

From source file:org.calrissian.accumulorecipes.commons.support.TimeUnit.java

License:Apache License

public long normalize(long timestamp) {
    MutableDateTime ts = new MutableDateTime(timestamp, DateTimeZone.UTC);

    /**/*from   w  w  w.  j  a va 2 s  .  co  m*/
     * NOTE: order of switch matters.
     *
     * This switch is designed to fall through from most to least significant. Zeroes all non significant
     * portions of the time before finally breaking at the end.
     */
    switch (this) {
    case MONTHS:
        ts.setDayOfMonth(1);
    case DAYS:
        ts.setHourOfDay(0);
    case HOURS:
        ts.setMinuteOfHour(0);
    case MINUTES:
        ts.setSecondOfMinute(0);
        ts.setMillisOfSecond(0);
        break;
    default:
        throw new IllegalArgumentException("Unsupported time unit");
    }

    return ts.getMillis();
}

From source file:org.efaps.ui.wicket.components.date.DateTimePanel.java

License:Apache License

/**
 * Method to get for the parameters returned from the form as a datetimes.
 *
 * @param _date date//from w  w  w. jav a2s.  c  o  m
 * @param _hour hour
 * @param _minute minutes
 * @param _ampm am/pm
 * @return valid string
 * @throws EFapsException on error
 */
public List<DateTime> getDateList(final List<StringValue> _date, final List<StringValue> _hour,
        final List<StringValue> _minute, final List<StringValue> _ampm) throws EFapsException {
    final List<DateTime> ret = new ArrayList<>();
    if (_date != null) {
        Iterator<StringValue> hourIter = null;
        Iterator<StringValue> minuteIter = null;
        Iterator<StringValue> ampmIter = null;
        if (_hour != null) {
            hourIter = _hour.iterator();
        }
        if (_minute != null) {
            minuteIter = _minute.iterator();
        }
        if (_ampm != null) {
            ampmIter = _ampm.iterator();
        }

        for (final StringValue date : _date) {
            if (!date.isNull() && !date.isEmpty()) {
                final DateTimeFormatter fmt = DateTimeFormat
                        .forPattern(this.converter.getDatePattern(Context.getThreadContext().getLocale()))
                        .withChronology(Context.getThreadContext().getChronology());
                fmt.withLocale(getLocale());
                final MutableDateTime mdt = fmt.parseMutableDateTime(date.toString());
                if (hourIter != null) {
                    final StringValue hourStr = hourIter.next();
                    final int hour = Integer.parseInt(hourStr.toString("0"));
                    mdt.setHourOfDay(hour);
                    if (ampmIter != null) {
                        final StringValue ampmStr = ampmIter.next();
                        if ("am".equals(ampmStr.toString("am"))) {
                            if (hour == 12) {
                                mdt.setHourOfDay(0);
                            }
                        } else {
                            if (hour != 12) {
                                mdt.setHourOfDay(hour + 12);
                            }
                        }
                    }
                    if (minuteIter != null) {
                        final StringValue minuteStr = minuteIter.next();
                        final int minute = Integer.parseInt(minuteStr.toString("0"));
                        mdt.setMinuteOfHour(minute);
                    }
                }
                ret.add(mdt.toDateTime());
            }
        }
    }
    return ret;
}

From source file:org.joda.example.time.DateTimePerformance.java

License:Apache License

private void checkJodaSetHour() {
    int COUNT = COUNT_VERY_FAST;
    // Is it fair to use only MutableDateTime here? You decide.
    MutableDateTime dt = new MutableDateTime(GJChronology.getInstance());
    for (int i = 0; i < AVERAGE; i++) {
        start("Joda", "setHour");
        for (int j = 0; j < COUNT; j++) {
            dt.setHourOfDay(13);
            if (dt == null) {
                System.out.println("Anti optimise");
            }//from   w ww . j  a v a  2s  .  c o  m
        }
        end(COUNT);
    }
}

From source file:org.joda.example.time.DateTimePerformance.java

License:Apache License

private void checkJISOSetHour() {
    int COUNT = COUNT_VERY_FAST;
    // Is it fair to use only MutableDateTime here? You decide.
    MutableDateTime dt = new MutableDateTime();
    for (int i = 0; i < AVERAGE; i++) {
        start("JISO", "setHour");
        for (int j = 0; j < COUNT; j++) {
            dt.setHourOfDay(13);
            if (dt == null) {
                System.out.println("Anti optimise");
            }/*from w w w  .j a va  2 s . c om*/
        }
        end(COUNT);
    }
}

From source file:org.joda.example.time.DateTimePerformance.java

License:Apache License

private void checkJodaSetGetHour() {
    int COUNT = COUNT_VERY_FAST;
    // Is it fair to use only MutableDateTime here? You decide.
    MutableDateTime dt = new MutableDateTime(GJChronology.getInstance());
    for (int i = 0; i < AVERAGE; i++) {
        start("Joda", "setGetHour");
        for (int j = 0; j < COUNT; j++) {
            dt.setHourOfDay(13);
            int val = dt.getHourOfDay();
            if (dt == null) {
                System.out.println("Anti optimise");
            }/* ww w .j  a  va  2 s .c  om*/
        }
        end(COUNT);
    }
}

From source file:org.joda.example.time.DateTimePerformance.java

License:Apache License

private void checkJISOSetGetHour() {
    int COUNT = COUNT_VERY_FAST;
    // Is it fair to use only MutableDateTime here? You decide.
    MutableDateTime dt = new MutableDateTime();
    for (int i = 0; i < AVERAGE; i++) {
        start("JISO", "setGetHour");
        for (int j = 0; j < COUNT; j++) {
            dt.setHourOfDay(13);
            int val = dt.getHourOfDay();
            if (dt == null) {
                System.out.println("Anti optimise");
            }/*from   w  w w .  j av a  2s. com*/
        }
        end(COUNT);
    }
}

From source file:org.n52.sos.cache.AbstractCacheScheduler.java

License:Apache License

public MutableDateTime resolveNextScheduleDate(LocalTime localTime, DateTime referenceTime) {
    /*//from w w  w  . j av a2 s.  c om
     * every 4am, starting with next
     */
    MutableDateTime mdt = referenceTime.toMutableDateTime();
    mdt.setHourOfDay(localTime.getHourOfDay());
    mdt.setMinuteOfHour(localTime.getMinuteOfHour());
    mdt.setSecondOfMinute(localTime.getSecondOfMinute());

    if (!referenceTime.isBefore(mdt)) {
        mdt.addDays(1);
    }

    Random random = new Random();
    mdt.addSeconds(random.nextInt(11) * 2);
    return mdt;
}

From source file:org.obp.utils.TimeUtil.java

License:Apache License

public static final long fromUtcHHMMSS(double time) {
    int hhmmss = (int) time;
    MutableDateTime mdt = MutableDateTime.now(DateTimeZone.UTC);
    mdt.setSecondOfMinute(hhmmss % 100);
    mdt.setMinuteOfHour((hhmmss / 100) % 100);
    mdt.setHourOfDay(hhmmss / 10000);
    mdt.setMillisOfSecond((int) ((time - hhmmss) * 1000));
    return mdt.toDateTime().getMillis();
}

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

License:Apache License

static DateTime forceMidnight(DateTime dt) {
    MutableDateTime mdt = dt.toMutableDateTime();
    mdt.setHourOfDay(0);
    mdt.setMinuteOfHour(0);//from   w  w  w  . ja  v  a 2  s  .c  o m
    mdt.setSecondOfMinute(0);
    return mdt.toDateTime();
}