Example usage for org.joda.time PeriodType minutes

List of usage examples for org.joda.time PeriodType minutes

Introduction

In this page you can find the example usage for org.joda.time PeriodType minutes.

Prototype

public static PeriodType minutes() 

Source Link

Document

Gets a type that defines just the minutes field.

Usage

From source file:com.metinkale.prayerapp.vakit.times.Times.java

License:Apache License

public int getLeftMinutes(int which) {
    LocalDateTime date = getTimeCal(null, which);
    Period period = new Period(LocalDateTime.now(), date, PeriodType.minutes());
    return period.getMinutes();
}

From source file:com.metinkale.prayerapp.vakit.times.Times.java

License:Apache License

public float getPassedPart() {
    int i = getNext();
    LocalDateTime date1 = getTimeCal(null, i - 1);
    LocalDateTime date2 = getTimeCal(null, i);
    Period period = new Period(date1, date2, PeriodType.minutes());
    float total = period.getMinutes();
    float passed = total - getLeftMinutes(i);
    return passed / total;
}

From source file:com.webarch.common.datetime.DateTimeUtils.java

License:Apache License

/**
 * ?/* www .  j  a v  a2  s.  c o m*/
 *
 * @return
 */
public static Period getTimePeriod(Date startTime, Date endTime, PeriodType periodType) {
    if (periodType == null)
        periodType = PeriodType.minutes();
    DateTime dateTimeStart = new DateTime(startTime);
    DateTime dateTimeEnd = new DateTime(endTime);
    Period p = new Period(dateTimeStart, dateTimeEnd, periodType);
    return p;
}

From source file:com.webarch.common.datetime.DateTimeUtils.java

License:Apache License

/**
 * ?//w  w  w  .  j av a2s .c  om
 *
 * @param startTime
 * @param endTime
 * @return
 */
public static long getPeriodMinutes(Date startTime, Date endTime) {
    return getTimePeriod(startTime, endTime, PeriodType.minutes()).getMinutes();
}

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

License:Apache License

public boolean isTimeValid(LocalTime time) {
    boolean timeValid = false;

    Interval periodTimeInterval = new Interval(startTime.toDateTimeToday(), endTime.toDateTimeToday());

    if (periodTimeInterval.contains(time.toDateTimeToday())) {
        int timeMinutes = new Duration(startTime.toDateTimeToday(), time.toDateTimeToday())
                .toPeriod(PeriodType.minutes()).getMinutes();

        if (timeMinutes % intervalBetweenLessonStart == 0) {
            timeValid = true;/*from ww w . j a v  a2 s  . c  o m*/
        }
    }

    return timeValid;
}

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

License:Apache License

@Override
protected final List<String> getTimeSlotContent(final DateMidnight date,
        final TimeSlot<PeriodBookingTimeSlotPayload> timeSlot,
        final ListItem<TimeSlot<PeriodBookingTimeSlotPayload>> timeSlotItem) {
    // Click action
    timeSlotItem.add(new AjaxEventBehavior("onclick") { //$NON-NLS-1$
        private static final long serialVersionUID = 1L;

        @Override//w  w  w.j a  v  a  2 s.  com
        protected void onEvent(AjaxRequestTarget target) {
            onTimeSlotClicked(timeSlot, timeSlot.getStartTime().toDateTime(date), target);

            target.add(timeSlotItem);
        }

        @Override
        public boolean isEnabled(Component component) {
            return isTimeSlotBookable(timeSlot);
        }
    });

    timeSlotItem.add(AttributeModifier.append("class", new AbstractReadOnlyModel<String>() { //$NON-NLS-1$
        private static final long serialVersionUID = 1L;

        @Override
        public String getObject() {
            return getTimeSlotClass(timeSlot);
        }
    }));

    List<String> contentLines = new ArrayList<String>();
    Period period = timeSlot.getPayload().getPeriod();

    // Time line
    DateTime startTime = timeSlot.getStartTime().toDateTime(date);
    DateTime endTime = timeSlot.getEndTime().toDateTime(date);
    org.joda.time.Period minutesDuration = new org.joda.time.Period(startTime, endTime, PeriodType.minutes());
    String timePriceLine = TIME_FORMAT.print(startTime) + "-" + TIME_FORMAT.print(endTime) + " - " //$NON-NLS-1$//$NON-NLS-2$
            + Math.round(minutesDuration.getMinutes()) + "m"; //$NON-NLS-1$
    if (period.getPrice() > 0) {
        timePriceLine += " - " + Formatters.getFormatCurrency().format(period.getPrice()); //$NON-NLS-1$
    }
    contentLines.add(timePriceLine);

    // Period
    if (Strings.isEmpty(period.getLocation()) == false) {
        contentLines.add(period.getLocation());
    }

    appendToTimeSlotContent(contentLines, timeSlot);

    return contentLines;
}

From source file:dk.teachus.utils.DateUtils.java

License:Apache License

public static int intervalMinutes(DateTime date1, DateTime date2) {
    int intervalMinutes = 0;

    if (date1 != null && date2 != null) {
        intervalMinutes = new Duration(date1, date2).toPeriod(PeriodType.minutes()).getMinutes();
    }//from  ww w .j a  v  a 2 s .co m

    return intervalMinutes;
}

From source file:org.agatom.springatom.webmvc.converters.IntervalToStringConverter.java

License:Open Source License

/** {@inheritDoc} */
@Override//from ww w .j a v  a 2 s  . c  o m
public String convert(final Interval source) {
    Preconditions.checkNotNull(source);
    return String.valueOf(source.toPeriod(PeriodType.minutes()).getMinutes());
}

From source file:org.jadira.usertype.dateandtime.joda.columnmapper.StringColumnPeriodMapper.java

License:Apache License

private PeriodType determinePeriodType(String s) {

    PeriodType periodType = PeriodType.standard();

    String current = s;//from  ww  w.  j a  va 2 s  .  co m

    if (current.startsWith(PeriodType.standard().getName())) {
        periodType = PeriodType.standard();
        current = s.substring(PeriodType.standard().getName().length());

    } else if (current.startsWith(PeriodType.yearMonthDayTime().getName())) {
        periodType = PeriodType.yearMonthDayTime();
        current = s.substring(PeriodType.yearMonthDayTime().getName().length());

    } else if (current.startsWith(PeriodType.yearMonthDay().getName())) {
        periodType = PeriodType.yearMonthDay();
        current = s.substring(PeriodType.yearMonthDay().getName().length());

    } else if (current.startsWith(PeriodType.yearWeekDayTime().getName())) {
        periodType = PeriodType.yearWeekDayTime();
        current = s.substring(PeriodType.yearWeekDayTime().getName().length());

    } else if (current.startsWith(PeriodType.yearWeekDay().getName())) {
        periodType = PeriodType.yearWeekDay();
        current = s.substring(PeriodType.yearWeekDay().getName().length());

    } else if (current.startsWith(PeriodType.yearDayTime().getName())) {
        periodType = PeriodType.yearDayTime();
        current = s.substring(PeriodType.yearDayTime().getName().length());

    } else if (current.startsWith(PeriodType.yearDay().getName())) {
        periodType = PeriodType.yearDay();
        current = s.substring(PeriodType.yearDay().getName().length());

    } else if (current.startsWith(PeriodType.dayTime().getName())) {
        periodType = PeriodType.dayTime();
        current = s.substring(PeriodType.dayTime().getName().length());

    } else if (current.startsWith(PeriodType.time().getName())) {
        periodType = PeriodType.time();
        current = s.substring(PeriodType.time().getName().length());

    } else if (current.startsWith(PeriodType.years().getName())) {
        periodType = PeriodType.years();
        current = s.substring(PeriodType.years().getName().length());

    } else if (current.startsWith(PeriodType.months().getName())) {
        periodType = PeriodType.months();
        current = s.substring(PeriodType.months().getName().length());

    } else if (current.startsWith(PeriodType.weeks().getName())) {
        periodType = PeriodType.weeks();
        current = s.substring(PeriodType.weeks().getName().length());

    } else if (current.startsWith(PeriodType.days().getName())) {
        periodType = PeriodType.days();
        current = s.substring(PeriodType.days().getName().length());

    } else if (current.startsWith(PeriodType.hours().getName())) {
        periodType = PeriodType.hours();
        current = s.substring(PeriodType.hours().getName().length());

    } else if (current.startsWith(PeriodType.minutes().getName())) {
        periodType = PeriodType.minutes();
        current = s.substring(PeriodType.minutes().getName().length());

    } else if (current.startsWith(PeriodType.seconds().getName())) {
        periodType = PeriodType.seconds();
        current = s.substring(PeriodType.seconds().getName().length());

    } else if (current.startsWith(PeriodType.millis().getName())) {
        periodType = PeriodType.millis();
        current = s.substring(PeriodType.millis().getName().length());
    }

    while (current.length() > 0) {

        if (current.startsWith("NoYears")) {
            periodType = periodType.withYearsRemoved();
            current = s.substring("NoYears".length());
        } else if (current.startsWith("NoMonths")) {
            periodType = periodType.withMonthsRemoved();
            current = s.substring("NoMonths".length());
        } else if (current.startsWith("NoWeeks")) {
            periodType = periodType.withWeeksRemoved();
            current = s.substring("NoWeeks".length());
        } else if (current.startsWith("NoDays")) {
            periodType = periodType.withDaysRemoved();
            current = s.substring("NoDays".length());
        } else if (current.startsWith("NoHours")) {
            periodType = periodType.withHoursRemoved();
            current = s.substring("NoHours".length());
        } else if (current.startsWith("NoMinutes")) {
            periodType = periodType.withMinutesRemoved();
            current = s.substring("NoMinutes".length());
        } else if (current.startsWith("NoSeconds")) {
            periodType = periodType.withSecondsRemoved();
            current = s.substring("NoSeconds".length());
        } else if (current.startsWith("NoMillis")) {
            periodType = periodType.withMillisRemoved();
            current = s.substring("NoMillis".length());
        } else {
            throw new IllegalArgumentException("Unrecognised PeriodType: " + s + "{" + current + "}");
        }
    }
    return periodType;
}