Example usage for org.joda.time Duration getStandardSeconds

List of usage examples for org.joda.time Duration getStandardSeconds

Introduction

In this page you can find the example usage for org.joda.time Duration getStandardSeconds.

Prototype

public long getStandardSeconds() 

Source Link

Document

Gets the length of this duration in seconds assuming that there are the standard number of milliseconds in a second.

Usage

From source file:de.avanux.livetracker.Tracking.java

License:Open Source License

/**
 * Returns true, if no location message has been received for the average location message period plus additional 5 seconds.
 * If no location message has been received yet we are overdue anyway.
 * @return/*  w w  w . j ava  2s.  co m*/
 */
public boolean isOverdue() {
    if (this.locationMessage == null) {
        // we are overdue until we receive location messages
        return true;
    } else {
        Duration age = new Duration(this.locationMessage.getDate(), new DateTime());
        if (age.getStandardSeconds() > (this.statistics.getAvgLocationMessagePeriod()
                + ADDITIONAL_OVERDUE_SECONDS)) {
            return true;
        } else {
            return false;
        }
    }
}

From source file:de.fatalix.bookery.App.java

License:Open Source License

public void userLoggedIn(@Observes(notifyObserver = Reception.IF_EXISTS) UserLoggedInEvent event) {
    AppUser user = userService.updateLastLogin(event.getUsername());

    if (user.getLastLogin() != null) {
        DateTime dtLastLogin = new DateTime(user.getLastLogin());
        DateTime dtCurrentLogin = new DateTime(user.getCurrentLogin());
        Duration duration = new Duration(dtLastLogin, dtCurrentLogin);
        String sinceLastLogin = "";
        if (duration.getStandardDays() > 0) {
            long days = duration.getStandardDays();
            if (days == 1) {
                sinceLastLogin = days + " day";
            } else {
                sinceLastLogin = days + " days";
            }//from   ww w  . j a  v a  2  s . c  om
        } else if (duration.getStandardHours() > 0) {
            long hours = duration.getStandardHours();
            if (hours == 1) {
                sinceLastLogin = hours + " hour";
            } else {
                sinceLastLogin = hours + " hours";
            }
        } else if (duration.getStandardMinutes() > 0) {
            long minutes = duration.getStandardMinutes();
            if (minutes == 1) {
                sinceLastLogin = minutes + " minute";
            } else {
                sinceLastLogin = minutes + " minutes";
            }
        } else {
            long seconds = duration.getStandardSeconds();
            if (seconds == 1) {
                sinceLastLogin = seconds + " second";
            } else {
                sinceLastLogin = seconds + " seconds";
            }
        }
        Notification.show("Welcome back " + event.getUsername() + " after " + sinceLastLogin + ".");
    } else {
        Notification.show("Welcome " + event.getUsername());
    }

    logger.info("User " + event.getUsername() + " logged in.");
    getNavigator().navigateTo(HomeView.id);
    appLayout.getAppHeader().setLoginName(SecurityUtils.getSubject().getPrincipal().toString());
    appLayout.getAppHeader().setVisible(isLoggedIn());

}

From source file:de.rwth.idsg.xsharing.router.iv.util.DurationSecondsSerializer.java

License:Open Source License

@Override
public void serialize(Duration value, JsonGenerator jgen, SerializerProvider provider) throws IOException {
    jgen.writeNumber(value.getStandardSeconds());
}

From source file:energy.usef.core.util.DateTimeUtil.java

License:Apache License

/**
 * Calculate the number of minutes from midnight to now. The number of minutes depends on summer- and winter time.
 *
 * @param dateTime the date time which includes the timezone. When setting the DateTime with the default constructor, the
 * default timezone where the application runs, is used.
 * @return the number of minutes from midnight.
 *///from www  .j  ava  2 s .co  m
public static Integer getElapsedMinutesSinceMidnight(LocalDateTime dateTime) {
    DateTime midnight = dateTime.toLocalDate().toDateMidnight().toDateTime();
    Duration duration = new Interval(midnight, dateTime.toDateTime()).toDuration();
    return (int) duration.getStandardSeconds() / SECONDS_PER_MINUTE;
}

From source file:energy.usef.core.util.DateTimeUtil.java

License:Apache License

/**
 * Calculate the number of minutes of a specific date. Only the date part (year, month and day) is used to calculate the number
 * of minutes. The number of minutes is calculated from midnight to midnight the next day. For a default day this method return
 * 24 * 60 = 1440. If on this day a summer- or wintertime switch occurs, the number of minutes are different.
 *
 * @param date the date time which includes the timezone. When setting the DateTime with the default constructor, the
 * default timezone where the application runs, is used.
 * @return the number of minutes for the day (date part) of the dateTime parameter.
 *///from w  ww .j  ava2s  .  c o m
public static Integer getMinutesOfDay(LocalDate date) {
    Duration duration = new Interval(date.toDateMidnight(), date.plusDays(1).toDateMidnight()).toDuration();
    return (int) duration.getStandardSeconds() / SECONDS_PER_MINUTE;
}

From source file:eu.hydrologis.libs.peakflow.core.discharge.QReal.java

License:Open Source License

/**
 * Calculate the discharge with rainfall data.
 *//*from   w ww  . ja va 2s  .c  om*/
// public QReal( ParameterBox fixedParameters, double[][] iuhdata, double[][] jeffdata ) {
// fixedParams = fixedParameters;
//
// jeff = jeffdata;
// ampi = iuhdata;
//
// System.out.println("AAAAAAAAAAAAAAAAAAAAAAAAAAAAA: ampilength " + ampi[ampi.length - 1][0]);
// }

/*
 * (non-Javadoc)
 * @see bsh.commands.h.peakflow.core.discharge.DischargeCalculator#calculateQ()
 */
public double[][] calculateQ() {
    double timestep = fixedParams.getTimestep();
    double area_super = fixedParams.getArea();
    double area_sub = fixedParams.getArea_sub();
    double area_tot = 0f;

    double raintimestep = jeffC.getRain_timestep();
    DateTime firstDate = jeffC.getFirstDate();

    /*
     * The maximum rain time has no sense with the real precipitations. In this case it will use
     * the rain timestep for tp.
     */
    double tcorr = ampi[ampi.length - 1][0];
    tpmax = (double) raintimestep;
    int rainLength = jeff.size();
    double[][] totalQshiftMatrix = new double[rainLength][(int) (Math.floor((tcorr + tpmax) / timestep) + 1
            + rainLength * raintimestep / timestep)];
    double[][] Q = new double[(int) Math.floor((tcorr + tpmax) / timestep) + 1][3];

    if (area_sub != -9999.0) {
        area_tot = area_sub + area_super;
    } else {
        area_tot = area_super;
    }

    Set<DateTime> dates = jeff.keySet();
    PrintStreamProgressMonitor pm = new PrintStreamProgressMonitor(out);
    pm.beginTask("Calculating discharge...", dates.size());
    int i = 0;
    for (DateTime dateTime : dates) {
        double J = jeff.get(dateTime);
        /*
         * calculate the discharge for t < tcorr
         */
        int j = 0;
        for (int t = 1; t < tcorr; t += timestep) {
            j = (int) Math.floor((t) / timestep);

            if (t <= tpmax) {
                Q[j][0] = t;
                double widthInterpolate = FluidUtils.width_interpolate(ampi, t, 0, 2);
                Q[j][1] = (double) (J * area_tot * widthInterpolate);
                Q[j][2] = Q[j - 1][2] + Q[j][1];
            } else {
                Q[j][0] = t;
                Q[j][1] = (double) (J * area_tot * (FluidUtils.width_interpolate(ampi, t, 0, 2)
                        - FluidUtils.width_interpolate(ampi, t - tpmax, 0, 2)));
                Q[j][2] = Q[j - 1][2] + Q[j][1];
            }
        }

        /*
         * calculate the discharge for t > tcorr
         */

        for (double t = tcorr; t < (tcorr + tpmax); t += timestep) {
            j = (int) Math.floor(((int) t) / timestep);
            Q[j][0] = t;
            Q[j][1] = (double) (J * area_tot
                    * (ampi[ampi.length - 1][2] - FluidUtils.width_interpolate(ampi, t - tpmax, 0, 2)));
            Q[j][2] = Q[j - 1][2] + Q[j][1];
        }

        /*
         * calculate the volumes
         */
        double vol = Q[Q.length - 2][2] * timestep;
        double vol2 = (double) (area_tot * J * raintimestep);

        /*
         * calculate zero padding before first value Note that jeff contains already the
         * progressive time of the rainfile.
         */
        int totalshiftmatrixindex = 0;
        int initalshiftmatrixindex = 0;
        // FIXME time in ???
        Duration duration = new Duration(firstDate, dateTime);
        long intervalSeconds = duration.getStandardSeconds();

        int paddingnumber = (int) (intervalSeconds / timestep);
        for (int m = 0; m < paddingnumber; m++) {
            totalQshiftMatrix[i][m] = 0;
            totalshiftmatrixindex++;
        }
        initalshiftmatrixindex = totalshiftmatrixindex;
        for (int k = initalshiftmatrixindex; k < Q.length + initalshiftmatrixindex; k++) {
            totalQshiftMatrix[i][k] = Q[k - initalshiftmatrixindex][1];
            totalshiftmatrixindex++;
        }
        for (int k = Q.length + totalshiftmatrixindex; k < totalQshiftMatrix[0].length; k++) {
            totalQshiftMatrix[i][k] = 0;
        }
        i++;
        pm.worked(1);
    }
    pm.done();

    /*
     * sum the discharge contributes
     */
    Qtot = new double[totalQshiftMatrix[0].length][2];
    double tottime = 0f;
    for (int k = 0; k < Qtot.length; k++) {
        double sum = 0f;
        for (int j = 0; j < totalQshiftMatrix.length; j++) {
            sum = sum + totalQshiftMatrix[j][k];
        }

        tottime = tottime + timestep;

        Qtot[k][1] = sum;
        Qtot[k][0] = tottime;
    }

    double total_vol = 0f;
    for (int k = 0; k < Qtot.length; k++) {
        total_vol = total_vol + Qtot[k][1];
    }
    double total_rain = 0.0;
    for (DateTime dateTime : dates) {
        double J = jeff.get(dateTime);
        total_rain = total_rain + J;
    }
    total_rain = total_rain * area_tot * raintimestep;

    return Qtot;
}

From source file:google.registry.monitoring.whitebox.StackdriverModule.java

License:Open Source License

@Provides
@Named("metricsWriteInterval")
static long provideMetricsWriteInterval(@Config("metricsWriteInterval") Duration metricsWriteInterval) {
    return metricsWriteInterval.getStandardSeconds();
}

From source file:io.mesosphere.mesos.frameworks.cassandra.scheduler.PersistedCassandraFrameworkConfiguration.java

License:Apache License

public void healthCheckInterval(final Duration interval) {
    setValue(CassandraFrameworkConfiguration.newBuilder(get())
            .setHealthCheckIntervalSeconds(interval.getStandardSeconds()).build());
}

From source file:io.mesosphere.mesos.frameworks.cassandra.scheduler.PersistedCassandraFrameworkConfiguration.java

License:Apache License

public void bootstrapGraceTimeSeconds(@NotNull final Duration interval) {
    setValue(CassandraFrameworkConfiguration.newBuilder(get())
            .setBootstrapGraceTimeSeconds(interval.getStandardSeconds()).build());
}

From source file:julian.lylly.model.Util.java

public static String durationToHourMinuteSecondString(Duration duration) {
    long h = duration.getStandardHours();
    long m = duration.getStandardMinutes() % 60;
    long s = duration.getStandardSeconds() % 60;
    return longTo2DigitString(h) + ":" + longTo2DigitString(m) + ":" + longTo2DigitString(s);
}