Example usage for org.joda.time Seconds secondsBetween

List of usage examples for org.joda.time Seconds secondsBetween

Introduction

In this page you can find the example usage for org.joda.time Seconds secondsBetween.

Prototype

public static Seconds secondsBetween(ReadablePartial start, ReadablePartial end) 

Source Link

Document

Creates a Seconds representing the number of whole seconds between the two specified partial datetimes.

Usage

From source file:org.encuestame.utils.DateUtil.java

License:Apache License

/**
 * Get Seconds Between Dates./*from ww  w .  ja v  a 2  s  .  co m*/
 * @param initDate
 * @return
 */
public static Integer getSecondsBetweenDates(final Date startDate) {
    final DateTime currentDate = new DateTime();
    final DateTime storedDate = new DateTime(startDate);
    final Seconds secondsBetween = Seconds.secondsBetween(storedDate, currentDate);
    return secondsBetween.getSeconds();
}

From source file:org.estatio.services.scheduler.work.ScheduledWorkItem.java

License:Apache License

/**
 * Number of seconds taken for this work item to complete.
 * @return//from  w ww  . jav a  2 s  .  c o m
 */
@javax.jdo.annotations.Column(allowsNull = "true")
public Integer getDuration() {
    if (getStartedAt() == null || getCompletedAt() == null) {
        return null;
    }
    Seconds seconds = Seconds.secondsBetween(getStartedAt(), getCompletedAt());
    return seconds.getSeconds();
}

From source file:org.graylog2.alerts.AlertServiceImpl.java

License:Open Source License

@Override
public int triggeredSecondsAgo(String streamId, String conditionId) {
    DBObject query = QueryBuilder.start("stream_id").is(streamId).and("condition_id").is(conditionId).get();
    BasicDBObject sort = new BasicDBObject("triggered_at", -1);

    DBObject alert = findOne(AlertImpl.class, query, sort);

    if (alert == null) {
        return -1;
    }//from  w  w  w.j a  va 2 s  .c  om

    DateTime triggeredAt = new DateTime(alert.get("triggered_at"), DateTimeZone.UTC);

    return Seconds.secondsBetween(triggeredAt, Tools.iso8601()).getSeconds();
}

From source file:org.graylog2.indexer.searches.timeranges.TimeRanges.java

License:Open Source License

/**
 * Calculate the number of seconds in the given time range.
 *
 * @param timeRange the {@link TimeRange}
 * @return the number of seconds in the given time range or 0 if an error occurred.
 *//*  w  w w.  jav  a  2 s  . c  om*/
public static int toSeconds(TimeRange timeRange) {
    if (timeRange.getFrom() == null || timeRange.getTo() == null) {
        return 0;
    }

    try {
        return Seconds.secondsBetween(timeRange.getFrom(), timeRange.getTo()).getSeconds();
    } catch (IllegalArgumentException e) {
        return 0;
    }
}

From source file:org.icgc.dcc.portal.auth.openid.DistributedConsumerAssociationStore.java

License:Open Source License

/**
 * Sets association time-to-live(TTL) to maximum of all received so far plus <tt>EXTRA_TTL_TIME</tt>.
 *//* w w  w.j  a v a 2 s .c o m*/
private void configureRetentionPolicy(Date expiryDate) {
    val newExpiryDate = Seconds.secondsBetween(new DateTime(expiryDate), new DateTime()).getSeconds();
    if (newExpiryDate > mapConfig.getTimeToLiveSeconds()) {
        mapConfig.setTimeToLiveSeconds(newExpiryDate + EXTRA_TTL_TIME_SECONDS);
    }
}

From source file:org.jarvis.core.services.CoreSunsetSunrise.java

License:Apache License

/**
 * get next sunset in millis//from   ww w  .  j  a  v a 2 s .c  om
 * @param lat
 * @param lng
 * @return long
 */
public long getNextSunrise(String lat, String lng) {
    SunApiRest time = get(lat, lng);
    Seconds seconds = Seconds.secondsBetween(DateTime.now(), time.sunrise);
    return seconds.getSeconds() * 1000L;
}

From source file:org.jarvis.core.services.CoreSunsetSunrise.java

License:Apache License

/**
 * get next sunset in millis/* w  ww . j  a  va  2 s.c  om*/
 * @param lat
 * @param lng
 * @return long
 */
public long getNextSunset(String lat, String lng) {
    SunApiRest time = get(lat, lng);
    Seconds seconds = Seconds.secondsBetween(DateTime.now(), time.sunset);
    return seconds.getSeconds() * 1000L;
}

From source file:org.jboss.drools.guvnor.importgenerator.ImportFileGenerator.java

License:Apache License

public void run(CmdArgsParser options) {
    try {/*from www  . java  2s.c  o  m*/
        SimpleDateFormat fmt = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
        Date startd = new Date();
        DateTime start = new DateTime(startd);
        this.options = options;
        BASE_DIR = options.getOption(Parameters.OPTIONS_BASE_DIR);
        logger.debug("Running BRMS Import Generator (started " + fmt.format(startd) + "):");

        logger.debug("Scanning directories...");
        Map<String, PackageFile> details = PackageFile.buildPackages(options);

        logger.debug("Generating 'Guvnor import data'...");
        String guvnorImport = generateImportFile(details);
        File guvnorImportFile = getFile(options.getOption(Parameters.OPTIONS_OUTPUT_FILE));
        logger.debug("Writing 'Guvnor import data to disk' (" + guvnorImportFile.getAbsolutePath() + ")");
        FileIOHelper.write(guvnorImport, guvnorImportFile);

        if (options.getOption(Parameters.OPTIONS_KAGENT_CHANGE_SET_FILE) != null) {
            logger.debug("Generating 'Knowledge agent changeset' data...");
            String kagentChangeSet = generateKnowledgeAgentInitFile(details);
            File kagentChangeSetFile = getFile(options.getOption(Parameters.OPTIONS_KAGENT_CHANGE_SET_FILE));
            logger.debug("Writing 'Knowledge agent changeset' to disk (" + kagentChangeSetFile.getAbsolutePath()
                    + ")");
            FileIOHelper.write(kagentChangeSet, kagentChangeSetFile);
        }

        DateTime end = new DateTime(System.currentTimeMillis());
        int m = Minutes.minutesBetween(start, end).getMinutes();
        int s = Seconds.secondsBetween(start, end).getSeconds() - (m * 60);
        logger.debug("Finished in (" + m + "m" + s + "s)");
    } catch (IOException e) {
        logger.error("", e);
    }
}

From source file:org.jhub1.agent.statistics.SmartDateDisplay.java

License:Open Source License

public static String showHowLong(DateTime rDate) {
    StringBuilder sb = new StringBuilder();
    DateTime dt = new DateTime();
    Weeks w = Weeks.weeksBetween(rDate, dt);
    Days d = Days.daysBetween(rDate, dt);
    Hours h = Hours.hoursBetween(rDate, dt);
    Minutes m = Minutes.minutesBetween(rDate, dt);
    Seconds s = Seconds.secondsBetween(rDate, dt);
    if (s.getSeconds() != 0) {
        sb.append(s.getSeconds() % 60).append("s");
    }// w  w  w . j a v  a2  s .c  o m
    if (m.getMinutes() != 0) {
        sb.insert(0, (m.getMinutes() % 60) + "m ");
    }
    if (h.getHours() != 0) {
        sb.insert(0, (h.getHours() % 24) + "h ");
    }
    if (d.getDays() != 0) {
        sb.insert(0, (d.getDays() % 7) + "d ");
    }
    if (w.getWeeks() != 0) {
        sb.insert(0, w.getWeeks() + "w ");
    }
    return sb.toString();
}

From source file:org.jpmml.evaluator.SecondsSinceDate.java

License:Open Source License

public SecondsSinceDate(LocalDate epoch, LocalDateTime dateTime) {
    setEpoch(epoch);//from w w  w . j av  a  2s. c o m

    // Have to have the same set of fields
    LocalDateTime epochDateTime = new LocalDateTime(epoch.getYear(), epoch.getMonthOfYear(),
            epoch.getDayOfMonth(), 0, 0, 0);

    setSeconds(Seconds.secondsBetween(epochDateTime, dateTime));
}