Example usage for org.joda.time MutableDateTime setMinuteOfHour

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

Introduction

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

Prototype

public void setMinuteOfHour(final int minuteOfHour) 

Source Link

Document

Set the minute of the hour to the specified value.

Usage

From source file:com.tmathmeyer.sentinel.ui.views.day.collisiondetection.DayPanel.java

License:Open Source License

private DateTime getTimeAtCursor() {
    Point m = MouseInfo.getPointerInfo().getLocation();
    Point p = getLocationOnScreen();
    MutableDateTime d = date.toMutableDateTime();
    m.y -= offset;// w  ww .  ja  v  a 2s.c o m
    if (m.y < p.y)
        m.y = p.y;
    if (m.y > 1440)
        m.y = 1440;

    d.setHourOfDay((m.y - p.y) / 60);
    int min = (m.y - p.y) % 60;

    if (min >= 7 && min < 23)
        min = 15;
    if (min < 7)
        min = 0;
    if (min >= 23 && min < 38)
        min = 30;
    if (min >= 38 && min < 55)
        min = 45;
    if (min >= 55) {
        min = 0;
        d.addHours(1);
    }
    d.setMinuteOfHour(min);
    return d.toDateTime();
}

From source file:com.xpn.xwiki.criteria.impl.PeriodFactory.java

License:Open Source License

private static MutableDateTime toHourStart(MutableDateTime mdt) {
    mdt.setMinuteOfHour(mdt.minuteOfHour().getMinimumValue());
    mdt.setSecondOfMinute(mdt.secondOfMinute().getMinimumValue());
    mdt.setMillisOfSecond(mdt.millisOfSecond().getMinimumValue());
    return mdt;/*w w w. ja  v a2  s . com*/
}

From source file:com.yahoo.bard.webservice.sql.helper.SqlTimeConverter.java

License:Apache License

/**
 * Sets the correct part of a {@link DateTime} corresponding to a
 * {@link SqlDatePartFunction}.//from w  w w .  j a v a  2  s .  co  m
 *
 * @param value  The value to be set for the dateTime with the sqlDatePartFn
 * @param sqlDatePartFn  The function used to extract part of a date with sql.
 * @param dateTime  The original dateTime to create a copy of.
 */
protected void setDateTime(int value, SqlDatePartFunction sqlDatePartFn, MutableDateTime dateTime) {
    if (YEAR.equals(sqlDatePartFn)) {
        dateTime.setYear(value);
    } else if (MONTH.equals(sqlDatePartFn)) {
        dateTime.setMonthOfYear(value);
    } else if (WEEK.equals(sqlDatePartFn)) {
        dateTime.setWeekOfWeekyear(value);
        dateTime.setDayOfWeek(1);
    } else if (DAYOFYEAR.equals(sqlDatePartFn)) {
        dateTime.setDayOfYear(value);
    } else if (HOUR.equals(sqlDatePartFn)) {
        dateTime.setHourOfDay(value);
    } else if (MINUTE.equals(sqlDatePartFn)) {
        dateTime.setMinuteOfHour(value);
    } else if (SECOND.equals(sqlDatePartFn)) {
        dateTime.setSecondOfMinute(value);
    } else {
        throw new IllegalArgumentException("Can't set value " + value + " for " + sqlDatePartFn);
    }
}

From source file:net.naonedbus.rest.controller.impl.HoraireController.java

License:Open Source License

/**
 * Rcuprer les horaires depuis le WebService.
 * //from  ww  w .j a v  a  2 s.  c om
 * @throws IOException
 * @throws MalformedURLException
 */
public synchronized List<Horaire> getAllFromWeb(final Arret arret, final DateMidnight date) throws IOException {
    final UrlBuilder url = new UrlBuilder(PATH);
    final List<HoraireNode> horaires;
    List<Horaire> result = null;

    url.addSegment(arret.getCodeArret());
    url.addSegment(arret.getCodeLigne());
    url.addSegment(arret.getCodeSens());
    url.addSegment(mDateFormat.format(date.toDate()));
    final HoraireContainer content = parseJsonObject(url.getUrl());

    MutableDateTime mutableDateTime = new MutableDateTime(date);

    if (content != null) {
        horaires = content.horaires;
        result = new ArrayList<Horaire>();

        int lastHour = Integer.MIN_VALUE;

        // Transformation des horaires TAN en horaire naonedbus.
        for (final HoraireNode horaireTan : horaires) {
            final int hour = Integer.parseInt(horaireTan.heure.replaceAll("[^\\d.]", ""));

            mutableDateTime.setHourOfDay(hour);

            // Changement de jour
            if (hour < lastHour) {
                mutableDateTime.addDays(1);
            }
            lastHour = hour;

            for (final String passage : horaireTan.passages) {
                int minute = Integer.parseInt(passage.replaceAll("[^\\d.]", ""));

                mutableDateTime.setMinuteOfHour(minute);

                final Horaire horaire = new Horaire();
                horaire.setJour(date);
                horaire.setHoraire(mutableDateTime.toDateTime());
                horaire.setTerminus(parseTerminus(passage, content.notes));
                horaire.setSection(new DateMidnight(horaire.getHoraire()));
                result.add(horaire);
            }
        }
    }

    return result;
}

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);//from w  w  w. ja  va2  s . c  om
    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);
    }

    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.ja v  a 2s. c  o 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 . ja va 2 s.  com*/
 * @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.hippoecm.frontend.plugins.yui.datetime.YuiDateTimeField.java

License:Apache License

private void updateDateTime() {
    Date date = getDate();//from w w w  . j a  v  a  2  s .c  o  m
    if (date != null) {
        MutableDateTime datetime = new MutableDateTime(date);
        try {
            TimeZone zone = getClientTimeZone();
            if (zone != null) {
                datetime.setZone(DateTimeZone.forTimeZone(zone));
            }

            Integer hours = getHours();
            if (hours != null) {
                datetime.set(DateTimeFieldType.hourOfDay(), hours % 24);

                Integer minutes = getMinutes();
                datetime.setMinuteOfHour(minutes != null ? minutes : 0);
            }

            // the date will be in the server's timezone
            setDate(datetime.toDate());
            //setModelObject(datetime.toDate());
        } catch (RuntimeException e) {
            error(e.getMessage());
            invalid();
        }
    }
}

From source file:org.hippoecm.frontend.widgets.AjaxDateTimeField.java

License:Apache License

private void updateDateTime(Object datetime, Integer hours, Integer minutes, AjaxRequestTarget target) {
    MutableDateTime date = new MutableDateTime(datetime);
    try {//www . j ava 2s .  c om
        TimeZone zone = getClientTimeZone();
        if (zone != null) {
            date.setZone(DateTimeZone.forTimeZone(zone));
        }

        if (hours != null) {
            date.set(DateTimeFieldType.hourOfDay(), hours.intValue() % 24);
            date.setMinuteOfHour((minutes != null) ? minutes.intValue() : 0);
        }

        // the date will be in the server's timezone
        setModelObject(date.toDate());

        if (target != null) {
            target.add(this);
        }
    } catch (RuntimeException e) {
        error(e.getMessage());
        invalid();
    }
}

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

License:Apache License

public MutableDateTime resolveNextScheduleDate(LocalTime localTime, DateTime referenceTime) {
    /*//from w ww  .  j  a  va2 s.c o m
     * 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;
}