Add MR to expand billing events into OneTimes

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=124837292
This commit is contained in:
Chris Tingue 2016-06-14 07:52:13 -07:00 committed by Justine Tunney
parent 7cf4ddce97
commit 2a83d122ef
6 changed files with 69 additions and 8 deletions

View file

@ -160,6 +160,25 @@ public final class RequestParameters {
}
}
/**
* Returns first request parameter associated with {@code name} parsed as an
* <a href="https://goo.gl/pk5Q2k">ISO 8601</a> timestamp, e.g. {@code 1984-12-18TZ},
* {@code 2000-01-01T16:20:00Z}.
*
* @throws BadRequestException if request parameter is present but not a valid {@link DateTime}.
*/
public static Optional<DateTime> extractOptionalDatetimeParameter(
HttpServletRequest req, String name) {
String stringParam = req.getParameter(name);
try {
return isNullOrEmpty(stringParam)
? Optional.<DateTime>absent()
: Optional.of(DateTime.parse(stringParam));
} catch (IllegalArgumentException e) {
throw new BadRequestException("Bad ISO 8601 timestamp: " + name);
}
}
/**
* Returns first request parameter associated with {@code name} parsed as an optional
* {@link InetAddress} (which might be IPv6).