Example usage for org.joda.time Period getSeconds

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

Introduction

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

Prototype

public int getSeconds() 

Source Link

Document

Gets the seconds field part of the period.

Usage

From source file:BillionGraves.BillionGravesController.java

/**
 *
 * @param event/* ww  w .  j av a 2s .  co m*/
 * @throws SQLException
 */
@FXML
public void btnFileIngest(ActionEvent event) throws SQLException {

    long startTime = System.currentTimeMillis();
    //Truncate table is checkbox is selected
    if (chkBoxTruncate.isSelected() == true) {
        consoleItems.add("Truncating Load Table");
        lstConsole.setItems(consoleItems);
    }
    PPOFNLDataWriter truncateTable = new PPOFNLDataWriter(chkBoxTruncate.isSelected());

    System.out.println("Ingesting records");

    consoleItems.add("Ingesting records");
    lstConsole.setItems(consoleItems);
    //Start the data ingest
    for (int i = 0; i < (lstViewFiles.getItems().size()); i++) { //loop to process each selected file*********
        String hashKey = lstViewFiles.getItems().get(i).toString();
        selectFilePath = namePath.get(hashKey);

        String ingestTimeStamp = MiscUtilities.getTimeStamp();//set timestamp for record group field
        System.out.println("  --Ingesting " + selectFilePath);

        consoleItems.add("  --Ingesting " + selectFilePath);
        lstConsole.setItems(consoleItems);

        //get all the data one row at a time and treat        
        try {
            dataReader = new TextFileReader(selectFilePath, currentLine, ingestTimeStamp);

        } catch (IOException ex) {
            Logger.getLogger(BillionGravesController.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    PPOFNLDataWriter getGrossRecordCount = new PPOFNLDataWriter("GROSS");
    Map<String, Integer> grossCountMap = getGrossRecordCount.grossData;

    consoleItems.add("Removing Duplicate Records");
    lstConsole.setItems(consoleItems);
    PPOFNLDataWriter removeDupes = new PPOFNLDataWriter();//removes dupes and embedded characters from load table.

    consoleItems.add("Assigning Unique Identifiers and Creating Sort Keys");
    lstConsole.setItems(consoleItems);
    PPOFNLDataWriter assignUI = new PPOFNLDataWriter(chkBoxUI.isSelected(), "");//Not ready to use.

    Date endDate = new Date();

    PPOFNLDataWriter getNetRecordCount = new PPOFNLDataWriter("NET");
    Map<String, Integer> netCountMap = getNetRecordCount.netData;

    PPOFNLDataWriter writeLog = new PPOFNLDataWriter(grossCountMap, netCountMap, fileGroupIngestTimestamp);

    long endTime = System.currentTimeMillis();

    Interval interval = new Interval(startTime, endTime);
    Period period = interval.toPeriod();

    consoleItems.add("Total elaped time = " + StringUtils.leftPad(String.valueOf(period.getHours()), 2, "0")
            + ":" + StringUtils.leftPad(String.valueOf(period.getMinutes()), 2, "0") + ":"
            + StringUtils.leftPad(String.valueOf(period.getSeconds()), 2, "0"));
    lstConsole.setItems(consoleItems);

    System.out.println("Total elaped time = " + StringUtils.leftPad(String.valueOf(period.getHours()), 2, "0")
            + ":" + StringUtils.leftPad(String.valueOf(period.getMinutes()), 2, "0") + ":"
            + StringUtils.leftPad(String.valueOf(period.getSeconds()), 2, "0"));

}

From source file:br.inf.ufes.lar.thtbot.utils.TimeUtil.java

License:Open Source License

/**
 * Get the number of seconds elapsed between two Dates.
 *
 * @param startDate Start Date./*from   www.j a v  a  2 s .co m*/
 * @param endDate End Date.
 * @return Number of seconds elapsed between two Dates.
 * @see Date
 * @since 1.0
 */
public static int getSecondsElapsed(Date startDate, Date endDate) {
    Interval interval = new Interval(startDate.getTime(), endDate.getTime());
    Period period = interval.toPeriod();

    return period.getSeconds();
}

From source file:com.atlassian.theplugin.jira.model.ActiveJiraIssueBean.java

License:Apache License

public long recalculateTimeSpent() {
    DateTime now = new DateTime();
    if (!paused) {
        Period nextPeriod = new Period(lastStartTime, now, PeriodType.seconds());
        secondsSpent = secondsSpent + nextPeriod.getSeconds();
    }//from w  ww . ja  va  2 s  .  c om
    lastStartTime = now;
    return secondsSpent;
}

From source file:com.blackducksoftware.integration.jira.task.JiraTaskTimed.java

License:Apache License

@Override
public String call() throws Exception {
    logger.info("Running the Hub JIRA periodic timed task.");

    final JiraContext jiraContext = initJiraContext(configDetails.getJiraAdminUserName(),
            configDetails.getJiraIssueCreatorUserName());
    if (jiraContext == null) {
        logger.error(//from w w  w. ja  v  a2 s .  co  m
                "No (valid) user in configuration data; The plugin has likely not yet been configured; The task cannot run (yet)");
        return "error";
    }
    final DateTime beforeSetup = new DateTime();
    final TicketInfoFromSetup ticketInfoFromSetup = new TicketInfoFromSetup();
    try {
        jiraSetup(jiraServices, jiraSettingsService, configDetails.getProjectMappingJson(), ticketInfoFromSetup,
                jiraContext);
    } catch (final Exception e) {
        logger.error("Error during JIRA setup: " + e.getMessage() + "; The task cannot run", e);
        return "error";
    }
    final DateTime afterSetup = new DateTime();
    final Period diff = new Period(beforeSetup, afterSetup);
    logger.info("Hub JIRA setup took " + diff.getMinutes() + "m," + diff.getSeconds() + "s," + diff.getMillis()
            + "ms.");
    final HubJiraTask processor = new HubJiraTask(configDetails, jiraContext, jiraSettingsService,
            ticketInfoFromSetup);
    final String runDateString = processor.execute();
    if (runDateString != null) {
        settings.put(HubJiraConfigKeys.HUB_CONFIG_LAST_RUN_DATE, runDateString);
    }
    logger.info("hub-jira periodic timed task has completed");
    return "success";
}

From source file:com.github.dbourdette.glass.tools.UtilsTool.java

License:Apache License

public String duration(Date start, Date end) {
    Period period = new Period(start.getTime(), end.getTime());

    StringBuilder builder = new StringBuilder();

    appendDuration(builder, period.getDays(), "d");
    appendDuration(builder, period.getHours(), "h");
    appendDuration(builder, period.getMinutes(), "m");
    appendDuration(builder, period.getSeconds(), "s");

    return builder.toString().trim();
}

From source file:com.github.jobs.utils.RelativeDate.java

License:Apache License

/**
 * This method returns a String representing the relative
 * date by comparing the Calendar being passed in to the
 * date / time that it is right now.// w w  w .j a v a 2s .  com
 *
 * @param context used to build the string response
 * @param time    time to compare with current time
 * @return a string representing the time ago
 */
public static String getTimeAgo(Context context, long time) {
    DateTime baseDate = new DateTime(time);
    DateTime now = new DateTime();
    Period period = new Period(baseDate, now);

    if (period.getSeconds() < 0 || period.getMinutes() < 0) {
        return context.getString(R.string.just_now);
    }

    if (period.getYears() > 0) {
        int resId = period.getYears() == 1 ? R.string.one_year_ago : R.string.years_ago;
        return buildString(context, resId, period.getYears());
    }

    if (period.getMonths() > 0) {
        int resId = period.getMonths() == 1 ? R.string.one_month_ago : R.string.months_ago;
        return buildString(context, resId, period.getMonths());
    }

    if (period.getWeeks() > 0) {
        int resId = period.getWeeks() == 1 ? R.string.one_week_ago : R.string.weeks_ago;
        return buildString(context, resId, period.getWeeks());
    }

    if (period.getDays() > 0) {
        int resId = period.getDays() == 1 ? R.string.one_day_ago : R.string.days_ago;
        return buildString(context, resId, period.getDays());
    }

    if (period.getHours() > 0) {
        int resId = period.getHours() == 1 ? R.string.one_hour_ago : R.string.hours_ago;
        return buildString(context, resId, period.getHours());
    }

    if (period.getMinutes() > 0) {
        int resId = period.getMinutes() == 1 ? R.string.one_minute_ago : R.string.minutes_ago;
        return buildString(context, resId, period.getMinutes());
    }

    int resId = period.getSeconds() == 1 ? R.string.one_second_ago : R.string.seconds_ago;
    return buildString(context, resId, period.getSeconds());
}

From source file:com.google.livingstories.server.util.TimeUtil.java

License:Apache License

/**
 * Return a String representation of the time that has passed from the given time to
 * right now./*from  w  w w. j  ava  2s . c o  m*/
 * This method returns an approximate user-friendly duration. Eg. If 2 months, 12 days and 4 hours
 * have passed, the method will return "2 months ago".
 * TODO: the results of this method need to be internationalized
 */
public static String getElapsedTimeString(Date updateCreationTime) {
    Period period = new Period(updateCreationTime.getTime(), new Date().getTime(),
            PeriodType.yearMonthDayTime());

    int years = period.getYears();
    int months = period.getMonths();
    int days = period.getDays();
    int hours = period.getHours();
    int minutes = period.getMinutes();
    int seconds = period.getSeconds();

    String timeLabel = "";

    if (years > 0) {
        timeLabel = years == 1 ? " year " : " years ";
        return "" + years + timeLabel + "ago";
    } else if (months > 0) {
        timeLabel = months == 1 ? " month " : " months ";
        return "" + months + timeLabel + "ago";
    } else if (days > 0) {
        timeLabel = days == 1 ? " day " : " days ";
        return "" + days + timeLabel + "ago";
    } else if (hours > 0) {
        timeLabel = hours == 1 ? " hour " : " hours ";
        return "" + hours + timeLabel + "ago";
    } else if (minutes > 0) {
        timeLabel = minutes == 1 ? " minute " : " minutes ";
        return "" + minutes + timeLabel + "ago";
    } else if (seconds > 0) {
        timeLabel = seconds == 1 ? " second " : " seconds ";
        return "" + seconds + timeLabel + "ago";
    } else {
        return "1 second ago";
    }
}

From source file:com.jajja.jorm.mixins.Postgres.java

License:Open Source License

public static PGInterval toInterval(Period period) {
    if (period == null) {
        return null;
    }//from  w  ww  .  j a  va2s . co m
    return new PGInterval(period.getYears(), period.getMonths(), period.getDays(), period.getHours(),
            period.getMinutes(), period.getSeconds() + (double) period.getMillis() / 1000);
}

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

License:Apache License

/**
 * Adds adjustment to the shortest set time range in period. E.g.
 *  period("5 days 3 hours", 1) -> "5 days 4 hours". This will fall
 *  back to adjusting years if no field in the period is set.
 * @param period The period to be adjusted
 * @param adjustment The adjustment. Note that positive values will result
 *                   in larger periods and an earlier time
 * @return The adjusted period//from   w  w w  .  j  a v  a 2 s  .c o m
 */
private Period adjust(final Period period, int adjustment) {
    if (adjustment == 0)
        return period;

    // Order is VERY important here
    LinkedHashMap<Integer, DurationFieldType> map = new LinkedHashMap<>();
    map.put(period.getSeconds(), DurationFieldType.seconds());
    map.put(period.getMinutes(), DurationFieldType.minutes());
    map.put(period.getHours(), DurationFieldType.hours());
    map.put(period.getDays(), DurationFieldType.days());
    map.put(period.getWeeks(), DurationFieldType.weeks());
    map.put(period.getMonths(), DurationFieldType.months());
    map.put(period.getYears(), DurationFieldType.years());

    for (Map.Entry<Integer, DurationFieldType> entry : map.entrySet()) {
        if (entry.getKey() > 0) {
            return period.withFieldAdded(entry.getValue(), adjustment);
        }
    }
    // Fall back to modifying years
    return period.withFieldAdded(DurationFieldType.years(), adjustment);
}

From source file:com.microsoft.azure.management.servicebus.implementation.TimeSpan.java

License:Open Source License

/**
 * Gets TimeSpan from given period./*from  ww w  . j av  a 2s. c  o m*/
 *
 * @param period duration in period format
 * @return TimeSpan
 */
public static TimeSpan fromPeriod(Period period) {
    // Normalize (e.g. move weeks to hour part)
    //
    Period p = new Period(period.toStandardDuration().getMillis());
    return TimeSpan
            .parse((new TimeSpan().withDays(p.getDays()).withHours(p.getHours()).withMinutes(p.getMinutes())
                    .withSeconds(p.getSeconds()).withMilliseconds(p.getMillis())).toString());
}