Removes conversion method
This commit is contained in:
@@ -26,8 +26,6 @@ import org.springframework.web.server.ServerWebExchange;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
import static org.springframework.cloud.gateway.handler.predicate.BetweenRoutePredicateFactory.getZonedDateTime;
|
||||
|
||||
/**
|
||||
* @author Spencer Gibb
|
||||
*/
|
||||
@@ -46,7 +44,7 @@ public class AfterRoutePredicateFactory extends AbstractRoutePredicateFactory<Af
|
||||
|
||||
@Override
|
||||
public Predicate<ServerWebExchange> apply(Config config) {
|
||||
ZonedDateTime datetime = getZonedDateTime(config.getDatetime());
|
||||
ZonedDateTime datetime = config.getDatetime();
|
||||
return exchange -> {
|
||||
final ZonedDateTime now = ZonedDateTime.now();
|
||||
return now.isAfter(datetime);
|
||||
|
||||
@@ -24,8 +24,6 @@ import java.util.function.Predicate;
|
||||
|
||||
import org.springframework.web.server.ServerWebExchange;
|
||||
|
||||
import static org.springframework.cloud.gateway.handler.predicate.BetweenRoutePredicateFactory.getZonedDateTime;
|
||||
|
||||
/**
|
||||
* @author Spencer Gibb
|
||||
*/
|
||||
@@ -44,7 +42,7 @@ public class BeforeRoutePredicateFactory extends AbstractRoutePredicateFactory<B
|
||||
|
||||
@Override
|
||||
public Predicate<ServerWebExchange> apply(Config config) {
|
||||
ZonedDateTime datetime = getZonedDateTime(config.getDatetime());
|
||||
ZonedDateTime datetime = config.getDatetime();
|
||||
return exchange -> {
|
||||
final ZonedDateTime now = ZonedDateTime.now();
|
||||
return now.isBefore(datetime);
|
||||
|
||||
@@ -49,9 +49,8 @@ public class BetweenRoutePredicateFactory extends AbstractRoutePredicateFactory<
|
||||
|
||||
@Override
|
||||
public Predicate<ServerWebExchange> apply(Config config) {
|
||||
//TODO: figure out boot conversion
|
||||
ZonedDateTime datetime1 = getZonedDateTime(config.datetime1);
|
||||
ZonedDateTime datetime2 = getZonedDateTime(config.datetime2);
|
||||
ZonedDateTime datetime1 = config.datetime1;
|
||||
ZonedDateTime datetime2 = config.datetime2;
|
||||
Assert.isTrue(datetime1.isBefore(datetime2),
|
||||
config.datetime1 +
|
||||
" must be before " + config.datetime2);
|
||||
@@ -88,29 +87,4 @@ public class BetweenRoutePredicateFactory extends AbstractRoutePredicateFactory<
|
||||
}
|
||||
}
|
||||
|
||||
public static ZonedDateTime getZonedDateTime(Object value) {
|
||||
ZonedDateTime dateTime;
|
||||
if (value instanceof ZonedDateTime) {
|
||||
dateTime = ZonedDateTime.class.cast(value);
|
||||
} else {
|
||||
dateTime = parseZonedDateTime(value.toString());
|
||||
}
|
||||
return dateTime;
|
||||
}
|
||||
|
||||
public static ZonedDateTime parseZonedDateTime(String dateString) {
|
||||
ZonedDateTime dateTime;
|
||||
try {
|
||||
long epoch = Long.parseLong(dateString);
|
||||
|
||||
dateTime = Instant.ofEpochMilli(epoch).atOffset(ZoneOffset.ofTotalSeconds(0))
|
||||
.toZonedDateTime();
|
||||
} catch (NumberFormatException e) {
|
||||
// try ZonedDateTime instead
|
||||
dateTime = ZonedDateTime.parse(dateString);
|
||||
}
|
||||
|
||||
return dateTime;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user