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

Method getDurationUnits

src/utils/DateTime.java:242–258  ·  view source on GitHub ↗

Returns the suffix or "units" of the duration as a string. The result will be ms, s, m, h, d, w, n or y. @param duration The duration in the format #units, e.g. 1d or 6h @return Just the suffix, e.g. 'd' or 'h' @throws IllegalArgumentException if the duration is null, empty or if the units are inval

(final String duration)

Source from the content-addressed store, hash-verified

240 * @since 2.4
241 */
242 public static final String getDurationUnits(final String duration) {
243 if (duration == null || duration.isEmpty()) {
244 throw new IllegalArgumentException("Duration cannot be null or empty");
245 }
246 int unit = 0;
247 while (unit < duration.length() &&
248 Character.isDigit(duration.charAt(unit))) {
249 unit++;
250 }
251 final String units = duration.substring(unit).toLowerCase();
252 if (units.equals("ms") || units.equals("s") || units.equals("m") ||
253 units.equals("h") || units.equals("d") || units.equals("w") ||
254 units.equals("n") || units.equals("y")) {
255 return units;
256 }
257 throw new IllegalArgumentException("Invalid units in the duration: " + units);
258 }
259
260 /**
261 * Parses the prefix of the duration, the interval and returns it as a number.

Callers 9

getDurationUnitsMethod · 0.95
getDurationUnitsFloatMethod · 0.95
getDurationUnitsNullMethod · 0.95
getDurationUnitsEmptyMethod · 0.95
getDurationIsNullMethod · 0.95
mockSystemTimeMethod · 0.95
RollupIntervalMethod · 0.95

Calls 2

isEmptyMethod · 0.80
equalsMethod · 0.45

Tested by 8

getDurationUnitsMethod · 0.76
getDurationUnitsFloatMethod · 0.76
getDurationUnitsNullMethod · 0.76
getDurationUnitsEmptyMethod · 0.76
getDurationIsNullMethod · 0.76
mockSystemTimeMethod · 0.76