Example usage for org.joda.time DateTime plusDays

List of usage examples for org.joda.time DateTime plusDays

Introduction

In this page you can find the example usage for org.joda.time DateTime plusDays.

Prototype

public DateTime plusDays(int days) 

Source Link

Document

Returns a copy of this datetime plus the specified number of days.

Usage

From source file:org.apache.isis.viewer.wicket.ui.components.scalars.jodatime.DateConverterForJodaDateTime.java

License:Apache License

@Override
protected String doConvertToString(DateTime value, Locale locale) {
    return value.plusDays(adjustBy).toString(getFormatterForDateTimePattern());
}

From source file:org.apache.pig.pen.AugmentBaseDataVisitor.java

License:Apache License

Object GetLargerValue(Object v) {
    byte type = DataType.findType(v);

    if (type == DataType.BAG || type == DataType.TUPLE || type == DataType.MAP)
        return null;

    switch (type) {
    case DataType.CHARARRAY:
        return (String) v + "0";
    case DataType.BYTEARRAY:
        String str = ((DataByteArray) v).toString();
        str = str + "0";
        return new DataByteArray(str);
    case DataType.INTEGER:
        return Integer.valueOf((Integer) v + 1);
    case DataType.LONG:
        return Long.valueOf((Long) v + 1);
    case DataType.FLOAT:
        return Float.valueOf((Float) v + 1);
    case DataType.DOUBLE:
        return Double.valueOf((Double) v + 1);
    case DataType.BIGINTEGER:
        return ((BigInteger) v).add(BigInteger.ONE);
    case DataType.BIGDECIMAL:
        return ((BigDecimal) v).add(BigDecimal.ONE);
    case DataType.DATETIME:
        DateTime dt = (DateTime) v;
        if (dt.getMillisOfSecond() != 0) {
            return dt.plusMillis(1);
        } else if (dt.getSecondOfMinute() != 0) {
            return dt.plusSeconds(1);
        } else if (dt.getMinuteOfHour() != 0) {
            return dt.plusMinutes(1);
        } else if (dt.getHourOfDay() != 0) {
            return dt.plusHours(1);
        } else {//from   w  w w.j a v a 2s  . c  om
            return dt.plusDays(1);
        }
    default:
        return null;
    }
}

From source file:org.apache.unomi.plugins.baseplugin.conditions.PropertyConditionESQueryBuilder.java

License:Apache License

private QueryBuilder getIsSameDayRange(Object value, String name) {
    DateTime date = new DateTime(value);
    DateTime dayStart = date.withTimeAtStartOfDay();
    DateTime dayAfterStart = date.plusDays(1).withTimeAtStartOfDay();
    return QueryBuilders.rangeQuery(name).gte(dayStart.toDate()).lte(dayAfterStart.toDate());
}

From source file:org.apereo.portal.events.aggr.AggregationIntervalHelperImpl.java

License:Apache License

/**
 * Return a sorted list of AcademicTermDetail objects where the the first element of the list
 * where the first element is the first term that starts after the specified start DateTime.
 *///from w w  w .jav a  2 s. c  o m
protected List<AcademicTermDetail> getAcademicTermsAfter(DateTime start) {
    final List<AcademicTermDetail> terms = this.eventAggregationManagementDao.getAcademicTermDetails();
    final int index = Collections.binarySearch(terms,
            new AcademicTermDetailImpl(start.toDateMidnight(), start.plusDays(1).toDateMidnight(), ""));
    if (index > 0) {
        return terms.subList(index, terms.size());
    } else if (index < 0) {
        return terms.subList(-(index + 1), terms.size());
    }
    return terms;
}

From source file:org.apereo.portal.portlets.activity.ActivityController.java

License:Apache License

private PortalActivity buildPortalActivity(PortletRequest request, int timeframe) {
    PortletPreferences prefs = request.getPreferences();
    DateTime begin, end;
    final AggregationInterval interval;
    final List<PortalGroupActivity> groupActivities = new ArrayList<PortalGroupActivity>();

    switch (timeframe) {
    case NOW: {//from w w w.  java 2  s.  com
        end = new DateTime();
        begin = end.minusHours(1);
        interval = AggregationInterval.FIVE_MINUTE;
        break;
    }
    case TODAY: {
        begin = new DateMidnight().toDateTime();
        end = begin.plusDays(1);
        interval = AggregationInterval.DAY;
        break;
    }
    case YESTERDAY: {
        end = new DateMidnight().toDateTime().minusSeconds(1);
        begin = end.minusDays(1);
        interval = AggregationInterval.DAY;
        break;
    }
    default: {
        end = new DateTime();
        begin = end.minusHours(1);
        interval = AggregationInterval.HOUR;
        break;
    }
    }

    String masterGroup = prefs.getValue(PREFERENCE_MASTER_GROUP, DEFAULT_PREFERENCE_MASTER_GROUP);
    List<String> displayGroups = Arrays
            .asList(prefs.getValues(PREFERENCE_DISPLAY_GROUPS, DEFAULT_PREFERENCE_DISPLAY_GROUPS));
    boolean displayOther = Boolean
            .valueOf(prefs.getValue(PREFERENCE_DISPLAY_OTHER, DEFAULT_PREFERENCE_DISPLAY_OTHER));
    int masterTotal = 0;
    int absTotal = 0;
    int subTotal = 0;

    switch (timeframe) {
    case NOW:
        for (AggregatedGroupMapping group : concurrentUserAggregationDao.getAggregatedGroupMappings()) {

            ConcurrentUserAggregationKey key = new ConcurrentUserAggregationKeyImpl(interval, group);
            final List<ConcurrentUserAggregation> aggregations = concurrentUserAggregationDao
                    .getAggregations(begin, end, key);

            // NB:  We only care about the most recent entry (??)
            if (aggregations.size() != 0) {
                final ConcurrentUserAggregation aggregation = aggregations.get(0);
                int groupTotal = aggregation.getConcurrentUsers();
                absTotal += aggregation.getConcurrentUsers();
                if (group.getGroupName().equalsIgnoreCase(masterGroup)) {
                    masterTotal = groupTotal;
                } else {
                    subTotal += groupTotal;
                }

                if (!group.getGroupName().equals(masterGroup)) {
                    if (displayGroups.isEmpty() || displayGroups.contains(group.getGroupName())) {
                        final PortalGroupActivity groupActivity = new PortalGroupActivity(group.getGroupName(),
                                groupTotal);
                        groupActivities.add(groupActivity);
                    }
                }
            }
        }
        break;
    default:
        String uniqueLoginsPref = prefs.getValue(PREFERENCE_UNIQUE_LOGINS, DEFAULT_PREFERENCE_UNIQUE_LOGINS);
        Boolean uniqueLogins = Boolean.valueOf(uniqueLoginsPref);

        for (AggregatedGroupMapping group : loginAggregationDao.getAggregatedGroupMappings()) {

            final LoginAggregationKey key = new LoginAggregationKeyImpl(interval, group);
            final List<LoginAggregation> aggregations = loginAggregationDao.getAggregations(begin, end, key);

            // NB:  We only care about the most recent entry (??)
            if (aggregations.size() != 0) {
                final LoginAggregation aggregation = aggregations.get(0);
                int groupTotal = getAggregationLoginCount(aggregation, uniqueLogins);
                absTotal += groupTotal;
                if (group.getGroupName().equalsIgnoreCase(masterGroup)) {
                    masterTotal = groupTotal;
                } else {
                    subTotal += groupTotal;
                }

                if (!group.getGroupName().equals(masterGroup)) {
                    if (displayGroups.isEmpty() || displayGroups.contains(group.getGroupName())) {
                        PortalGroupActivity groupActivity = new PortalGroupActivity(group.getGroupName(),
                                groupTotal);
                        groupActivities.add(groupActivity);
                    }
                }
            }
        }
        break;
    }

    if (displayOther) {
        int otherTotal = masterTotal - subTotal;
        if (otherTotal > 0) {
            PortalGroupActivity otherGroup = new PortalGroupActivity("Other", otherTotal);
            groupActivities.add(otherGroup);
        }
    }

    Collections.sort(groupActivities);
    Collections.reverse(groupActivities);
    int total = masterTotal > 0 ? masterTotal : absTotal;
    final PortalActivity activity = new PortalActivity(total, groupActivities);
    return activity;
}

From source file:org.artifactory.security.jobs.PasswordExpireNotificationJob.java

License:Open Source License

/**
 * Produces unique (per user) email body
 *
 * @param userName          user name//w w w .j ava  2  s.  c  o m
 * @param passwordCreated   the date when password was created
 * @param plainText         whether email should be send in plain text or html
 *
 * @return email body
 */
public String getMailBody(String userName, Long passwordCreated, boolean plainText) {
    DateTime created = new DateTime(passwordCreated);
    CentralConfigService centralConfigService = ContextHelper.get().beanForType(CentralConfigService.class);
    int expiresIn = centralConfigService.getMutableDescriptor().getSecurity().getPasswordSettings()
            .getExpirationPolicy().getPasswordMaxAge();
    DateTime now = DateTime.now();
    int daysLeft = created.plusDays(expiresIn).minusDays(now.getDayOfYear()).getDayOfYear();
    if ((daysLeft == 365 || daysLeft == 366) && created.plusDays(expiresIn).dayOfYear().get() != daysLeft)
        daysLeft = 0;
    DateTime dueDate = now.plusDays(daysLeft);

    if (daysLeft == 0) {
        if (!plainText)
            return String.format(
                    "<!DOCTYPE html>" + "<html>" + "<body>" + "<p>" + "Dear %s,<br><br>"
                            + "Your Artifactory password is about to expire today (%s).<br>"
                            + "Please change your password before it expires, "
                            + "Once expired you will not be able to  access the<br>"
                            + "Artifactory UI or REST API using that password until it will be changed.<br><br>"
                            + "Password can be changed in <a href=\"" + getProfilePageUrl()
                            + "\">your profile page</a> " + "or by your system administrator.<br><br>" + "</p>"
                            + "</body>" + "</html>",
                    userName.toUpperCase(), dueDate.toString("MMMMM dd, YYYY"));
        return String.format("Dear %s,\n" + "\n" + "Your Artifactory password is about to expire today (%s).\n"
                + "Please change your password before it expires. Once expired you will not be able to  access the\n"
                + "Artifactory UI or REST API using that password until it will be changed.\n" + "\n"
                + "Password can be changed in your page [1] or by your system administrator.\n\n" + "[1] "
                + getProfilePageUrl(), userName.toUpperCase(), dueDate.toString("MMMMM dd, YYYY"));
    } else {
        if (!plainText)
            return String.format("<!DOCTYPE html>" + "<html>" + "<body>" + "<p>" + "Dear %s,<br><br>"
                    + "Your Artifactory password is about to expire in %d " + (daysLeft == 1 ? "day" : "days")
                    + " (%s).<br>" + "Please change your password before it expires, "
                    + "Once expired you will not be able to  access the<br>"
                    + "Artifactory UI or REST API using that password until it will be changed.<br><br>"
                    + "Password can be changed in <a href=\"" + getProfilePageUrl()
                    + "\">your profile page</a> " + "or by your system administrator.<br><br>" + "</p>"
                    + "</body>" + "</html>", userName.toUpperCase(), daysLeft,
                    dueDate.toString("MMMMM dd, YYYY"));
        return String.format("Dear %s,\n" + "\n" + "Your Artifactory password is about to expire in %d "
                + (daysLeft == 1 ? "day" : "days") + " (%s).\n"
                + "Please change your password before it expires. Once expired you will not be able to  access the\n"
                + "Artifactory UI or REST API using that password until it will be changed.\n" + "\n"
                + "Password can be changed in your page [1] or by your system administrator.\n\n" + "[1] "
                + getProfilePageUrl(), userName.toUpperCase(), daysLeft, dueDate.toString("MMMMM dd, YYYY"));
    }
}

From source file:org.artifactory.security.SecurityServiceImpl.java

License:Open Source License

private Integer getDaysLeftUntilPasswordExpires(Long userPasswordCreationTime) {
    Integer daysLeft;/* www.  ja v a 2s  . c o m*/
    DateTime created = new DateTime(userPasswordCreationTime.longValue());
    int expiresIn = getPasswordExpirationDays();
    DateTime now = DateTime.now();
    daysLeft = created.plusDays(expiresIn).minusDays(now.getDayOfYear()).getDayOfYear();
    if ((daysLeft == 365 || daysLeft == 366) && created.plusDays(expiresIn).dayOfYear().get() != daysLeft) {
        daysLeft = 0;
    }
    return daysLeft;
}

From source file:org.artifactory.storage.db.security.service.UserGroupServiceImpl.java

License:Open Source License

/**
 * Checks whether user password is expired
 *
 * @param userName  a user name//from w w  w .  j  a va  2  s .  c o  m
 * @param expiresIn days for password to stay valid after creation
 * @return boolean
 */
@Override
public boolean isUserPasswordExpired(String userName, int expiresIn) {
    boolean isExpired = false;

    String passwordCreatedProperty = findUserProperty(userName, "passwordCreated");
    DateTime created = null;
    if (Strings.isNullOrEmpty(passwordCreatedProperty)) {
        log.debug("Password creation for user {} was not found, initiating default value (now)", userName);
        created = DateTime.now();
        addUserProperty(userName, "passwordCreated", Long.toString(created.getMillis()));
    } else {
        created = new DateTime(Long.valueOf(passwordCreatedProperty));
    }

    log.debug("Password creation for user {} is {}, password expires after {}", userName, created, expiresIn);
    if (isExpired = created.plusDays(expiresIn).isBeforeNow()) {
        log.debug("User {} credentials have expired (updating profile accordingly)", userName);
        expireUserPassword(userName);
    }

    // todo: [mp] set user.credentialsExpired=True if expired indeed

    return isExpired;
}

From source file:org.ash.history.CalendarH.java

License:Open Source License

/**
 * Get fragged days for Calendar.//  www .j  a  v a  2  s . co m
 * 
 * @param begin0
 * @param end0
 * @return
 */
private long[] getFraggedDays(long begin0, long end0) {

    DateTime begin = new DateTime(begin0);
    DateTime end = new DateTime(end0);

    DateTime beginTmp = new DateTime(begin);
    DateTime beginDayPlus0000 = new DateTime(beginTmp.getYear(), beginTmp.getMonthOfYear(),
            beginTmp.getDayOfMonth(), 0, 0, 0, 0);
    DateTime endTmp = new DateTime(end);
    DateTime endPlus2359 = new DateTime(endTmp.getYear(), endTmp.getMonthOfYear(), endTmp.getDayOfMonth(), 23,
            59, 59, 999);

    Interval interval = new Interval(beginDayPlus0000, endPlus2359);
    Days days = Days.daysIn(interval);

    int daysBetween = days.getDays();

    long[] flaggedDates = new long[daysBetween + 1];

    DateTime tmp = new DateTime(begin);
    // Load days.
    for (int i = 0; i <= daysBetween; i++) {
        DateTime tmp1 = tmp.plusDays(i);
        flaggedDates[i] = tmp1.getMillis();
    }

    return flaggedDates;
}

From source file:org.bensteele.jirrigate.Irrigator.java

License:Open Source License

/**
 * Returns the time and date the next irrigation is due based on the watering_days and
 * watering_start_time. It does not take into account whether or not any of the {@link Controller}
 * are active.//  ww  w.j  a  v a2 s .c  o  m
 *
 * @return The time and date of the next irrigation for any controller under this irrigator's
 * control.
 */
protected DateTime nextIrrigationAt() {
    DateTime dt = new DateTime();
    for (int i = 0; i < 7; i++) {
        for (final int dayOfWeek : wateringDays) {
            if (dayOfWeek == (dt.getDayOfWeek())) {
                // If it's the first run then we may match the same day we are currently on, in this case
                // we need to check that we don't report a time in the past. Validate that the hour and
                // minute right now are not past the scheduled watering time. If it's not the first run
                // then it's ok to let through.
                if (i != 0 || (i == 0 && dt.toLocalTime().isBefore(wateringStartTime))) {

                    // Reset the hour to 0 and increment until we match the watering hour.
                    dt = dt.withHourOfDay(0);
                    while (dt.getHourOfDay() < wateringStartTime.getHourOfDay()) {
                        dt = dt.plusHours(1);
                    }

                    // Reset the minute to 0 and increment until we match the watering minute.
                    dt = dt.withMinuteOfHour(0);
                    while (dt.getMinuteOfHour() < wateringStartTime.getMinuteOfHour()) {
                        dt = dt.plusMinutes(1);
                    }
                    return dt;
                }
            }
        }
        dt = dt.plusDays(1);
    }
    return null;
}