Example usage for org.joda.time DateTime plusMillis

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

Introduction

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

Prototype

public DateTime plusMillis(int millis) 

Source Link

Document

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

Usage

From source file:es.usc.citius.servando.calendula.scheduling.AlarmScheduler.java

License:Open Source License

public static boolean isWithinDefaultMargins(DateTime t, Context cxt) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(cxt);
    String delayMinutesStr = prefs.getString("alarm_reminder_window", "60");
    long window = Long.parseLong(delayMinutesStr);
    DateTime now = DateTime.now();// w ww .  j ava  2s  . c  om
    return t.isBefore(now) && t.plusMillis((int) window * 60 * 1000).isAfter(now);
}

From source file:fast.bats.europe.FastPitchMessage.java

License:Apache License

public DateTime getDateTime() {
    DateTimeZone timeZone = DateTimeZone.forID("Europe/London");
    DateTime midnight = new DateTime(timeZone).toDateMidnight().toDateTime();
    return midnight.plusMillis((int) getTimestamp());
}

From source file:fi.hsl.parkandride.core.domain.prediction.UtilizationHistoryImpl.java

License:EUPL

@Override
public CloseableIterator<Utilization> getUpdatesSince(DateTime startExclusive) {
    DateTime start = startExclusive.plusMillis(1);
    DateTime end = new DateTime().plusYears(1);
    return utilizationRepository.findUtilizationsBetween(utilizationKey, start, end);
}

From source file:fr.amap.commons.animation.Timeline.java

public void start() {

    fireStarted();//  w  w w . j a  va 2 s .  c o  m

    DateTime currentTime = new DateTime(startTime);
    int lastDoy = currentTime.getDayOfYear();

    fireTimeChanged(currentTime);
    fireDoyChanged(currentTime);

    while (currentTime.compareTo(endTime) <= 0) {
        currentTime = currentTime.plusMillis((int) (timeStep * 3600 * 1000));

        if (currentTime.compareTo(endTime) > 0) {
            break;
        }

        if (currentTime.getDayOfYear() != lastDoy) {

            lastDoy = currentTime.getDayOfYear();
            fireDoyChanged(currentTime);
        }

        fireTimeChanged(currentTime);
    }

    fireFinished();
}

From source file:google.registry.backup.CommitLogCheckpointStrategy.java

License:Open Source License

/**
 * Returns a threshold value defined as the latest timestamp that is before all new commit logs,
 * where "new" means having a commit time after the per-bucket timestamp in the given map.
 * When no such commit logs exist, the threshold value is set to END_OF_TIME.
 *//*from  ww  w  .ja  v  a2s. c  om*/
@VisibleForTesting
DateTime readNewCommitLogsAndFindThreshold(ImmutableMap<Integer, DateTime> bucketTimes) {
    DateTime timeBeforeAllNewCommits = END_OF_TIME;
    for (Entry<Integer, DateTime> entry : bucketTimes.entrySet()) {
        Key<CommitLogBucket> bucketKey = getBucketKey(entry.getKey());
        DateTime bucketTime = entry.getValue();
        // Add 1 to handle START_OF_TIME since 0 isn't a valid id - filter then uses >= instead of >.
        Key<CommitLogManifest> keyForFilter = Key
                .create(CommitLogManifest.create(bucketKey, bucketTime.plusMillis(1), null));
        List<Key<CommitLogManifest>> manifestKeys = ofy.load().type(CommitLogManifest.class).ancestor(bucketKey)
                .filterKey(">=", keyForFilter).limit(1).keys().list();
        if (!manifestKeys.isEmpty()) {
            timeBeforeAllNewCommits = earliestOf(timeBeforeAllNewCommits,
                    CommitLogManifest.extractCommitTime(getOnlyElement(manifestKeys)).minusMillis(1));
        }
    }
    return timeBeforeAllNewCommits;
}

From source file:google.registry.backup.ExportCommitLogDiffAction.java

License:Open Source License

/**
 * Loads the diff keys for one bucket.//from  www .  j av a 2 s .  c  om
 *
 * @param lowerCheckpoint exclusive lower bound on keys in this diff, or null if no lower bound
 * @param upperCheckpoint inclusive upper bound on keys in this diff
 * @param bucketNum the bucket to load diff keys from
 */
private Iterable<Key<CommitLogManifest>> loadDiffKeysFromBucket(@Nullable CommitLogCheckpoint lowerCheckpoint,
        CommitLogCheckpoint upperCheckpoint, int bucketNum) {
    // If no lower checkpoint exists, use START_OF_TIME as the effective exclusive lower bound.
    DateTime lowerCheckpointBucketTime = lowerCheckpoint == null ? START_OF_TIME
            : lowerCheckpoint.getBucketTimestamps().get(bucketNum);
    // Since START_OF_TIME=0 is not a valid id in a key, add 1 to both bounds. Then instead of
    // loading lowerBound < x <= upperBound, we can load lowerBound <= x < upperBound.
    DateTime lowerBound = lowerCheckpointBucketTime.plusMillis(1);
    DateTime upperBound = upperCheckpoint.getBucketTimestamps().get(bucketNum).plusMillis(1);
    // If the lower and upper bounds are equal, there can't be any results, so skip the query.
    if (lowerBound.equals(upperBound)) {
        return ImmutableSet.of();
    }
    Key<CommitLogBucket> bucketKey = getBucketKey(bucketNum);
    return ofy().load().type(CommitLogManifest.class).ancestor(bucketKey)
            .filterKey(">=", CommitLogManifest.createKey(bucketKey, lowerBound))
            .filterKey("<", CommitLogManifest.createKey(bucketKey, upperBound)).keys();
}

From source file:google.registry.tools.GenerateLordnCommand.java

License:Open Source License

@Override
public void run() throws IOException {
    DateTime now = DateTime.now(UTC);
    ImmutableList.Builder<String> claimsCsv = new ImmutableList.Builder<>();
    ImmutableList.Builder<String> sunriseCsv = new ImmutableList.Builder<>();
    for (DomainResource domain : ofy().load().type(DomainResource.class).filter("tld", tld)) {
        String status = " ";
        if (domain.getLaunchNotice() == null && domain.getSmdId() != null) {
            sunriseCsv.add(LordnTask.getCsvLineForSunriseDomain(domain, domain.getCreationTime()));
            status = "S";
        } else if (domain.getLaunchNotice() != null || domain.getSmdId() != null) {
            claimsCsv.add(LordnTask.getCsvLineForClaimsDomain(domain, domain.getCreationTime()));
            status = "C";
        }/*w w  w.  j a v  a  2 s  .  co  m*/
        System.out.printf("%s[%s] ", domain.getFullyQualifiedDomainName(), status);
    }
    ImmutableList<String> claimsRows = claimsCsv.build();
    ImmutableList<String> claimsAll = new ImmutableList.Builder<String>()
            .add(String.format("1,%s,%d", now, claimsRows.size())).add(LordnTask.COLUMNS_CLAIMS)
            .addAll(claimsRows).build();
    ImmutableList<String> sunriseRows = sunriseCsv.build();
    ImmutableList<String> sunriseAll = new ImmutableList.Builder<String>()
            .add(String.format("1,%s,%d", now.plusMillis(1), sunriseRows.size())).add(LordnTask.COLUMNS_SUNRISE)
            .addAll(sunriseRows).build();
    Files.write(claimsOutputPath, claimsAll, UTF_8);
    Files.write(sunriseOutputPath, sunriseAll, UTF_8);
}

From source file:io.tilt.minka.business.follower.Follower.java

License:Apache License

private void certifyClearance() {
    boolean lost = false;
    final Clearance clear = leaderConsumer.getLastClearance();
    long delta = 0;
    int maxAbsence = config.getFollowerClearanceMaxAbsenceMs();
    if (clear != null) {
        firstClearanceGot = true;/*w  ww.j ava 2 s. c om*/
        final DateTime now = new DateTime(DateTimeZone.UTC);
        final DateTime lastClearanceDate = clear.getCreation();
        lost = lastClearanceDate.plusMillis(maxAbsence).isBefore(now);
        delta = now.getMillis() - lastClearanceDate.getMillis();
    }
    if (firstClearanceGot) {
        if (lost) {
            logger.error("{}: ({}) Executing Clearance policy, last: {} too old (Max: {}, Past: {} msecs)",
                    getClass().getSimpleName(), config.getResolvedShardId(),
                    clear != null ? clear.getCreation() : "null", maxAbsence, delta);
            leaderConsumer.getPartitionManager().releaseAllCausePolicies();
        } else {
            logger.debug("{}: ({}) Clearence certified #{} from Leader: {}", getClass().getSimpleName(),
                    config.getResolvedShardId(), clear.getSequenceId(), clear.getLeaderShardId());
        }
    }
}

From source file:jais.readers.AISSocketReader.java

License:Apache License

/**
 * //  www.  ja  v  a2s  . com
 * @throws jais.readers.AISReaderException
 */
@Override
public void read() throws AISReaderException {

    try (InputStream is = _s.getInputStream();
            BufferedInputStream bis = new BufferedInputStream(is, _bufferSize);
            InputStreamReader isr = new InputStreamReader(bis);
            BufferedReader br = new BufferedReader(isr, _bufferSize)) {
        LOG.info("Reading...");

        DateTime lastRead = DateTime.now();

        while (super._shouldRun && _s.isConnected() && !_s.isInputShutdown()) {
            try {
                if (lastRead.plusMillis(_timeout).isBeforeNow())
                    throw new AISReaderException("Reader timed out!  No new data in " + _timeout + "ms.");

                String line = br.readLine();
                if (line != null && !line.isEmpty()) {
                    super.processPacketString(line);
                    lastRead = DateTime.now();
                }
            } catch (AISPacketException ae) {
                LOG.debug("Encountered an AISException: " + ae.getMessage(), ae);
            } catch (IOException ioe) {
                LOG.error("Encountered an IOException: " + ioe.getMessage(), ioe);
                throw new AISReaderException("Encountered an IOException: " + ioe.getMessage(), ioe);
            }
        }
    } catch (IOException ioe) {
        throw new AISReaderException("Unable to read from socket: " + ioe.getMessage(), ioe);
    } finally {
        try {
            LOG.error("Socket is no longer valid.  Closing.");
            _s.close();
        } catch (IOException ioe) {
            // do nothing
        }
    }

    LOG.fatal("Read terminated.");
}

From source file:jp.furplag.util.time.DateTimeUtils.java

License:Apache License

/**
 * calculate Chronological Julian Day represented by specified instant.
 *
 * @param instant/*from  w  w  w.j a  v  a  2  s . co  m*/
 * @param zone
 * @return
 */
public static double toCJD(final Object instant, final DateTimeZone zone) {
    DateTime then = toDT(instant, zone);

    return toAJD(then.plusMillis(zone.getOffset(then))) + .5d;
}