Example usage for org.joda.time DurationFieldType seconds

List of usage examples for org.joda.time DurationFieldType seconds

Introduction

In this page you can find the example usage for org.joda.time DurationFieldType seconds.

Prototype

public static DurationFieldType seconds() 

Source Link

Document

Get the seconds field type.

Usage

From source file:azkaban.app.Scheduler.java

License:Apache License

private String createPeriodString(ReadablePeriod period) {
    String periodStr = "n";

    if (period == null) {
        return "n";
    }/*w w  w  .j a v a2s.co  m*/

    if (period.get(DurationFieldType.days()) > 0) {
        int days = period.get(DurationFieldType.days());
        periodStr = days + "d";
    } else if (period.get(DurationFieldType.hours()) > 0) {
        int hours = period.get(DurationFieldType.hours());
        periodStr = hours + "h";
    } else if (period.get(DurationFieldType.minutes()) > 0) {
        int minutes = period.get(DurationFieldType.minutes());
        periodStr = minutes + "m";
    } else if (period.get(DurationFieldType.seconds()) > 0) {
        int seconds = period.get(DurationFieldType.seconds());
        periodStr = seconds + "s";
    }

    return periodStr;
}

From source file:azkaban.migration.scheduler.Schedule.java

License:Apache License

public static String createPeriodString(ReadablePeriod period) {
    String periodStr = "n";

    if (period == null) {
        return "n";
    }/*w  w  w. j a va 2s.co  m*/

    if (period.get(DurationFieldType.months()) > 0) {
        int months = period.get(DurationFieldType.months());
        periodStr = months + "M";
    } else if (period.get(DurationFieldType.weeks()) > 0) {
        int weeks = period.get(DurationFieldType.weeks());
        periodStr = weeks + "w";
    } else if (period.get(DurationFieldType.days()) > 0) {
        int days = period.get(DurationFieldType.days());
        periodStr = days + "d";
    } else if (period.get(DurationFieldType.hours()) > 0) {
        int hours = period.get(DurationFieldType.hours());
        periodStr = hours + "h";
    } else if (period.get(DurationFieldType.minutes()) > 0) {
        int minutes = period.get(DurationFieldType.minutes());
        periodStr = minutes + "m";
    } else if (period.get(DurationFieldType.seconds()) > 0) {
        int seconds = period.get(DurationFieldType.seconds());
        periodStr = seconds + "s";
    }

    return periodStr;
}

From source file:azkaban.utils.TimeUtils.java

License:Apache License

/**
 * Format ReadablePeriod object to string
 *
 * @param period readable period object/*from   www.  ja  va 2  s  .  c  o  m*/
 * @return String presentation of ReadablePeriod Object
 */
public static String formatPeriod(final ReadablePeriod period) {
    String periodStr = "null";

    if (period == null) {
        return periodStr;
    }

    if (period.get(DurationFieldType.years()) > 0) {
        final int years = period.get(DurationFieldType.years());
        periodStr = years + " year(s)";
    } else if (period.get(DurationFieldType.months()) > 0) {
        final int months = period.get(DurationFieldType.months());
        periodStr = months + " month(s)";
    } else if (period.get(DurationFieldType.weeks()) > 0) {
        final int weeks = period.get(DurationFieldType.weeks());
        periodStr = weeks + " week(s)";
    } else if (period.get(DurationFieldType.days()) > 0) {
        final int days = period.get(DurationFieldType.days());
        periodStr = days + " day(s)";
    } else if (period.get(DurationFieldType.hours()) > 0) {
        final int hours = period.get(DurationFieldType.hours());
        periodStr = hours + " hour(s)";
    } else if (period.get(DurationFieldType.minutes()) > 0) {
        final int minutes = period.get(DurationFieldType.minutes());
        periodStr = minutes + " minute(s)";
    } else if (period.get(DurationFieldType.seconds()) > 0) {
        final int seconds = period.get(DurationFieldType.seconds());
        periodStr = seconds + " second(s)";
    }

    return periodStr;
}

From source file:azkaban.utils.TimeUtils.java

License:Apache License

/**
 * Convert ReadablePeriod Object to string
 *
 * @param period ReadablePeriod Object/*from w  w  w. jav  a2  s . c o m*/
 * @return string formatted ReadablePeriod Object
 */
public static String createPeriodString(final ReadablePeriod period) {
    String periodStr = "null";

    if (period == null) {
        return periodStr;
    }

    if (period.get(DurationFieldType.years()) > 0) {
        final int years = period.get(DurationFieldType.years());
        periodStr = years + "y";
    } else if (period.get(DurationFieldType.months()) > 0) {
        final int months = period.get(DurationFieldType.months());
        periodStr = months + "M";
    } else if (period.get(DurationFieldType.weeks()) > 0) {
        final int weeks = period.get(DurationFieldType.weeks());
        periodStr = weeks + "w";
    } else if (period.get(DurationFieldType.days()) > 0) {
        final int days = period.get(DurationFieldType.days());
        periodStr = days + "d";
    } else if (period.get(DurationFieldType.hours()) > 0) {
        final int hours = period.get(DurationFieldType.hours());
        periodStr = hours + "h";
    } else if (period.get(DurationFieldType.minutes()) > 0) {
        final int minutes = period.get(DurationFieldType.minutes());
        periodStr = minutes + "m";
    } else if (period.get(DurationFieldType.seconds()) > 0) {
        final int seconds = period.get(DurationFieldType.seconds());
        periodStr = seconds + "s";
    }

    return periodStr;
}

From source file:azkaban.utils.Utils.java

License:Apache License

public static String createPeriodString(ReadablePeriod period) {
    String periodStr = "null";

    if (period == null) {
        return "null";
    }//  ww w .  java2s .  c  o m

    if (period.get(DurationFieldType.years()) > 0) {
        int years = period.get(DurationFieldType.years());
        periodStr = years + "y";
    } else if (period.get(DurationFieldType.months()) > 0) {
        int months = period.get(DurationFieldType.months());
        periodStr = months + "M";
    } else if (period.get(DurationFieldType.weeks()) > 0) {
        int weeks = period.get(DurationFieldType.weeks());
        periodStr = weeks + "w";
    } else if (period.get(DurationFieldType.days()) > 0) {
        int days = period.get(DurationFieldType.days());
        periodStr = days + "d";
    } else if (period.get(DurationFieldType.hours()) > 0) {
        int hours = period.get(DurationFieldType.hours());
        periodStr = hours + "h";
    } else if (period.get(DurationFieldType.minutes()) > 0) {
        int minutes = period.get(DurationFieldType.minutes());
        periodStr = minutes + "m";
    } else if (period.get(DurationFieldType.seconds()) > 0) {
        int seconds = period.get(DurationFieldType.seconds());
        periodStr = seconds + "s";
    }

    return periodStr;
}

From source file:azkaban.utils.WebUtils.java

License:Apache License

public String formatPeriod(ReadablePeriod period) {
    String periodStr = "null";

    if (period == null) {
        return periodStr;
    }/* w  ww.j a v  a  2 s . c  o  m*/

    if (period.get(DurationFieldType.years()) > 0) {
        int years = period.get(DurationFieldType.years());
        periodStr = years + " year(s)";
    } else if (period.get(DurationFieldType.months()) > 0) {
        int months = period.get(DurationFieldType.months());
        periodStr = months + " month(s)";
    } else if (period.get(DurationFieldType.weeks()) > 0) {
        int weeks = period.get(DurationFieldType.weeks());
        periodStr = weeks + " week(s)";
    } else if (period.get(DurationFieldType.days()) > 0) {
        int days = period.get(DurationFieldType.days());
        periodStr = days + " day(s)";
    } else if (period.get(DurationFieldType.hours()) > 0) {
        int hours = period.get(DurationFieldType.hours());
        periodStr = hours + " hour(s)";
    } else if (period.get(DurationFieldType.minutes()) > 0) {
        int minutes = period.get(DurationFieldType.minutes());
        periodStr = minutes + " minute(s)";
    } else if (period.get(DurationFieldType.seconds()) > 0) {
        int seconds = period.get(DurationFieldType.seconds());
        periodStr = seconds + " second(s)";
    }

    return periodStr;
}

From source file:com.cenrise.test.azkaban.Utils.java

License:Apache License

public static String createPeriodString(final ReadablePeriod period) {
    String periodStr = "null";

    if (period == null) {
        return "null";
    }/*from  w  ww .  j  a v  a2  s .c o  m*/

    if (period.get(DurationFieldType.years()) > 0) {
        final int years = period.get(DurationFieldType.years());
        periodStr = years + "y";
    } else if (period.get(DurationFieldType.months()) > 0) {
        final int months = period.get(DurationFieldType.months());
        periodStr = months + "M";
    } else if (period.get(DurationFieldType.weeks()) > 0) {
        final int weeks = period.get(DurationFieldType.weeks());
        periodStr = weeks + "w";
    } else if (period.get(DurationFieldType.days()) > 0) {
        final int days = period.get(DurationFieldType.days());
        periodStr = days + "d";
    } else if (period.get(DurationFieldType.hours()) > 0) {
        final int hours = period.get(DurationFieldType.hours());
        periodStr = hours + "h";
    } else if (period.get(DurationFieldType.minutes()) > 0) {
        final int minutes = period.get(DurationFieldType.minutes());
        periodStr = minutes + "m";
    } else if (period.get(DurationFieldType.seconds()) > 0) {
        final int seconds = period.get(DurationFieldType.seconds());
        periodStr = seconds + "s";
    }

    return periodStr;
}

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. com
 */
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:eu.eidas.auth.engine.metadata.MetadataGenerator.java

License:EUPL

private DateTime getExpireDate() {
    DateTime expiryDate = DateTime.now();
    expiryDate = expiryDate.withFieldAdded(DurationFieldType.seconds(),
            (int) (getConfigParams().getValidityDuration()));
    return expiryDate;
}

From source file:net.sourceforge.fenixedu.util.HourMinuteSecond.java

License:Open Source License

/**
 * Returns a new date plus the specified number of seconds.
 * <p>//from w w w  .j a v a 2  s .  c o  m
 * This date instance is immutable and unaffected by this method call.
 * <p>
 * The following three lines are identical in effect:
 * 
 * <pre>
 * HourMinuteSecond added = hms.plusSeconds(6);
 * 
 * HourMinuteSecond added = hms.plus(Period.seconds(6));
 * 
 * HourMinuteSecond added = hms.withFieldAdded(DurationFieldType.seconds(), 6);
 * </pre>
 * 
 * @param seconds
 *            the amount of seconds to add, may be negative
 * @return the new date plus the increased seconds
 */
public HourMinuteSecond plusSeconds(int seconds) {
    return withFieldAdded(DurationFieldType.seconds(), seconds);
}