public SegmentMetadataQueryConfig(String period) { defaultHistory = ISO_FORMATTER.parsePeriod(period); }
/** * Parses a {@code Period} from the specified string using a formatter. * * @param str the string to parse, not null * @param formatter the formatter to use, not null * @since 2.0 */ public static Period parse(String str, PeriodFormatter formatter) { return formatter.parsePeriod(str); }
/** * Parses a {@code Period} from the specified string using a formatter. * * @param str the string to parse, not null * @param formatter the formatter to use, not null * @since 2.0 */ public static Period parse(String str, PeriodFormatter formatter) { return formatter.parsePeriod(str); }
/** * Parses a {@code MutablePeriod} from the specified string using a formatter. * * @param str the string to parse, not null * @param formatter the formatter to use, not null * @since 2.0 */ public static MutablePeriod parse(String str, PeriodFormatter formatter) { return formatter.parsePeriod(str).toMutablePeriod(); }
@Override public Object deserializeKey(String key, DeserializationContext ctxt) throws IOException { if (key.length() == 0) { return null; } return ISOPeriodFormat.standard().parsePeriod(key); } }
/** * Parses a {@code MutablePeriod} from the specified string using a formatter. * * @param str the string to parse, not null * @param formatter the formatter to use, not null * @since 2.0 */ public static MutablePeriod parse(String str, PeriodFormatter formatter) { return formatter.parsePeriod(str).toMutablePeriod(); }
PeriodFormatter formatter = new PeriodFormatterBuilder() .appendDays().appendSuffix("d ") .appendHours().appendSuffix("h ") .appendMinutes().appendSuffix("min") .toFormatter(); Period p = formatter.parsePeriod("2d 5h 30min");
private static Period parsePeriod(PeriodFormatter periodFormatter, String value) { boolean negative = value.startsWith("-"); if (negative) { value = value.substring(1); } Period period = periodFormatter.parsePeriod(value); for (DurationFieldType type : period.getFieldTypes()) { checkArgument(period.get(type) >= 0, "Period field %s is negative", type); } if (negative) { period = period.negated(); } return period; }
private Optional<Long> getEarliestAllowedTimestamp() { if (!this.state.contains(RECORD_MAX_ALLOWED_TIME_AGO)) { return Optional.<Long> absent(); } DateTime currentTime = new DateTime(this.timeZone); String maxTimeAgoStr = this.state.getProp(RECORD_MAX_ALLOWED_TIME_AGO); Period maxTimeAgo = PERIOD_FORMATTER.parsePeriod(maxTimeAgoStr); return Optional.of(currentTime.minus(maxTimeAgo).getMillis()); }
private DateTime getEarliestAllowedFolderTime(DateTime currentTime, PeriodFormatter periodFormatter) { String maxTimeAgoStr = this.state.getProp(COMPACTION_TIMEBASED_MAX_TIME_AGO, DEFAULT_COMPACTION_TIMEBASED_MAX_TIME_AGO); Period maxTimeAgo = periodFormatter.parsePeriod(maxTimeAgoStr); return currentTime.minus(maxTimeAgo); }
private DateTime getLatestAllowedFolderTime(DateTime currentTime, PeriodFormatter periodFormatter) { String minTimeAgoStr = this.state.getProp(COMPACTION_TIMEBASED_MIN_TIME_AGO, DEFAULT_COMPACTION_TIMEBASED_MIN_TIME_AGO); Period minTimeAgo = periodFormatter.parsePeriod(minTimeAgoStr); return currentTime.minus(minTimeAgo); }
private Period getOwnDurationThreshold (Dataset dataset) { String retention = dataset.jobProps().getProp(MRCompactor.COMPACTION_LATEDATA_THRESHOLD_DURATION, MRCompactor.DEFAULT_COMPACTION_LATEDATA_THRESHOLD_DURATION); Period period = getPeriodFormatter().parsePeriod(retention); return period; }
/** * Creates a new <code>Seconds</code> by parsing a string in the ISO8601 format 'PTnS'. * <p> * The parse will accept the full ISO syntax of PnYnMnWnDTnHnMnS however only the * seconds component may be non-zero. If any other component is non-zero, an exception * will be thrown. * * @param periodStr the period string, null returns zero * @return the period in seconds * @throws IllegalArgumentException if the string format is invalid */ @FromString public static Seconds parseSeconds(String periodStr) { if (periodStr == null) { return Seconds.ZERO; } Period p = PARSER.parsePeriod(periodStr); return Seconds.seconds(p.getSeconds()); }
/** * Creates a new <code>Hours</code> by parsing a string in the ISO8601 format 'PTnH'. * <p> * The parse will accept the full ISO syntax of PnYnMnWnDTnHnMnS however only the * hours component may be non-zero. If any other component is non-zero, an exception * will be thrown. * * @param periodStr the period string, null returns zero * @return the period in hours * @throws IllegalArgumentException if the string format is invalid */ @FromString public static Hours parseHours(String periodStr) { if (periodStr == null) { return Hours.ZERO; } Period p = PARSER.parsePeriod(periodStr); return Hours.hours(p.getHours()); }
/** * Creates a new <code>Months</code> by parsing a string in the ISO8601 format 'PnM'. * <p> * The parse will accept the full ISO syntax of PnYnMnWnDTnHnMnS however only the * months component may be non-zero. If any other component is non-zero, an exception * will be thrown. * * @param periodStr the period string, null returns zero * @return the period in months * @throws IllegalArgumentException if the string format is invalid */ @FromString public static Months parseMonths(String periodStr) { if (periodStr == null) { return Months.ZERO; } Period p = PARSER.parsePeriod(periodStr); return Months.months(p.getMonths()); }
/** * Creates a new <code>Years</code> by parsing a string in the ISO8601 format 'PnY'. * <p> * The parse will accept the full ISO syntax of PnYnMnWnDTnHnMnS however only the * years component may be non-zero. If any other component is non-zero, an exception * will be thrown. * * @param periodStr the period string, null returns zero * @return the period in years * @throws IllegalArgumentException if the string format is invalid */ @FromString public static Years parseYears(String periodStr) { if (periodStr == null) { return Years.ZERO; } Period p = PARSER.parsePeriod(periodStr); return Years.years(p.getYears()); }
/** * Creates a new <code>Minutes</code> by parsing a string in the ISO8601 format 'PTnM'. * <p> * The parse will accept the full ISO syntax of PnYnMnWnDTnHnMnS however only the * minutes component may be non-zero. If any other component is non-zero, an exception * will be thrown. * * @param periodStr the period string, null returns zero * @return the period in minutes * @throws IllegalArgumentException if the string format is invalid */ @FromString public static Minutes parseMinutes(String periodStr) { if (periodStr == null) { return Minutes.ZERO; } Period p = PARSER.parsePeriod(periodStr); return Minutes.minutes(p.getMinutes()); }
/** * Creates a new <code>Days</code> by parsing a string in the ISO8601 format 'PnD'. * <p> * The parse will accept the full ISO syntax of PnYnMnWnDTnHnMnS however only the * days component may be non-zero. If any other component is non-zero, an exception * will be thrown. * * @param periodStr the period string, null returns zero * @return the period in days * @throws IllegalArgumentException if the string format is invalid */ @FromString public static Days parseDays(String periodStr) { if (periodStr == null) { return Days.ZERO; } Period p = PARSER.parsePeriod(periodStr); return Days.days(p.getDays()); }
private boolean isLookbackTimeStringDaily(String lookbackTime) { PeriodFormatter periodFormatter = new PeriodFormatterBuilder().appendDays().appendSuffix("d").toFormatter(); try { periodFormatter.parsePeriod(lookbackTime); return true; } catch (Exception e) { return false; } }
protected static Period getLookBackPeriod(String lookbackTime) { PeriodFormatter periodFormatter = new PeriodFormatterBuilder().appendYears().appendSuffix("y").appendMonths().appendSuffix("M").appendDays() .appendSuffix("d").appendHours().appendSuffix("h").appendMinutes().appendSuffix("m").toFormatter(); return periodFormatter.parsePeriod(lookbackTime); } }