Example usage for org.joda.time Period getMinutes

List of usage examples for org.joda.time Period getMinutes

Introduction

In this page you can find the example usage for org.joda.time Period getMinutes.

Prototype

public int getMinutes() 

Source Link

Document

Gets the minutes field part of the period.

Usage

From source file:org.projectforge.web.teamcal.event.MyWicketEvent.java

License:Open Source License

public String getDuration() {
    if (duration != null) {
        return duration;
    }/*from  w w w. j  a  va 2s.c  om*/
    final Period period = new Period(this.getStart(), this.getEnd());
    int days = period.getDays();
    if (isAllDay() == true) {
        ++days;
    }
    final int hours = period.getHours();
    final int minutes = period.getMinutes();
    final StringBuffer buf = new StringBuffer();
    if (days > 0) { // days
        buf.append(days).append(ThreadLocalUserContext.getLocalizedString("calendar.unit.day")).append(" ");
    }
    if (isAllDay() == false) {
        buf.append(hours).append(":"); // hours
        if (minutes < 10) {
            buf.append("0");
        }
        buf.append(minutes);
    }
    duration = buf.toString();
    return duration;
}

From source file:org.projectforge.web.teamcal.event.TeamCalEventProvider.java

License:Open Source License

/**
 * @see org.projectforge.web.calendar.MyFullCalendarEventsProvider#buildEvents(org.joda.time.DateTime,
 *      org.joda.time.DateTime)/*from w w w  .j  a v  a 2 s .  c o m*/
 */
@Override
protected void buildEvents(final DateTime start, final DateTime end) {
    final TemplateEntry activeTemplateEntry = filter.getActiveTemplateEntry();
    if (activeTemplateEntry == null) {
        // Nothing to build.
        return;
    }
    final Set<Integer> visibleCalendars = activeTemplateEntry.getVisibleCalendarIds();
    if (CollectionUtils.isEmpty(visibleCalendars) == true) {
        // Nothing to build.
        return;
    }
    final TeamEventFilter eventFilter = new TeamEventFilter();
    eventFilter.setTeamCals(visibleCalendars);
    eventFilter.setStartDate(start.toDate());
    eventFilter.setEndDate(end.toDate());
    eventFilter.setUser(ThreadLocalUserContext.getUser());
    final List<TeamEvent> teamEvents = teamEventDao.getEventList(eventFilter, true);

    boolean longFormat = false;
    days = Days.daysBetween(start, end).getDays();
    if (days < 10) {
        // Week or day view:
        longFormat = true;
    }

    final TeamCalRight right = new TeamCalRight(accessChecker);
    final PFUserDO user = ThreadLocalUserContext.getUser();
    final TimeZone timeZone = ThreadLocalUserContext.getTimeZone();
    if (CollectionUtils.isNotEmpty(teamEvents) == true) {
        for (final TeamEvent teamEvent : teamEvents) {
            final DateTime startDate = new DateTime(teamEvent.getStartDate(),
                    ThreadLocalUserContext.getDateTimeZone());
            final DateTime endDate = new DateTime(teamEvent.getEndDate(),
                    ThreadLocalUserContext.getDateTimeZone());
            final TeamEventDO eventDO;
            final TeamCalEventId id = new TeamCalEventId(teamEvent, timeZone);
            if (teamEvent instanceof TeamEventDO) {
                eventDO = (TeamEventDO) teamEvent;
            } else {
                eventDO = ((TeamRecurrenceEvent) teamEvent).getMaster();
            }
            teamEventMap.put(id.toString(), teamEvent);
            final MyWicketEvent event = new MyWicketEvent();
            event.setClassName(
                    EVENT_CLASS_NAME + " " + EventDroppedCallbackScriptGenerator.NO_CONTEXTMENU_INDICATOR);
            event.setId("" + id);
            event.setColor(activeTemplateEntry.getColorCode(eventDO.getCalendarId()));

            if (eventRight.hasUpdateAccess(ThreadLocalUserContext.getUser(), eventDO, null)) {
                event.setEditable(true);
            } else {
                event.setEditable(false);
            }

            // id <= 0 is hint for abo events -> not editable
            if (eventDO.getId() != null && eventDO.getId() <= 0) {
                event.setEditable(false);
            }

            if (teamEvent.isAllDay() == true) {
                event.setAllDay(true);
            }

            event.setStart(startDate);
            event.setEnd(endDate);

            String recurrence = null;
            if (eventDO.hasRecurrence() == true) {
                final Recur recur = eventDO.getRecurrenceObject();
                final TeamEventRecurrenceData recurrenceData = new TeamEventRecurrenceData(recur,
                        ThreadLocalUserContext.getTimeZone());
                final RecurrenceFrequency frequency = recurrenceData.getFrequency();
                if (frequency != null) {
                    final String unitI18nKey = frequency.getUnitI18nKey();
                    if (unitI18nKey != null) {
                        recurrence = recurrenceData.getInterval() + " " + getString(unitI18nKey);
                    }
                }
            }
            String reminder = null;
            if (eventDO.getReminderActionType() != null
                    && NumberHelper.greaterZero(eventDO.getReminderDuration()) == true
                    && eventDO.getReminderDurationUnit() != null) {
                reminder = getString(eventDO.getReminderActionType().getI18nKey()) + " "
                        + eventDO.getReminderDuration() + " "
                        + getString(eventDO.getReminderDurationUnit().getI18nKey());
            }
            event.setTooltip(eventDO.getCalendar().getTitle(),
                    new String[][] { { eventDO.getSubject() },
                            { eventDO.getLocation(), getString("timesheet.location") },
                            { eventDO.getNote(), getString("plugins.teamcal.event.note") },
                            { recurrence, getString("plugins.teamcal.event.recurrence") },
                            { reminder, getString("plugins.teamcal.event.reminder") } });
            final String title;
            String durationString = "";
            if (longFormat == true) {
                // String day = duration.getDays() + "";
                final Period period = new Period(startDate, endDate);
                int hourInt = period.getHours();
                if (period.getDays() > 0) {
                    hourInt += period.getDays() * 24;
                }
                final String hour = hourInt < 10 ? "0" + hourInt : "" + hourInt;

                final int minuteInt = period.getMinutes();
                final String minute = minuteInt < 10 ? "0" + minuteInt : "" + minuteInt;

                if (event.isAllDay() == false) {
                    durationString = "\n"
                            + ThreadLocalUserContext.getLocalizedString("plugins.teamcal.event.duration") + ": "
                            + hour + ":" + minute;
                }
                final StringBuffer buf = new StringBuffer();
                buf.append(teamEvent.getSubject());
                if (StringUtils.isNotBlank(teamEvent.getNote()) == true) {
                    buf.append("\n")
                            .append(ThreadLocalUserContext.getLocalizedString("plugins.teamcal.event.note"))
                            .append(": ").append(teamEvent.getNote());
                }
                buf.append(durationString);
                title = buf.toString();
            } else {
                title = teamEvent.getSubject();
            }
            if (right.hasMinimalAccess(eventDO.getCalendar(), user.getId()) == true) {
                // for minimal access
                event.setTitle("");
                event.setEditable(false);
            } else {
                event.setTitle(title);
            }
            events.put(id + "", event);
        }
    }
}

From source file:org.samcrow.ridgesurvey.data.ObservationItemView.java

License:Open Source License

/**
 * Formats a duration with a human-friendly form of [] minutes/hours... ago
 * @param duration the duration to format
 * @return a representation of the duration
 *///from w w w. j  a v  a2  s . c  o  m
private static String formatAgo(Period duration) {
    if (duration.getDays() > 1) {
        return String.format(Locale.getDefault(), "%d days ago", duration.getDays());
    }
    if (duration.getHours() > 1) {
        return String.format(Locale.getDefault(), "%d hours ago", duration.getHours());
    }
    if (duration.getMinutes() > 1) {
        return String.format(Locale.getDefault(), "%d minutes ago", duration.getMinutes());
    } else {
        return "Just now";
    }
}

From source file:org.trakhound.www.trakhound.DeviceDetails.java

License:Open Source License

private void updateStatus(DeviceStatus status) {

    if (status.statusInfo == null)
        status.statusInfo = new StatusInfo();

    if (status.statusInfo.deviceStatus != null) {

        String deviceStatus = status.statusInfo.deviceStatus;

        // Current Status Indicator
        View banner = findViewById(R.id.DeviceStatusIndicator);
        if (banner != null) {

            if (deviceStatus.equals("Alert")) {
                banner.setBackgroundColor(getResources().getColor(R.color.statusRed));
            } else if (deviceStatus.equals("Idle")) {
                banner.setBackgroundColor(getResources().getColor(R.color.statusOrange));
            } else {
                banner.setBackgroundColor(getResources().getColor(R.color.statusGreen));
            }/*  ww w .  j  av a 2 s  .c om*/
        }

        // Current Status Text
        TextView txt = (TextView) findViewById(R.id.DeviceStatusText);
        if (txt != null)
            txt.setText(deviceStatus);

        // Current Status Timer
        Period period = new Period(status.statusInfo.deviceStatusTimer * 1000);
        String statusPeriod = String.format("%02d:%02d:%02d", period.getHours(), period.getMinutes(),
                period.getSeconds());

        txt = (TextView) findViewById(R.id.DeviceStatusTime);
        if (txt != null)
            txt.setText(statusPeriod);

    } else
        clearStatus();
}

From source file:org.trakhound.www.trakhound.DeviceDetails.java

License:Open Source License

private void updateDevicePercentages(DeviceStatus status) {

    // Percentages
    if (status.timersInfo != null && status.timersInfo.total > 0) {

        TimersInfo info = status.timersInfo;

        double active = (info.active / info.total) * 100;
        double idle = (info.idle / info.total) * 100;
        double alert = (info.alert / info.total) * 100;

        // Progress Bars

        // Active
        ProgressBar pb = (ProgressBar) findViewById(R.id.ActiveProgressBar);
        if (pb != null)
            pb.setProgress((int) Math.round(active));

        // Idle//from   w  ww. ja v  a 2  s . c o m
        pb = (ProgressBar) findViewById(R.id.IdleProgressBar);
        if (pb != null)
            pb.setProgress((int) Math.round(idle));

        // Alert
        pb = (ProgressBar) findViewById(R.id.AlertProgressBar);
        if (pb != null)
            pb.setProgress((int) Math.round(alert));

        // Percentage TextViews

        // Active
        TextView txt = (TextView) findViewById(R.id.ActivePercentage);
        if (txt != null)
            txt.setText(String.format("%.0f%%", active));

        // Idle
        txt = (TextView) findViewById(R.id.IdlePercentage);
        if (txt != null)
            txt.setText(String.format("%.0f%%", idle));

        // Alert
        txt = (TextView) findViewById(R.id.AlertPercentage);
        if (txt != null)
            txt.setText(String.format("%.0f%%", alert));

        // Time Elapsed TextViews

        // Active
        Integer seconds = Integer.valueOf((int) Math.round(info.active));
        Period period = new Period(seconds * 1000);
        String statusPeriod = String.format("%02d:%02d:%02d", period.getHours(), period.getMinutes(),
                period.getSeconds());
        txt = (TextView) findViewById(R.id.ActiveTime);
        if (txt != null)
            txt.setText(statusPeriod);

        // Idle
        seconds = Integer.valueOf((int) Math.round(info.idle));
        period = new Period(seconds * 1000);
        statusPeriod = String.format("%02d:%02d:%02d", period.getHours(), period.getMinutes(),
                period.getSeconds());
        txt = (TextView) findViewById(R.id.IdleTime);
        if (txt != null)
            txt.setText(statusPeriod);

        // Alert
        seconds = Integer.valueOf((int) Math.round(info.alert));
        period = new Period(seconds * 1000);
        statusPeriod = String.format("%02d:%02d:%02d", period.getHours(), period.getMinutes(),
                period.getSeconds());
        txt = (TextView) findViewById(R.id.AlertTime);
        if (txt != null)
            txt.setText(statusPeriod);

    } else
        clearDevicePercentages();
}

From source file:org.trakhound.www.trakhound.device_list.ListAdapter.java

License:Open Source License

private void setProductionStatus(ViewHolder holder, StatusInfo info) {

    if (info != null && info.deviceStatus != null) {

        if (holder.ProductionStatus != null)
            holder.ProductionStatus.setText(info.deviceStatus);

        if (holder.ProductionStatusTimer != null && info.deviceStatusTimer != null) {

            Period period = new Period(info.deviceStatusTimer * 1000);
            String statusPeriod = String.format("%02d:%02d:%02d", period.getHours(), period.getMinutes(),
                    period.getSeconds());

            holder.ProductionStatusTimer.setText(statusPeriod);
        }/*from  w w w  .j  a  v  a  2s  .  c om*/
    }
}

From source file:org.wisdom.akka.impl.Job.java

License:Apache License

/**
 * Translates the given (Joda) Period to (Scala) duration.
 *
 * @param period the period//from w ww.j  av a 2  s .c om
 * @return the duration representing the same amount of time
 */
public static FiniteDuration toDuration(Period period) {
    return Duration.create(period.getDays(), TimeUnit.DAYS)
            .plus(Duration.create(period.getHours(), TimeUnit.HOURS)
                    .plus(Duration.create(period.getMinutes(), TimeUnit.MINUTES)
                            .plus(Duration.create(period.getSeconds(), TimeUnit.SECONDS))));
}

From source file:org.wso2.carbon.apimgt.usage.client.impl.APIUsageStatisticsRestClientImpl.java

License:Open Source License

/**
 * This method is used to get the breakdown of the duration between 2 days/timestamps in terms of years,
 * months, days, hours, minutes and seconds
 *
 * @param fromDate Start timestamp of the duration
 * @param toDate   End timestamp of the duration
 * @return A map containing the breakdown
 * @throws APIMgtUsageQueryServiceClientException when there is an error during date parsing
 *///from  ww  w.j  a va 2  s .c o  m
private Map<String, Integer> getDurationBreakdown(String fromDate, String toDate)
        throws APIMgtUsageQueryServiceClientException {
    Map<String, Integer> durationBreakdown = new HashMap<String, Integer>();

    DateTimeFormatter formatter = DateTimeFormat
            .forPattern(APIUsageStatisticsClientConstants.TIMESTAMP_PATTERN);
    LocalDateTime startDate = LocalDateTime.parse(fromDate, formatter);
    LocalDateTime endDate = LocalDateTime.parse(toDate, formatter);
    Period period = new Period(startDate, endDate);
    int numOfYears = period.getYears();
    int numOfMonths = period.getMonths();
    int numOfWeeks = period.getWeeks();
    int numOfDays = period.getDays();
    if (numOfWeeks > 0) {
        numOfDays += numOfWeeks * 7;
    }
    int numOfHours = period.getHours();
    int numOfMinutes = period.getMinutes();
    int numOfSeconds = period.getSeconds();
    durationBreakdown.put(APIUsageStatisticsClientConstants.DURATION_YEARS, numOfYears);
    durationBreakdown.put(APIUsageStatisticsClientConstants.DURATION_MONTHS, numOfMonths);
    durationBreakdown.put(APIUsageStatisticsClientConstants.DURATION_DAYS, numOfDays);
    durationBreakdown.put(APIUsageStatisticsClientConstants.DURATION_WEEKS, numOfWeeks);
    durationBreakdown.put(APIUsageStatisticsClientConstants.DURATION_HOURS, numOfHours);
    durationBreakdown.put(APIUsageStatisticsClientConstants.DURATION_MINUTES, numOfMinutes);
    durationBreakdown.put(APIUsageStatisticsClientConstants.DURATION_SECONDS, numOfSeconds);
    return durationBreakdown;
}

From source file:se.toxbee.sleepfighter.text.DateTextUtils.java

License:Open Source License

/**
 * Builds and returns earliest text when given a resources bundle.
 *
 * @param formats an array of strings containing formats for [no-alarm-active, < minute, xx-yy-zz, xx-yy, xx]
 *       where xx, yy, zz can be either day, hours, minutes (non-respectively).
 * @param partsFormat an array of strings containing part formats for [day, month, hour].
 * @param diff difference between now and ats.
 * @param ats an AlarmTimestamp: the information about the alarm & its timestamp.
 * @return the built time-to string.// w w  w.j ava  2  s. com
 */
public static final String getTimeToText(String[] formats, String[] partFormats, Period diff,
        AlarmTimestamp ats) {
    String earliestText;

    // Not real? = we don't have any alarms active.
    if (ats == AlarmTimestamp.INVALID) {
        earliestText = formats[0];
    } else {
        int[] diffVal = { Math.abs(diff.getDays()), Math.abs(diff.getHours()), Math.abs(diff.getMinutes()) };

        // What fields are set?
        BitSet setFields = new BitSet(3);
        setFields.set(0, diffVal[0] != 0);
        setFields.set(1, diffVal[1] != 0);
        setFields.set(2, diffVal[2] != 0);
        int cardinality = setFields.cardinality();

        earliestText = formats[cardinality + 1];

        if (cardinality > 0) {
            List<String> args = new ArrayList<String>(3);

            for (int i = setFields.nextSetBit(0); i >= 0; i = setFields.nextSetBit(i + 1)) {
                args.add(partFormats[i]);
            }

            // Finally format everything.
            earliestText = String.format(earliestText, args.toArray());

            earliestText = String.format(earliestText, diffVal[0], diffVal[1], diffVal[2]);
        } else {
            // only seconds remains until it goes off.
            earliestText = formats[1];
        }
    }

    return earliestText;
}

From source file:trabalho.model.JodaMain.java

public int retornaTempo(RegistroPontoEntity registro) {
    RegistroPontoEntity registroPonto = registro;
    DateTime dataHoraEntrada = new DateTime(registroPonto.getDataInicial());
    DateTime dataHoraSaida = new DateTime(registroPonto.getDataFinal());
    Period tempoTrabalhado = new Period(dataHoraEntrada, dataHoraSaida);
    int horaLocal = tempoTrabalhado.getMinutes() + tempoTrabalhado.getHours() * 60
            + tempoTrabalhado.getDays() * 1440;
    System.out.println(horaLocal);
    return horaLocal;
}