Example usage for org.joda.time Interval toPeriod

List of usage examples for org.joda.time Interval toPeriod

Introduction

In this page you can find the example usage for org.joda.time Interval toPeriod.

Prototype

public Period toPeriod() 

Source Link

Document

Converts the duration of the interval to a Period using the All period type.

Usage

From source file:BillionGraves.BillionGravesController.java

/**
 *
 * @param event/*w w  w .java 2  s  .  c  o  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 days elapsed between two Dates.
 *
 * @param startDate Start Date./* ww w. j a va2  s.co  m*/
 * @param endDate End Date.
 * @return Number of days elapsed between two Dates.
 * @see Date
 * @since 1.0
 */
public static int getDaysElapsed(Date startDate, Date endDate) {
    Interval interval = new Interval(startDate.getTime(), endDate.getTime());
    Period period = interval.toPeriod();

    return period.getDays();
}

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

License:Open Source License

/**
 * Get the number of hours elapsed between two Dates.
 *
 * @param startDate Start Date.//  w  w w  . j a v  a2s.  c om
 * @param endDate End Date.
 * @return Number of hours elapsed between two Dates.
 * @see Date
 * @since 1.0
 */
public static int getHoursElapsed(Date startDate, Date endDate) {
    Interval interval = new Interval(startDate.getTime(), endDate.getTime());
    Period period = interval.toPeriod();

    return period.getHours();
}

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

License:Open Source License

/**
 * Get the number of minutes elapsed between two Dates.
 *
 * @param startDate Start Date./*from  ww w  . j  ava2 s .c  o  m*/
 * @param endDate End Date.
 * @return Number of minutes elapsed between two Dates.
 * @see Date
 * @since 1.0
 */
public static int getMinutesElapsed(Date startDate, Date endDate) {
    Interval interval = new Interval(startDate.getTime(), endDate.getTime());
    Period period = interval.toPeriod();

    return period.getMinutes();
}

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  w ww  . j  av  a  2s . c  o 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:Dialogos.RetiroDialogo.java

/**
 * Creates new form RetiroDialogo/* ww  w.  j  a  va2s .c  o  m*/
 */
public RetiroDialogo(java.awt.Frame parent, boolean modal, Cupo cupo) {
    super(parent, modal);
    initComponents();
    this.cupo = cupo;
    this.setLocationRelativeTo(parent);
    placa.setText(cupo.getPlaca().getPlaca());
    Interval intervalo = new Interval(new Instant(cupo.getCupoPK().getIngreso().getTime()),
            new Instant(cupo.getSalida().getTime()));
    Period period = intervalo.toPeriod();
    PeriodFormatter minutesAndSeconds = new PeriodFormatterBuilder().printZeroAlways().appendHours()
            .appendSeparator(":").appendMinutes().toFormatter();
    String result = minutesAndSeconds.print(period);
    tiempo.setText(result);
    cobroFinal.setText(String.valueOf(cupo.getCobroSugerido()));
    if (cupo.getLocker() != null) {
        locker.setText(String.format("%s : %d", cupo.getLocker().getIdentificador(),
                cupo.getLocker().getAlojamiento()));
    } else {
        locker.setText("Ninguno");
    }
    observaciones.setText(cupo.getPlaca().getUsuario().getObservacion());
    this.setVisible(true);
}

From source file:io.coala.xml.XmlUtil.java

License:Apache License

/**
 * @param interval/* www .j  a  v a2  s.c  o m*/
 * @return a JAXP {@link Duration}
 */
public static Duration toDuration(final Interval interval) {
    return toDuration(interval.toPeriod());
}

From source file:name.gluino.webmailfeed.ClubMember.java

License:Open Source License

public int getAge() {
    if (birthday != null) {
        Interval iv = new Interval(birthday, new DateTime());
        Period p = iv.toPeriod();
        return p.getYears();
    } else {//w w  w  .j  a va 2 s .  c o  m
        // some default value...
        return 30;
    }
}

From source file:net.sf.jacclog.service.analyzer.commands.internal.AnalyzeLogEntriesShellCommand.java

License:Apache License

private void analyzeEntries() {
    if (service != null) {
        final DateTimeFormatter format = DateTimeFormat.forPattern("yyyyMMdd");
        final DateTime from = format.parseDateTime(this.from);
        final DateTime to = (this.to != null) ? format.parseDateTime(this.to) : from.plusDays(1);
        final Interval interval = new Interval(from, to);
        final Period period = interval.toPeriod();

        final StringBuffer buffer = new StringBuffer();
        buffer.append("Analyse the log entries from '");
        buffer.append(from.toString()).append('\'');
        buffer.append(" to '").append(to);

        // print the period
        final String space = " ";
        buffer.append("'. The period includes ");
        final PeriodFormatter dateFormat = new PeriodFormatterBuilder().appendYears()
                .appendSuffix(" year", " years").appendSeparator(space).appendMonths()
                .appendSuffix(" month", " months").appendSeparator(space).appendWeeks()
                .appendSuffix(" week", " weeks").appendSeparator(space).appendDays()
                .appendSuffix(" day", " days").appendSeparator(space).appendHours()
                .appendSuffix(" hour", " hours").appendSeparator(space).appendMinutes()
                .appendSuffix(" minute", " minutes").appendSeparator(space).toFormatter();
        dateFormat.printTo(buffer, period);
        buffer.append('.');

        System.out.println(buffer.toString());

        final long maxResults = service.count(interval);
        if (maxResults > 0) {
            int maxCount = 0;
            if (proceed(maxResults)) {
                final long startTime = System.currentTimeMillis();

                final LogEntryAnalysisResult result = analyzerService.analyze(interval).toResult();
                final Map<UserAgentInfo, AtomicInteger> stats = result.getUserAgentInfos();
                System.out.println("User agent information count: " + stats.size());

                String name;//from   w w  w .j a  va  2 s  .c  o m
                String osName;
                int count;
                for (final Entry<UserAgentInfo, AtomicInteger> entry : stats.entrySet()) {
                    name = entry.getKey().getName();
                    osName = entry.getKey().getOsName();
                    count = entry.getValue().get();
                    maxCount += count;
                    System.out.println(name + " (" + osName + ") \t" + count);
                }
                System.out.println("Sum: " + maxCount);

                final long elapsedTime = System.currentTimeMillis() - startTime;
                final Period p = new Period(elapsedTime);
                System.out.println("Total processing time: " + p.toString(FORMATTER));
            }
        } else {
            System.out.println("There is nothing to analyze.");
        }
    }
}

From source file:net.sourceforge.fenixedu.domain.time.chronologies.AcademicChronology.java

License:Open Source License

public int getDayOfAcademicSemester(long instant) {
    AcademicCalendarEntry entryByInstant = academicCalendar.getEntryByInstant(instant, AcademicSemesterCE.class,
            AcademicYearCE.class);
    if (entryByInstant != null) {
        DateTime instantDateTime = new DateTime(instant);
        Interval interval = new Interval(entryByInstant.getBegin(), instantDateTime);
        int days = interval.toPeriod().getDays();
        if (days > 0) {
            return days;
        }//from w  ww  . j a  v  a 2s.c  om
    }
    return 0;
}