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:divconq.lang.BigDateTime.java

License:Open Source License

/**
 * @param date translates into BigDateTime
 *///from  w w w .  jav a  2s.com
public BigDateTime(DateTime date) {
    if (date == null)
        return;

    // make sure we are using ISO and UTC
    date = date.toDateTime(ISOChronology.getInstanceUTC());
    //date = date.toDateTime(DateTimeZone.UTC);      

    this.year = 50000000000L + date.getYear(); // ISO says 1 BCE = 0, 2 BCE = -1, etc
    this.month = date.getMonthOfYear();
    this.day = date.getDayOfMonth();
    this.hour = date.getHourOfDay();
    this.minute = date.getMinuteOfHour();
    this.second = date.getSecondOfMinute();
}

From source file:dk.teachus.backend.domain.impl.BookingsImpl.java

License:Apache License

public Booking getBooking(Period period, DateTime time) {
    Booking booking = null;/*from   w  w w.  j a v  a2s .  c  o m*/

    for (Booking foundBooking : bookings) {
        if (foundBooking.getPeriod().getId().equals(period.getId())) {
            DateTime dt1 = foundBooking.getDate();
            DateTime dt2 = time;

            if (dt1.toDateMidnight().equals(dt2.toDateMidnight())) {
                if (dt1.getHourOfDay() == dt2.getHourOfDay()
                        && dt1.getMinuteOfHour() == dt2.getMinuteOfHour()) {
                    booking = foundBooking;
                    break;
                }
            }
        }
    }

    return booking;
}

From source file:dk.teachus.frontend.components.calendar.CalendarPanel.java

License:Apache License

private int calculateNumberOfCalendarHours() {
    DateTime calStart = getCalendarStartTime().toDateTimeToday();
    DateTime calEnd = getCalendarEndTime().toDateTimeToday();
    if (getCalendarEndTime().getHourOfDay() == 0 && getCalendarEndTime().getMinuteOfHour() == 0) {
        calEnd = calEnd.plusDays(1);//from  www .  j a v a  2 s.com
    }
    if (calEnd.getMinuteOfHour() > 0) {
        calEnd = calEnd.plusHours(1).withMinuteOfHour(0);
    }
    return new org.joda.time.Period(calStart, calEnd, PeriodType.hours()).getHours();
}

From source file:edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.DateTimeWithPrecisionVTwo.java

License:Open Source License

/**
 * This produces a map for use in the template. Will be using this b/c 
 *///from  ww w . j a  v a  2 s.  c om
public Map getMapForTemplate(EditConfigurationVTwo editConfig, MultiValueEditSubmission editSub) {
    Map<String, Object> map = new HashMap<String, Object>();

    //always need the fieldName, required precision, and constants
    map.put("fieldName", getFieldName());
    addPrecisionConstants(map);
    map.put("minimumPrecision", minimumPrecision.uri());
    map.put("requiredLevel", displayRequiredLevel.uri());

    //Still expecting single precision uri not multiple
    String precisionUri = getPrecision(editConfig, editSub);

    VitroVocabulary.Precision existingPrec = toPrecision(precisionUri);

    if (precisionUri != null && !"".equals(precisionUri) && existingPrec == null) {
        if (!BLANK_SENTINEL.equals(precisionUri)) {
            log.debug("field " + getFieldName() + ": existing precision uri was " + "'" + precisionUri
                    + "' but could not convert to Precision object");
        }
    }

    if (precisionUri == null || precisionUri.isEmpty() || existingPrec == null) {
        map.put("existingPrecision", "");

        /* no precision so there should also be no datetime */
        DateTime value = getTimeValue(editConfig, editSub);
        if (value != null)
            log.debug("Unexpected state: Precision for " + getFieldName() + " was '" + precisionUri
                    + "' but date time was " + value);

        map.put("year", "");
        map.put("month", "");
        map.put("day", "");
        map.put("hour", "");
        map.put("minute", "");
        map.put("second", "");
    } else if (VitroVocabulary.Precision.NONE.uri().equals(precisionUri)) {
        //bdc34: not sure what to do with the NONE precision
        map.put("existingPrecision", precisionUri);

        map.put("year", "");
        map.put("month", "");
        map.put("day", "");
        map.put("hour", "");
        map.put("minute", "");
        map.put("second", "");
    } else {
        map.put("existingPrecision", precisionUri);

        DateTime value = getTimeValue(editConfig, editSub);
        /* This is the case where there is a precision so there should be a datetime */
        if (value == null) {
            //If there is no value, then this is an error condition
            log.error("Field " + getFieldName() + " has precision " + precisionUri
                    + " but the date time value is null ");
            map.put("year", "");
            map.put("month", "");
            map.put("day", "");
            map.put("hour", "");
            map.put("minute", "");
            map.put("second", "");

        } else {

            /* only put the values in the map for ones which are significant based on the precision */
            if (existingPrec.ordinal() >= VitroVocabulary.Precision.SECOND.ordinal())
                map.put("second", Integer.toString(value.getSecondOfMinute()));
            else
                map.put("second", "");

            if (existingPrec.ordinal() >= VitroVocabulary.Precision.MINUTE.ordinal())
                map.put("minute", Integer.toString(value.getMinuteOfHour()));
            else
                map.put("minute", "");

            if (existingPrec.ordinal() >= VitroVocabulary.Precision.HOUR.ordinal())
                map.put("hour", Integer.toString(value.getHourOfDay()));
            else
                map.put("hour", "");

            if (existingPrec.ordinal() >= VitroVocabulary.Precision.DAY.ordinal())
                map.put("day", Integer.toString(value.getDayOfMonth()));
            else
                map.put("day", "");

            if (existingPrec.ordinal() >= VitroVocabulary.Precision.MONTH.ordinal())
                map.put("month", Integer.toString(value.getMonthOfYear()));
            else
                map.put("month", "");

            if (existingPrec.ordinal() >= VitroVocabulary.Precision.YEAR.ordinal())
                map.put("year", Integer.toString(value.getYear()));
            else
                map.put("year", "");
        }
    }

    return map;
}

From source file:edu.illinois.cs.cogcomp.temporal.normalizer.main.timex2interval.Period.java

License:Open Source License

/**
 * This function deals with a period of time with format the xxth day/month, etc
 * @param start the anchor time/*from  ww w  .  ja v a  2  s .  c om*/
 * @param temporalPhrase
  * @return
  */
public static TimexChunk Periodrule(DateTime start, TemporalPhrase temporalPhrase) {

    int year;
    DateTime finish;
    String temp1;
    String temp2;
    Interval interval;
    interval = new Interval(start, start);
    String phrase = temporalPhrase.getPhrase();
    phrase = phrase.toLowerCase();
    DateTimeFormatter fmt = DateTimeFormat.forPattern("yyyy-MM-dd");

    int modiword = 0;// 0 :no modified words 1:early,ealier 2:late,later
    // Handle some special cases
    TimexChunk tc = new TimexChunk();
    tc.addAttribute(TimexNames.type, TimexNames.DATE);
    if (phrase.contains("now") || phrase.contains("currently") || phrase.contains("current")
            || phrase.contains("today")) {
        DateTime virtualStart = interval.getStart();
        virtualStart = new DateTime(virtualStart.getYear(), virtualStart.getMonthOfYear(),
                virtualStart.getDayOfMonth(), virtualStart.getHourOfDay(), virtualStart.getMinuteOfHour(),
                virtualStart.getSecondOfMinute(), virtualStart.getMillisOfSecond() + 1);
        tc.addAttribute(TimexNames.value, TimexNames.PRESENT_REF);
        return tc;
    }
    if (phrase.contains("early") || phrase.contains("earlier")) {
        modiword = 1;
    }
    if (phrase.contains("late") || phrase.contains("later")) {
        modiword = 2;
    }

    String units = "";

    for (String unitStr : dateUnitSet) {
        units = units + unitStr + "|";
    }
    units += "s$";

    String patternStr = "(?:the)?\\s*(\\d{1,4})(?:th|nd|st|rd)\\s*(" + units + ")\\s*";
    Pattern pattern = Pattern.compile(patternStr);
    Matcher matcher = pattern.matcher(phrase);
    boolean matchFound = matcher.find();
    if (matchFound) {
        temp1 = matcher.group(1);
        temp2 = matcher.group(2);

        String residual = StringUtils.difference(matcher.group(0), phrase);
        String anchorStr = "";
        if (residual.length() > 0) {
            TemporalPhrase anchorPhrase = new TemporalPhrase(residual, temporalPhrase.getTense());
            TimexChunk anchorTimex = TimexNormalizer.normalize(anchorPhrase);
            if (anchorTimex != null) {
                anchorStr = anchorTimex.getAttribute(TimexNames.value);
            }
        }

        if (temp2.equals("century")) {
            year = (Integer.parseInt(temp1) - 1) * 100;
            start = new DateTime(year, 1, 1, 0, 0, 0, 0);
            finish = new DateTime(year + 99, 12, 31, 23, 59, 59, 59);
            tc.addAttribute(TimexNames.value, String.valueOf(finish.getCenturyOfEra()));
            return tc;
        }

        else if (temp2.equals("decade")) {
            // e.g.: 3rd decade (of this century)
            // first we get this century is 20, then the 3rd decade is 203
            int anchorCentury = start.getCenturyOfEra();
            String val = String.valueOf(anchorCentury * 10 + temp1);
            tc.addAttribute(TimexNames.value, String.valueOf(val));
            return tc;
        }

        else if (temp2.equals("year")) {
            int anchorCentury = start.getCenturyOfEra();
            String val = String.valueOf(anchorCentury * 100 + temp1);
            tc.addAttribute(TimexNames.value, String.valueOf(val));
            return tc;
        }

        else if (temp2.equals("quarter")) {
            int anchorYear = start.getYear();
            String val = String.valueOf(anchorYear) + "-Q" + temp1;
            tc.addAttribute(TimexNames.value, String.valueOf(val));
            return tc;
        }

        else if (temp2.equals("month")) {
            int anchorYear = start.getYear();
            String monthStr = Integer.parseInt(temp1) < 10 ? "0" + temp1 : temp1;
            String val = String.valueOf(anchorYear) + "-" + monthStr;
            tc.addAttribute(TimexNames.value, String.valueOf(val));
            return tc;
        }

        else if (temp2.equals("day")) {
            String val = "";
            if (anchorStr.length() > 0) {
                List<String> normTimexList = Period.normTimexToList(anchorStr);
                String anchorYear = normTimexList.get(0);
                String anchorDate;
                String anchorMonth;
                if (normTimexList.size() == 1 || Integer.parseInt(temp1) > 31) {
                    anchorMonth = "01";
                } else {
                    anchorMonth = normTimexList.get(1);
                }
                DateTime normDateTime = new DateTime(Integer.parseInt(anchorYear),
                        Integer.parseInt(anchorMonth), 1, 0, 0);
                normDateTime = normDateTime.minusDays(-1 * Integer.parseInt(temp1));
                anchorYear = String.valueOf(normDateTime.getYear());
                anchorMonth = String.valueOf(normDateTime.getMonthOfYear());
                anchorDate = String.valueOf(normDateTime.getDayOfMonth());
                anchorMonth = anchorMonth.length() == 1 ? "0" + anchorMonth : anchorMonth;
                anchorDate = anchorDate.length() == 1 ? "0" + anchorDate : anchorDate;
                val = anchorYear + "-" + anchorMonth + "-" + anchorDate;

            } else {
                int month = Integer.parseInt(temp1) > 31 ? 1 : start.getMonthOfYear();
                DateTime normDateTime = new DateTime(start.getYear(), month, 1, 0, 0);
                normDateTime = normDateTime.minusDays(-1 * Integer.parseInt(temp1));
                String anchorYear = String.valueOf(normDateTime.getYear());
                String anchorMonth = String.valueOf(normDateTime.getMonthOfYear());
                String anchorDate = String.valueOf(normDateTime.getDayOfMonth());
                anchorMonth = anchorMonth.length() == 1 ? "0" + anchorMonth : anchorMonth;
                anchorDate = anchorDate.length() == 1 ? "0" + anchorDate : anchorDate;
                val = String.valueOf(anchorYear) + "-" + anchorMonth + "-" + anchorDate;
            }
            tc.addAttribute(TimexNames.value, String.valueOf(val));
            return tc;
        }

        else if (temp2.equals("s")) {

            if (Integer.parseInt(temp1) < 100) {
                year = start.getCenturyOfEra();
                year = year * 100 + Integer.parseInt(temp1);
                if (modiword == 0) {
                    tc.addAttribute(TimexNames.value, String.valueOf(year / 10));
                }

                else if (modiword == 1) {
                    tc.addAttribute(TimexNames.value, String.valueOf(year / 10));
                    tc.addAttribute(TimexNames.mod, TimexNames.START);
                }

                else if (modiword == 2) {
                    tc.addAttribute(TimexNames.value, String.valueOf(year / 10));
                    tc.addAttribute(TimexNames.mod, TimexNames.END);
                }

                return tc;
            }

            else {
                if (modiword == 0) {
                    start = new DateTime(Integer.parseInt(temp1), 1, 1, 0, 0, 0, 0);
                    finish = new DateTime(Integer.parseInt(temp1) + 9, 12, 31, 23, 59, 59, 59);
                    tc.addAttribute(TimexNames.value, String.valueOf(finish.getYear() / 10));
                }

                else if (modiword == 1) {
                    start = new DateTime(Integer.parseInt(temp1), 1, 1, 0, 0, 0, 0);
                    finish = new DateTime(Integer.parseInt(temp1) + 3, 12, 31, 23, 59, 59, 59);
                    tc.addAttribute(TimexNames.value, String.valueOf(finish.getYear() / 10));
                    tc.addAttribute(TimexNames.mod, TimexNames.START);
                }

                else if (modiword == 2) {
                    start = new DateTime(Integer.parseInt(temp1) + 7, 1, 1, 0, 0, 0, 0);
                    finish = new DateTime(Integer.parseInt(temp1) + 9, 12, 31, 23, 59, 59, 59);
                    tc.addAttribute(TimexNames.value, String.valueOf(finish.getYear() / 10));
                    tc.addAttribute(TimexNames.mod, TimexNames.END);
                }
                return tc;

            }
        }

    }
    return null;
}

From source file:edu.washington.cs.mystatus.odk.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  . j  a va  2  s  . c om*/

    // 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) {
            MyStatus.getInstance().getActivityLogger().logInstanceAction(TimeWidget.this, "onTimeChanged",
                    String.format("%1$02d:%2$02d", hourOfDay, minute), mPrompt.getIndex());
        }
    });

    setGravity(Gravity.LEFT);
    addView(mTimePicker);

}

From source file:es.pode.adl.datamodels.datatypes.DateTimeValidator.java

License:Open Source License

/**
 * Compares two valid data model elements for equality.
 * /*from  w ww  .j  av  a  2 s.  co  m*/
 * @param iFirst  The first value being compared.
 * 
 * @param iSecond The second value being compared.
 * 
 * @param iDelimiters The common set of delimiters associated with the
 * values being compared.
 * 
 * @return Returns <code>true</code> if the two values are equal, otherwise
 *         <code>false</code>.
 */
public boolean compare(String iFirst, String iSecond, Vector iDelimiters) {

    boolean equal = true;

    DateTimeFormatter dtp = ISODateTimeFormat.dateTimeParser();

    try {
        // Parse the first string and remove the sub-seconds
        DateTime dt1 = dtp.parseDateTime(iFirst);
        dt1 = new DateTime(dt1.getYear(), dt1.getMonthOfYear(), dt1.getDayOfMonth(), dt1.getHourOfDay(),
                dt1.getMinuteOfHour(), dt1.getSecondOfMinute(), 0);

        // Parse the second string and remove the sub-seconds
        DateTime dt2 = dtp.parseDateTime(iSecond);
        dt2 = new DateTime(dt2.getYear(), dt2.getMonthOfYear(), dt2.getDayOfMonth(), dt2.getHourOfDay(),
                dt2.getMinuteOfHour(), dt2.getSecondOfMinute(), 0);

        equal = dt1.equals(dt2);
    } catch (Exception e) {
        // String format error -- these cannot be equal
        equal = false;
    }

    return equal;
}

From source file:es.ucm.fdi.tutorias.business.boundary.Emails.java

License:Open Source License

private boolean crearArchivoCal(String nombreCalendario, Tutoria tutoria) {
    String hostEmail = username;//from  www  . ja v a  2s . c  o  m

    //Initialize values
    String calFile = nombreCalendario;
    ;

    //start time
    DateTime comienzo = tutoria.getComienzoTutoria();
    java.util.Calendar startCal = java.util.Calendar.getInstance();
    startCal.set(comienzo.getYear(), comienzo.getMonthOfYear(), comienzo.getDayOfMonth(),
            comienzo.getHourOfDay(), comienzo.getMinuteOfHour());

    //end time
    java.util.Calendar endCal = java.util.Calendar.getInstance();
    DateTime fin = tutoria.getFinTutoria();
    endCal.set(fin.getYear(), fin.getMonthOfYear(), fin.getDayOfMonth(), fin.getHourOfDay(),
            fin.getMinuteOfHour());

    String subject = "Tutora";
    String location = "Location - \"Facultad de Informtica-UCM\"";
    String description = tutoria.getResumenDudas();

    net.fortuna.ical4j.model.Calendar calendar = new net.fortuna.ical4j.model.Calendar();
    calendar.getProperties().add(new ProdId("-//ProyectoSI-FdiUcm//iCal4j 1.0//EN"));
    calendar.getProperties().add(Version.VERSION_2_0);
    calendar.getProperties().add(CalScale.GREGORIAN);

    SimpleDateFormat sdFormat = new SimpleDateFormat("yyyyMMdd'T'hhmmss'Z'");
    String strDate = sdFormat.format(startCal.getTime());

    net.fortuna.ical4j.model.Date startDt = null;
    try {
        startDt = new net.fortuna.ical4j.model.Date(strDate, "yyyyMMdd'T'hhmmss'Z'");
    } catch (ParseException e) {
        e.printStackTrace();
        return false;
    }

    long diff = endCal.getTimeInMillis() - startCal.getTimeInMillis();
    int min = (int) (diff / (1000 * 60));

    Dur dur = new Dur(0, 0, min, 0);

    //Creating a meeting event
    VEvent meeting = new VEvent(startDt, dur, subject);

    meeting.getProperties().add(new Location(location));
    meeting.getProperties().add(new Description());

    try {
        meeting.getProperties().getProperty(Property.DESCRIPTION).setValue(description);
    } catch (IOException e) {
        e.printStackTrace();
        return false;
    } catch (URISyntaxException e) {
        e.printStackTrace();
        return false;
    } catch (ParseException e) {
        e.printStackTrace();
        return false;
    }

    try {
        meeting.getProperties().add(new Organizer("MAILTO:" + hostEmail));
    } catch (URISyntaxException e) {
        e.printStackTrace();
        return false;
    }

    calendar.getComponents().add(meeting);

    FileOutputStream fout = null;

    try {
        fout = new FileOutputStream(calFile);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
        return false;
    }

    CalendarOutputter outputter = new CalendarOutputter();
    outputter.setValidating(false);

    try {
        outputter.output(calendar, fout);
        return true;
    } catch (IOException e) {
        e.printStackTrace();
        return false;
    } catch (ValidationException e) {
        e.printStackTrace();
        return false;
    }
}

From source file:es.usc.citius.servando.calendula.fragments.RoutineCreateOrEditFragment.java

License:Open Source License

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_create_or_edit_routine, container, false);

    pColor = DB.patients().getActive(getActivity()).color();

    mNameTextView = (TextView) rootView.findViewById(R.id.routine_edit_name);
    timeButton = (Button) rootView.findViewById(R.id.button2);

    timeButton.setTextColor(pColor);//  w w  w  .java 2  s .co  m

    long routineId = -1;

    if (getArguments() != null) {
        routineId = getArguments().getLong(CalendulaApp.INTENT_EXTRA_ROUTINE_ID, -1);
    }

    if (routineId == -1 && savedInstanceState != null) {
        routineId = savedInstanceState.getLong(CalendulaApp.INTENT_EXTRA_ROUTINE_ID, -1);
    }

    if (routineId != -1) {
        mRoutine = Routine.findById(routineId);
        setRoutine(mRoutine);
        hour = mRoutine.time().getHourOfDay();
        minute = mRoutine.time().getMinuteOfHour();
    } else {
        DateTime now = DateTime.now();
        hour = now.getHourOfDay();
        minute = now.getMinuteOfHour();
    }

    if (getDialog() != null) {
        getDialog().setTitle(R.string.title_create_routine_activity);
        mConfirmButton = (Button) rootView.findViewById(R.id.done_button);
        mConfirmButton.setVisibility(View.VISIBLE);
        mConfirmButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                onEdit();
            }
        });
    }

    timeButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            float density = getResources().getDisplayMetrics().densityDpi;
            Log.d("RoutineCreateOrEditFragment", "Density: " + density);
            if (density >= DisplayMetrics.DENSITY_XHIGH) {
                RadialTimePickerDialog timePickerDialog = RadialTimePickerDialog
                        .newInstance(RoutineCreateOrEditFragment.this, hour, minute, true);
                timePickerDialog.show(getChildFragmentManager(), "111");
            } else {
                TimePickerBuilder tpb = new TimePickerBuilder().setFragmentManager(getChildFragmentManager())
                        .setStyleResId(R.style.BetterPickersDialogFragment_Light);
                tpb.addTimePickerDialogHandler(RoutineCreateOrEditFragment.this);
                tpb.show();
            }

        }
    });

    updateTime();

    return rootView;
}

From source file:es.usc.citius.servando.calendula.fragments.ScheduleImportFragment.java

License:Open Source License

private void setupHourlyRepetitionLinsteners() {
    hourlyIntervalEditText.setOnClickListener(new View.OnClickListener() {
        @Override//from   ww w .j a  v  a2s .  c o  m
        public void onClick(View v) {
            showHourlyPickerDIalog();
        }
    });

    hourlyIntervalFrom.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            DateTime time = schedule.startTime().toDateTimeToday();

            RadialTimePickerDialog timePickerDialog = RadialTimePickerDialog.newInstance(
                    ScheduleImportFragment.this, time.getHourOfDay(), time.getMinuteOfHour(), true);
            timePickerDialog.show(getChildFragmentManager(), "111");
        }
    });

    hourlyIntervalRepeatDose.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            showHourlyDosePickerDialog();
        }
    });
}