Example usage for org.joda.time DateTime minus

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

Introduction

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

Prototype

public DateTime minus(ReadablePeriod period) 

Source Link

Document

Returns a copy of this datetime with the specified period taken away.

Usage

From source file:com.jbirdvegas.mgerrit.search.AgeSearch.java

License:Apache License

@Override
public String[] getEscapeArgument() {
    DateTime now = new DateTime();
    Period period = mPeriod;/*from  w w w  .j  a  v a 2s  . co  m*/

    // Equals: we need to do some arithmetic to get a range from the period
    if ("=".equals(getOperator())) {
        if (period == null) {
            period = new Period(mInstant, Instant.now());
        }
        DateTime earlier = now.minus(adjust(period, +1));
        DateTime later = now.minus(period);
        return new String[] { earlier.toString(), later.toString() };
    } else {
        if (period == null) {
            return new String[] { mInstant.toString() };
        }
        return new String[] { now.minus(period).toString() };
    }
}

From source file:com.jbirdvegas.mgerrit.search.AgeSearch.java

License:Apache License

@Override
public String getGerritQuery(ServerVersion serverVersion) {
    String operator = getOperator();

    if ("<=".equals(operator) || "<".equals(operator)) {
        return BeforeSearch._getGerritQuery(this, serverVersion);
    } else if (">=".equals(operator) || ">".equals(operator)) {
        return AfterSearch._getGerritQuery(this, serverVersion);
    }//from   w w w.  j  av  a2s  . co  m

    if (serverVersion != null && serverVersion.isFeatureSupported(ServerVersion.VERSION_BEFORE_SEARCH)
            && mInstant != null) {
        // Use a combination of before and after to get an interval
        if (mPeriod == null) {
            mPeriod = new Period(mInstant, Instant.now());
        }
        DateTime now = new DateTime();
        DateTime earlier = now.minus(adjust(mPeriod, +1));
        DateTime later = now.minus(mPeriod);

        SearchKeyword newer = new AfterSearch(earlier.toString());
        SearchKeyword older = new BeforeSearch(later.toString());
        return newer.getGerritQuery(serverVersion) + "+" + older.getGerritQuery(serverVersion);
    } else {
        // Need to leave off the operator and make sure we are using relative format
        /* Gerrit only supports specifying one time unit, so we will normalize the period
         *  into days.  */
        return OP_NAME + ":" + String.valueOf(toDays()) + "d";
    }
}

From source file:com.manydesigns.portofino.pageactions.calendar.AgendaView.java

License:Open Source License

public int addEvent(Event event) {
    DateMidnight day = new DateMidnight(event.getInterval().getStart());
    DateTime end = event.getInterval().getEnd();
    int added = 0;
    while (end.minus(1).compareTo(day) >= 0) {
        if (addEvent(day, event)) {
            added++;//  w w w  . j a v  a2  s  . com
        }
        day = day.plusDays(1);
    }
    return added;
}

From source file:com.marklogic.samplestack.dbclient.DateFacetBuilder.java

License:Apache License

public static ObjectNode dateFacet(DateTime min, DateTime max) {
    DateFacetBuilder fb = new DateFacetBuilder(new CustomObjectMapper());
    fb.name("date");
    /*//from  w w w .  ja v  a 2s .  co  m
    long interval = max.getMillis() - min.getMillis();
    if (interval / BucketInterval.BY_DAY.bucketDuration() < 40) {
       fb.period("DAY");
       DateTime bucketStart = min.minus(min.getMillisOfDay());
       while (bucketStart.isBefore(max)) {
    DateTime bucketEnd = bucketStart.plusDays(1);
    fb.bucket(bucketStart, bucketEnd);
    bucketStart = bucketStart.plusDays(1);
       }
    }
    else if (interval / BucketInterval.BY_WEEK.bucketDuration() < 40) {
       fb.period("WEEK");
       DateTime bucketStart = min.minusDays(min.getDayOfWeek()).minus(min.getMillisOfDay());
       while (bucketStart.isBefore(max)) {
    DateTime bucketEnd = bucketStart.plusWeeks(1);
    fb.bucket(bucketStart, bucketEnd);
    bucketStart = bucketStart.plusWeeks(1);
       }
    } else {
    */
    // for 8.0-1 we are only doing facets by month
    fb.period("MONTH");
    DateTime bucketStart = min.minusDays(min.getDayOfMonth() - 1).minus(min.getMillisOfDay());
    bucketStart = new DateTime(bucketStart);
    while (bucketStart.isBefore(max)) {
        DateTime bucketEnd = bucketStart.plusMonths(1);
        fb.bucket(bucketStart, bucketEnd);
        bucketStart = bucketStart.plusMonths(1);
    }
    // }
    return fb.facetNode;
}

From source file:com.metamx.common.Granularity.java

License:Apache License

public final DateTime decrement(DateTime time) {
    return time.minus(getUnits(1));
}

From source file:com.metamx.common.Granularity.java

License:Apache License

public final DateTime decrement(DateTime time, int count) {
    return time.minus(getUnits(count));
}

From source file:com.mirth.connect.server.util.PasswordRequirementsChecker.java

License:Open Source License

public Calendar getLastExpirationDate(PasswordRequirements passwordRequirements) {
    DateTime dateTime = new DateTime();

    // Must keep all passwords if reuse period is -1 (infinite) or reuse limit is set
    if ((passwordRequirements.getReusePeriod() == -1) || passwordRequirements.getReuseLimit() != 0) {
        return null;
    }//from  ww  w  .  ja  v a  2s . com

    if (passwordRequirements.getReusePeriod() == 0) {
        return Calendar.getInstance();
    }

    return dateTime.minus(Duration.standardDays(passwordRequirements.getReusePeriod()))
            .toCalendar(Locale.getDefault());
}

From source file:com.ning.billing.util.clock.ClockMock.java

License:Apache License

private DateTime truncate(final DateTime time) {
    return time.minus(time.getMillisOfSecond());
}

From source file:com.ning.billing.util.clock.DefaultClock.java

License:Apache License

public static DateTime truncateMs(final DateTime input) {
    return input.minus(input.getMillisOfSecond());
}

From source file:com.ning.metrics.collector.processing.quartz.CounterEventCleanUpJob.java

License:Apache License

@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
    log.info("Starting clean up of expired rolled up counters");
    DateTime toDateTime = new DateTime(DateTimeZone.UTC);

    int deletedRolledUpEvents = counterStorage.cleanExpiredDailyRolledUpCounters(
            toDateTime.minus(config.getRolledUpCounterStorageTimeout().getMillis()));
    log.info(String.format("Deleted %d rolledup events", deletedRolledUpEvents));
    log.info("Expired roll up counter event clean up done");
}