Example usage for org.joda.time Seconds getSeconds

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

Introduction

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

Prototype

public int getSeconds() 

Source Link

Document

Gets the number of seconds that this period represents.

Usage

From source file:act.job.JobManager.java

License:Apache License

public void on(DateTime instant, Runnable runnable) {
    if (LOGGER.isTraceEnabled()) {
        LOGGER.trace("schedule runnable[%s] on %s", runnable, instant);
    }/*from  w w  w  . j a va  2 s  . c o m*/
    DateTime now = DateTime.now();
    E.illegalArgumentIf(instant.isBefore(now));
    Seconds seconds = Seconds.secondsBetween(now, instant);
    executor().schedule(wrap(runnable), seconds.getSeconds(), TimeUnit.SECONDS);
}

From source file:act.job.JobManager.java

License:Apache License

public <T> Future<T> on(DateTime instant, Callable<T> callable) {
    if (LOGGER.isTraceEnabled()) {
        LOGGER.trace("schedule callable[%s] on %s", callable, instant);
    }// w  w w  .  j a  v  a  2s  .c  o m
    DateTime now = DateTime.now();
    E.illegalArgumentIf(instant.isBefore(now));
    Seconds seconds = Seconds.secondsBetween(now, instant);
    return executor().schedule(callable, seconds.getSeconds(), TimeUnit.SECONDS);
}

From source file:com.bitplan.rest.RestServerImpl.java

License:Apache License

/**
 * stop this server/*ww w . ja v  a2 s. co m*/
 * 
 * @see com.bitplan.rest.RestServer#stop()
 */
@Override
public void stop() {
    if (httpServer != null) {
        httpServer.shutdown();
        httpServer = null;
        running = false;
        stopTime = DateTime.now();
        Seconds secs = Seconds.secondsBetween(startTime, stopTime);
        System.out.println("finished after " + secs.getSeconds() + " secs");
        // if someone is waiting for us let him continue ..
        informStarter();
    }
}

From source file:com.cisco.dvbu.ps.utils.date.DateDiffDate.java

License:Open Source License

/**
 * Called to invoke the stored procedure.  Will only be called a
 * single time per instance.  Can throw CustomProcedureException or
 * SQLException if there is an error during invoke.
 *//*from ww  w. j ava2s . co  m*/
public void invoke(Object[] inputValues) throws CustomProcedureException, SQLException {
    java.util.Date startDate = null;
    java.util.Date endDate = null;
    Calendar startCal = null;
    Calendar endCal = null;
    DateTime startDateTime = null;
    DateTime endDateTime = null;
    String datePart = null;
    long dateLength = 0;

    try {
        result = null;
        if (inputValues[0] == null) {
            result = new Long(dateLength);
            return;
        }

        if (inputValues[1] == null) {
            result = new Long(dateLength);
            return;
        }

        if (inputValues[2] == null) {
            result = new Long(dateLength);
            return;
        }

        datePart = (String) inputValues[0];
        startDate = (java.util.Date) inputValues[1];
        startCal = Calendar.getInstance();
        startCal.setTime(startDate);

        endDate = (java.util.Date) inputValues[2];
        endCal = Calendar.getInstance();
        endCal.setTime(endDate);

        startDateTime = new DateTime(startCal.get(Calendar.YEAR), startCal.get(Calendar.MONTH) + 1,
                startCal.get(Calendar.DAY_OF_MONTH), 0, 0, 0, 0);
        endDateTime = new DateTime(endCal.get(Calendar.YEAR), endCal.get(Calendar.MONTH) + 1,
                endCal.get(Calendar.DAY_OF_MONTH), 0, 0, 0, 0);

        if (datePart.equalsIgnoreCase("second")) {
            Seconds seconds = Seconds.secondsBetween(startDateTime, endDateTime);
            dateLength = seconds.getSeconds();
        }

        if (datePart.equalsIgnoreCase("minute")) {
            Minutes minutes = Minutes.minutesBetween(startDateTime, endDateTime);
            dateLength = minutes.getMinutes();
        }

        if (datePart.equalsIgnoreCase("hour")) {
            Hours hours = Hours.hoursBetween(startDateTime, endDateTime);
            dateLength = hours.getHours();
        }

        if (datePart.equalsIgnoreCase("day")) {
            Days days = Days.daysBetween(startDateTime, endDateTime);
            dateLength = days.getDays();
        }

        if (datePart.equalsIgnoreCase("week")) {
            Weeks weeks = Weeks.weeksBetween(startDateTime, endDateTime);
            dateLength = weeks.getWeeks();
        }

        if (datePart.equalsIgnoreCase("month")) {
            Months months = Months.monthsBetween(startDateTime, endDateTime);
            dateLength = months.getMonths();
        }

        if (datePart.equalsIgnoreCase("year")) {
            Years years = Years.yearsBetween(startDateTime, endDateTime);
            dateLength = years.getYears();
        }

        result = new Long(dateLength);
    } catch (Throwable t) {
        throw new CustomProcedureException(t);
    }
}

From source file:com.cisco.dvbu.ps.utils.date.DateDiffTimestamp.java

License:Open Source License

/**
 * Called to invoke the stored procedure.  Will only be called a
 * single time per instance.  Can throw CustomProcedureException or
 * SQLException if there is an error during invoke.
 *//*from w ww.j  a v  a2 s. c om*/
public void invoke(Object[] inputValues) throws CustomProcedureException, SQLException {
    Timestamp startTimestamp = null;
    Timestamp endTimestamp = null;
    Calendar startCal = null;
    Calendar endCal = null;
    DateTime startDateTime = null;
    DateTime endDateTime = null;
    String datePart = null;
    long dateLength = 0;

    try {
        result = null;
        if (inputValues[0] == null) {
            result = new Long(dateLength);
            return;
        }

        if (inputValues[1] == null) {
            result = new Long(dateLength);
            return;
        }

        if (inputValues[2] == null) {
            result = new Long(dateLength);
            return;
        }

        datePart = (String) inputValues[0];
        startTimestamp = (Timestamp) inputValues[1];
        // long startMilliseconds = startTimestamp.getTime() +
        // (startTimestamp.getNanos() / 1000000);
        long startMilliseconds = startTimestamp.getTime()
                + (startTimestamp.getNanos() % 1000000L >= 500000L ? 1 : 0);
        startCal = Calendar.getInstance();
        startCal.setTimeInMillis(startMilliseconds);

        endTimestamp = (Timestamp) inputValues[2];
        // long endMilliseconds = endTimestamp.getTime() +
        // (endTimestamp.getNanos() / 1000000);
        long endMilliseconds = endTimestamp.getTime() + (endTimestamp.getNanos() % 1000000L >= 500000L ? 1 : 0);

        endCal = Calendar.getInstance();
        endCal.setTimeInMillis(endMilliseconds);

        startDateTime = new DateTime(startCal.get(Calendar.YEAR), startCal.get(Calendar.MONTH) + 1,
                startCal.get(Calendar.DAY_OF_MONTH), startCal.get(Calendar.HOUR_OF_DAY),
                startCal.get(Calendar.MINUTE), startCal.get(Calendar.SECOND),
                startCal.get(Calendar.MILLISECOND));
        endDateTime = new DateTime(endCal.get(Calendar.YEAR), endCal.get(Calendar.MONTH) + 1,
                endCal.get(Calendar.DAY_OF_MONTH), endCal.get(Calendar.HOUR_OF_DAY),
                endCal.get(Calendar.MINUTE), endCal.get(Calendar.SECOND), endCal.get(Calendar.MILLISECOND));

        Interval interval = new Interval(startDateTime, endDateTime);

        if (datePart.equalsIgnoreCase("second") || datePart.equalsIgnoreCase("ss")) {
            Seconds seconds = Seconds.secondsIn(interval);
            dateLength = seconds.getSeconds();
        } else if (datePart.equalsIgnoreCase("minute") || datePart.equalsIgnoreCase("mi")) {
            Minutes minutes = Minutes.minutesIn(interval);
            dateLength = minutes.getMinutes();
        } else if (datePart.equalsIgnoreCase("hour") || datePart.equalsIgnoreCase("hh")) {
            Hours hours = Hours.hoursIn(interval);
            dateLength = hours.getHours();
        } else if (datePart.equalsIgnoreCase("day") || datePart.equalsIgnoreCase("dd")) {
            Days days = Days.daysIn(interval);
            dateLength = days.getDays();
        } else if (datePart.equalsIgnoreCase("week") || datePart.equalsIgnoreCase("wk")) {
            Weeks weeks = Weeks.weeksIn(interval);
            dateLength = weeks.getWeeks();
        } else if (datePart.equalsIgnoreCase("month") || datePart.equalsIgnoreCase("mm")) {
            Months months = Months.monthsIn(interval);
            dateLength = months.getMonths();
        } else if (datePart.equalsIgnoreCase("year") || datePart.equalsIgnoreCase("yy")) {
            Years years = Years.yearsIn(interval);
            dateLength = years.getYears();
        } else if (datePart.equalsIgnoreCase("millisecond") || datePart.equalsIgnoreCase("ms")) {
            dateLength = (endTimestamp.getTime() - startTimestamp.getTime()); // millis
        } else if (datePart.equalsIgnoreCase("microsecond") || datePart.equalsIgnoreCase("mcs")) {
            dateLength = ((endTimestamp.getTime() - startTimestamp.getTime()) / 1000) // seconds
                    * 1000000L // micros
                    + (endTimestamp.getNanos() - startTimestamp.getNanos()) / 1000; // nanos/1000
        } else if (datePart.equalsIgnoreCase("nanosecond") || datePart.equalsIgnoreCase("ns")) {
            dateLength = ((endTimestamp.getTime() - startTimestamp.getTime()) / 1000) // seconds
                    * 1000000000L // nanos
                    + (endTimestamp.getNanos() - startTimestamp.getNanos()); // nanos
        } else {
            throw new IllegalArgumentException(datePart);
        }

        result = new Long(dateLength);

    } catch (Throwable t) {
        throw new CustomProcedureException(t);
    }
}

From source file:com.jeet.cli.Admin.java

private static void checkIntegrity(Map fileMap) {
    System.out.print("Enter File Index(0 to cancel): ");
    String choise = null;/*from  w  w  w .j  a v  a2  s  . c o  m*/
    try {
        choise = bufferRead.readLine();
    } catch (IOException ioe) {
        System.err.println("Error in reading option.");
        System.err.println("Please try again.");
        checkIntegrity(fileMap);
    }
    if (choise != null && NumberUtils.isDigits(choise)) {
        Integer choiseInt = Integer.parseInt(choise);
        if (fileMap.containsKey(choiseInt)) {
            try {
                String key = fileMap.get(choiseInt).toString();
                File file = FileUtil.downloadAndDecryptFile(key);
                Long fileLength = file.length();
                if (FileUtil.getHash(key.split("/")[1]).equals(HashUtil.generateFileHash(file))) {
                    Map userMetadata = S3Connect.getUserMetadata(key);
                    //                        System.out.println(userMetadata.get(Constants.LAST_MODIFIED_KEY));
                    //                        System.out.println(S3Connect.getLastModified(key).getTime());
                    //check last access time
                    if (userMetadata.containsKey(Constants.LAST_MODIFIED_KEY)) {
                        Long millisFromMettaData = Long
                                .valueOf(userMetadata.get(Constants.LAST_MODIFIED_KEY).toString());
                        Long millisFromS3 = S3Connect.getLastModified(key).getTime();
                        Seconds difference = Seconds.secondsBetween(new DateTime(millisFromMettaData),
                                new DateTime(millisFromS3));
                        if (difference.getSeconds() < Constants.LAST_MODIFIED_VARIANT) {
                            //check file length
                            if (userMetadata.containsKey(Constants.FILE_LENGTH_KEY) && fileLength.toString()
                                    .equals(userMetadata.get(Constants.FILE_LENGTH_KEY))) {
                                //check hash from user data
                                if (userMetadata.containsKey(Constants.HASH_KEY) && userMetadata
                                        .get(Constants.HASH_KEY).equals(FileUtil.getHash(key.split("/")[1]))) {
                                    System.out.println(ANSI_GREEN + "Data integrity is preserved.");
                                } else {
                                    System.out.println(ANSI_RED + "Data integrity is not preserved.");
                                }
                            } else {
                                System.out.println(ANSI_RED + "File is length does not matched.");
                            }
                        } else {
                            System.out.println(ANSI_RED + "File is modified outside the system.");
                        }
                    } else {
                        System.out.println(ANSI_RED + "File is modified outside the system.");
                    }
                } else {
                    System.out.println(ANSI_RED + "Data integrity is not preserved.");
                }

            } catch (Exception ex) {
                ex.printStackTrace();
                System.err.println("Error in downlaoding file.");
            }
            askFileListInputs(fileMap);
        } else if (choiseInt.equals(0)) {
            System.out.println("Check Integrity file canceled.");
            askFileListInputs(fileMap);
        } else {
            System.err.println("Please select from provided options only.");
            checkIntegrity(fileMap);
        }
    } else {
        System.err.println("Please enter digits only.");
        checkIntegrity(fileMap);
    }
}

From source file:com.keepassdroid.utils.DateUtil.java

License:Open Source License

public static long convertDateToKDBX4Time(DateTime dt) {
    try {/*from w  ww  . j a  v a2  s. c  om*/
        Seconds secs = Seconds.secondsBetween(javaEpoch, dt);
        return secs.getSeconds() + epochOffset;
    } catch (ArithmeticException e) {
        // secondsBetween overflowed an int
        Date javaDt = dt.toDate();
        long seconds = javaDt.getTime() / 1000L;
        return seconds + epochOffset;
    }
}

From source file:com.pacoapp.paco.ui.ExperimentExecutor.java

License:Open Source License

private void addTiming(Event event) {
    if (formOpenTime != null) {
        DateTime formFinishTime = DateTime.now();
        Seconds duration = Seconds.secondsBetween(formOpenTime, formFinishTime);

        Output durationResponse = new Output();
        durationResponse.setAnswer(Integer.toString(duration.getSeconds()));
        durationResponse.setName(FORM_DURATION_IN_SECONDS);
        event.addResponse(durationResponse);
    }//from  w  ww  .  j a  v  a2  s. c  o m
}

From source file:com.qcadoo.mes.cmmsMachineParts.listeners.PlannedEventRealizationDetailsListeners.java

License:Open Source License

public void calculateDuration(final ViewDefinitionState view, final ComponentState state, final String[] args) {
    FieldComponent startDateFieldComponent = (FieldComponent) view
            .getComponentByReference(PlannedEventRealizationFields.START_DATE);
    FieldComponent finishDateFieldComponent = (FieldComponent) view
            .getComponentByReference(PlannedEventRealizationFields.FINISH_DATE);
    FieldComponent durationFieldComponent = (FieldComponent) view
            .getComponentByReference(PlannedEventRealizationFields.DURATION);

    if ((startDateFieldComponent.getFieldValue() == null
            || startDateFieldComponent.getFieldValue().toString().isEmpty())
            || (finishDateFieldComponent.getFieldValue() == null
                    || finishDateFieldComponent.getFieldValue().toString().isEmpty())) {
        return;//from ww  w .j  a  va  2  s  .  c o  m
    }

    Date start = DateUtils.parseDate(startDateFieldComponent.getFieldValue());
    Date end = DateUtils.parseDate(finishDateFieldComponent.getFieldValue());

    if (start != null && end != null && start.before(end)) {
        Seconds seconds = Seconds.secondsBetween(new DateTime(start), new DateTime(end));
        durationFieldComponent.setFieldValue(Integer.valueOf(seconds.getSeconds()));
    }
    durationFieldComponent.requestComponentUpdateState();
}

From source file:com.qcadoo.mes.cmmsMachineParts.listeners.StaffWorkTimeDetailsListenersCMMS.java

License:Open Source License

public void calculateLaborTime(final ViewDefinitionState view, final ComponentState state,
        final String[] args) {
    FieldComponent startDateFieldComponent = (FieldComponent) view
            .getComponentByReference(StaffWorkTimeFields.EFFECTIVE_EXECUTION_TIME_START);
    FieldComponent endDateFieldComponent = (FieldComponent) view
            .getComponentByReference(StaffWorkTimeFields.EFFECTIVE_EXECUTION_TIME_END);
    FieldComponent laborTimeFieldComponent = (FieldComponent) view
            .getComponentByReference(StaffWorkTimeFields.LABOR_TIME);
    if (startDateFieldComponent.getFieldValue() == null || endDateFieldComponent.getFieldValue() == null) {
        return;/*from   w ww  . ja v a2  s .c  o m*/
    }
    Date start = DateUtils.parseDate(startDateFieldComponent.getFieldValue());
    Date end = DateUtils.parseDate(endDateFieldComponent.getFieldValue());

    if (start != null && end != null && start.before(end)) {
        Seconds seconds = Seconds.secondsBetween(new DateTime(start), new DateTime(end));
        laborTimeFieldComponent.setFieldValue(Integer.valueOf(seconds.getSeconds()));
    }
    laborTimeFieldComponent.requestComponentUpdateState();
}