final DateTimes.UtcFormatter parser = DateTimes.wrapFormatter(createAutoParser()); return (String input) -> { Preconditions.checkArgument(!Strings.isNullOrEmpty(input), "null timestamp"); } else { try { final DateTimes.UtcFormatter formatter = DateTimes.wrapFormatter(DateTimeFormat.forPattern(format)); return input -> { Preconditions.checkArgument(!Strings.isNullOrEmpty(input), "null timestamp");
formatString == null ? createDefaultParser(timeZone) : DateTimes.wrapFormatter(DateTimeFormat.forPattern(formatString).withZone(timeZone));
private Supplier<Function<String, String>> makeFunctionSupplier() final DateTimes.UtcFormatter parser = DateTimes.wrapFormatter(DateTimeFormat.forPattern(timeFormat)); final DateTimes.UtcFormatter formatter = DateTimes.wrapFormatter(DateTimeFormat.forPattern(resultFormat));
@Override public ExprEval apply(List<Expr> args, Expr.ObjectBinding bindings) { if (args.size() != 1 && args.size() != 2) { throw new IAE("Function[%s] needs 1 or 2 arguments", name()); } ExprEval value = args.get(0).eval(bindings); if (value.type() != ExprType.STRING) { throw new IAE("first argument should be string type but got %s type", value.type()); } DateTimes.UtcFormatter formatter = DateTimes.ISO_DATE_OPTIONAL_TIME; if (args.size() > 1) { ExprEval format = args.get(1).eval(bindings); if (format.type() != ExprType.STRING) { throw new IAE("second argument should be string type but got %s type", format.type()); } formatter = DateTimes.wrapFormatter(DateTimeFormat.forPattern(format.asString())); } DateTime date; try { date = formatter.parse(value.asString()); } catch (IllegalArgumentException e) { throw new IAE(e, "invalid value %s", value.asString()); } return toValue(date); }
@Test public void testContextualTimestampList() { String DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss"; String[] dates = new String[]{ "2000-01-01T05:00:00", "2000-01-01T05:00:01", "2000-01-01T05:00:01", "2000-01-01T05:00:02", "2000-01-01T05:00:03", }; TimestampSpec spec = new TimestampSpec("TIMEstamp", DATE_FORMAT, null); DateTimes.UtcFormatter formatter = DateTimes.wrapFormatter(ISODateTimeFormat.dateHourMinuteSecond()); for (String date : dates) { DateTime dateTime = spec.extractTimestamp(ImmutableMap.of("TIMEstamp", date)); DateTime expectedDateTime = formatter.parse(date); Assert.assertEquals(expectedDateTime, dateTime); } } }
.toParser(); return DateTimes.wrapFormatter( new DateTimeFormatterBuilder() .append(ISODateTimeFormat.dateElementParser())
final DateTimes.UtcFormatter parser = DateTimes.wrapFormatter(createAutoParser()); return (String input) -> { Preconditions.checkArgument(!Strings.isNullOrEmpty(input), "null timestamp"); } else { try { final DateTimes.UtcFormatter formatter = DateTimes.wrapFormatter(DateTimeFormat.forPattern(format)); return input -> { Preconditions.checkArgument(!Strings.isNullOrEmpty(input), "null timestamp");
formatString == null ? createDefaultParser(timeZone) : DateTimes.wrapFormatter(DateTimeFormat.forPattern(formatString).withZone(timeZone));
private Supplier<Function<String, String>> makeFunctionSupplier() final DateTimes.UtcFormatter parser = DateTimes.wrapFormatter(DateTimeFormat.forPattern(timeFormat)); final DateTimes.UtcFormatter formatter = DateTimes.wrapFormatter(DateTimeFormat.forPattern(resultFormat));
@Override public ExprEval apply(List<Expr> args, Expr.ObjectBinding bindings) { if (args.size() != 1 && args.size() != 2) { throw new IAE("Function[%s] needs 1 or 2 arguments", name()); } ExprEval value = args.get(0).eval(bindings); if (value.type() != ExprType.STRING) { throw new IAE("first argument should be string type but got %s type", value.type()); } DateTimes.UtcFormatter formatter = DateTimes.ISO_DATE_OPTIONAL_TIME; if (args.size() > 1) { ExprEval format = args.get(1).eval(bindings); if (format.type() != ExprType.STRING) { throw new IAE("second argument should be string type but got %s type", format.type()); } formatter = DateTimes.wrapFormatter(DateTimeFormat.forPattern(format.asString())); } DateTime date; try { date = formatter.parse(value.asString()); } catch (IllegalArgumentException e) { throw new IAE(e, "invalid value %s", value.asString()); } return toValue(date); }
.toParser(); return DateTimes.wrapFormatter( new DateTimeFormatterBuilder() .append(ISODateTimeFormat.dateElementParser())