MCPcopy Create free account
hub / github.com/OpenTSDB/opentsdb / getDurationInterval

Method getDurationInterval

src/utils/DateTime.java:270–291  ·  view source on GitHub ↗

Parses the prefix of the duration, the interval and returns it as a number. E.g. if you supply "1d" it will return "1". If you supply "60m" it will return "60". @param duration The duration to parse in the format #units, e.g. "1d" or "60m" @return The interval as an integer, regardless of units. @th

(final String duration)

Source from the content-addressed store, hash-verified

268 * @since 2.4
269 */
270 public static final int getDurationInterval(final String duration) {
271 if (duration == null || duration.isEmpty()) {
272 throw new IllegalArgumentException("Duration cannot be null or empty");
273 }
274 if (duration.contains(".")) {
275 throw new IllegalArgumentException("Floating point intervals are not supported");
276 }
277 int unit = 0;
278 while (Character.isDigit(duration.charAt(unit))) {
279 unit++;
280 }
281 int interval;
282 try {
283 interval = Integer.parseInt(duration.substring(0, unit));
284 } catch (NumberFormatException e) {
285 throw new IllegalArgumentException("Invalid duration (number): " + duration);
286 }
287 if (interval <= 0) {
288 throw new IllegalArgumentException("Zero or negative duration: " + duration);
289 }
290 return interval;
291 }
292
293 /**
294 * Returns whether or not a date is specified in a relative fashion.

Callers 9

getDurationIntervalMethod · 0.95
mockSystemTimeMethod · 0.95
RollupIntervalMethod · 0.95

Calls 2

isEmptyMethod · 0.80
containsMethod · 0.80

Tested by 8

getDurationIntervalMethod · 0.76
mockSystemTimeMethod · 0.76