List of usage examples for org.joda.time Period seconds
public static Period seconds(int seconds)
From source file:io.konig.dao.core.SimpleChartFactory.java
License:Apache License
private Period toPeriod(ShapeQuery query) throws DaoException { String value = query.getParameters().get("timeInterval.durationUnit"); if (value == null) { throw new DaoException("durationUnit is not defined"); }/* w ww .ja v a 2 s. c o m*/ value = value.toLowerCase(); switch (value) { case "second": return Period.seconds(1); case "hour": return Period.hours(1); case "day": return Period.days(1); case "week": return Period.weeks(1); case "month": return Period.months(1); case "quarter": return Period.months(3); case "year": return Period.years(1); } throw new DaoException("Invalid durationUnit: " + value); }
From source file:org.apache.druid.indexing.common.IndexTaskClient.java
License:Apache License
private static RetryPolicyFactory initializeRetryPolicyFactory(long numRetries) { // Retries [numRetries] times before giving up; this should be set long enough to handle any temporary // unresponsiveness such as network issues, if a task is still in the process of starting up, or if the task is in // the middle of persisting to disk and doesn't respond immediately. return new RetryPolicyFactory(new RetryPolicyConfig().setMinWait(Period.seconds(MIN_RETRY_WAIT_SECONDS)) .setMaxWait(Period.seconds(MAX_RETRY_WAIT_SECONDS)).setMaxRetryCount(numRetries)); }
From source file:org.kalypso.commons.time.PeriodUtils.java
License:Open Source License
public static Period getPeriod(final int calendarField, final int amount) { switch (calendarField) { case Calendar.YEAR: return Period.years(amount); case Calendar.MONTH: return Period.months(amount); case Calendar.WEEK_OF_YEAR: case Calendar.WEEK_OF_MONTH: return Period.weeks(amount); case Calendar.DAY_OF_MONTH: case Calendar.DAY_OF_YEAR: case Calendar.DAY_OF_WEEK: case Calendar.DAY_OF_WEEK_IN_MONTH: return Period.days(amount); case Calendar.HOUR: case Calendar.HOUR_OF_DAY: return Period.hours(amount); case Calendar.MINUTE: return Period.minutes(amount); case Calendar.SECOND: return Period.seconds(amount); case Calendar.MILLISECOND: return Period.millis(amount); case Calendar.AM_PM: case Calendar.ERA: default://ww w . ja va 2 s . c o m throw new UnsupportedOperationException(); } }
From source file:org.mrgeo.geometry.splitter.TimeSpanGeometrySplitter.java
License:Apache License
@Override public void initialize(Map<String, String> splitterProperties, final boolean uuidOutputNames, final String[] outputNames) { String timeFormat = splitterProperties.get(TIME_FORMAT_PROPERTY); if (timeFormat == null || timeFormat.isEmpty()) { dtf = ISODateTimeFormat.dateTime(); } else {/* w w w . j a v a 2 s . c o m*/ dtf = DateTimeFormat.forPattern(timeFormat); } DateTime startTime = getTimeProperty(splitterProperties, START_TIME_PROPERTY, dtf); DateTime endTime = getTimeProperty(splitterProperties, END_TIME_PROPERTY, dtf); String strInterval = splitterProperties.get(INTERVAL_PROPERTY); if (strInterval == null || strInterval.isEmpty()) { throw new IllegalArgumentException("Missing interval property for time span geometry splitter"); } int seconds = -1; try { seconds = Integer.parseInt(strInterval); } catch (NumberFormatException nfe) { throw new IllegalArgumentException( "Invalid value for interval property for time span geometry splitter"); } Period interval = Period.seconds(seconds); startField = splitterProperties.get(START_FIELD_PROPERTY); if (startField == null || startField.isEmpty()) { throw new IllegalArgumentException("Missing startField property for time span geometry splitter"); } endField = splitterProperties.get(END_FIELD_PROPERTY); if (endField == null || endField.isEmpty()) { throw new IllegalArgumentException("Missing endField property for time span geometry splitter"); } compareType = TimeSpanGeometrySplitter.CompareType.END_TIME; String strCompareType = splitterProperties.get(COMPARE_TYPE_PROPERTY); if (strCompareType != null && !strCompareType.isEmpty()) { compareType = compareTypeFromString(strCompareType); } List<DateTime> breakpointsList = new ArrayList<DateTime>(); DateTime currBreakpoint = startTime; while (currBreakpoint.compareTo(endTime) <= 0) { breakpointsList.add(currBreakpoint); currBreakpoint = currBreakpoint.plus(interval); } // If the endTime is greater than the last breakpoint, then // include one more breakpoint. if (endTime.compareTo(currBreakpoint.minus(interval)) > 0) { breakpointsList.add(currBreakpoint); } if ((outputNames != null) && (breakpointsList.size() != outputNames.length)) { throw new IllegalArgumentException( "Invalid set of output names specified for the time span" + " geometry splitter. There are " + breakpointsList.size() + " breakpoints, and " + outputNames.length + " output names"); } breakpoints = new DateTime[breakpointsList.size()]; breakpointsList.toArray(breakpoints); outputs = new String[breakpoints.length]; for (int i = 0; i < breakpoints.length; i++) { String output; if (outputNames != null) { output = outputNames[i]; } else { if (uuidOutputNames) { output = UUID.randomUUID().toString(); } else { output = breakpoints[i].toString(dtf); // DirectoryMultipleOutputs only allows alphanumeric characters output = output.replaceAll("[^\\p{Alnum}]", ""); } } outputs[i] = output; } }
From source file:rcrr.reversi.ClockFixtures.java
License:Open Source License
/** * Returns a duration object corresponding to the value of the {@code seconds} parameter. * * @param seconds the number of seconds given to the duration object * @return the corresponding duration object *//*from w ww .j a v a2 s .com*/ private static Duration durationValueOfSeconds(final int seconds) { return Period.seconds(seconds).toStandardDuration(); }
From source file:ta4jexamples.loaders.CsvTradesLoader.java
License:Open Source License
/** * Builds a list of empty ticks.//from w w w . java 2 s.c o m * @param beginTime the begin time of the whole period * @param endTime the end time of the whole period * @param duration the tick duration (in seconds) * @return the list of empty ticks */ private static List<Tick> buildEmptyTicks(DateTime beginTime, DateTime endTime, int duration) { List<Tick> emptyTicks = new ArrayList<Tick>(); Period tickTimePeriod = Period.seconds(duration); DateTime tickEndTime = beginTime; do { tickEndTime = tickEndTime.plus(tickTimePeriod); emptyTicks.add(new Tick(tickTimePeriod, tickEndTime)); } while (tickEndTime.isBefore(endTime)); return emptyTicks; }
From source file:uk.ac.imperial.lsds.seep.infrastructure.monitor.policy.threshold.TimeThreshold.java
License:Open Source License
public static TimeThreshold seconds(int seconds) { return new TimeThreshold(Period.seconds(seconds)); }