Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#2014 update. #2039

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -167,18 +167,15 @@ private static void convertAgeToDob(QueryObject queryObject, int utcMinuteOffset
QueryTerm qt = (QueryTerm) qe;
if (qt.getEntity().equalsIgnoreCase(EntityEnum.PASSENGER.getEntityName()) &&
qt.getField().equalsIgnoreCase("passengerDetails.age")) {

String replacementField = "passengerDetails.dob";
String replacementType = "date";
qt.setField(replacementField);
qt.setType(replacementType);


//Handle UTC offsets.
LocalDateTime localDatetime = LocalDateTime.now();
localDatetime = localDatetime.minusMinutes(utcMinuteOffset);

LocalDate localDate = localDatetime.toLocalDate();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
String replacementField = "passengerDetails.dob";
String replacementType = "date";
switch (qt.getOperator()) {
case LESS:
// Because dates are stored as the "greatest date" being the date in the future,
Expand All @@ -188,6 +185,8 @@ private static void convertAgeToDob(QueryObject queryObject, int utcMinuteOffset
LocalDate lessTime = localDate.minusYears(lessAge + 1);
String[] lessReplacementValue = new String[] {lessTime.format(formatter)};
qt.setValue(lessReplacementValue);
qt.setField(replacementField);
qt.setType(replacementType);
break;
case LESS_OR_EQUAL:
// Because dates are stored as the "greatest date" being the date in the future,
Expand All @@ -196,7 +195,9 @@ private static void convertAgeToDob(QueryObject queryObject, int utcMinuteOffset
int lessEqualAge = Integer.parseInt(qt.getValue()[0]);
LocalDate lessEqualTime = localDate.minusYears(lessEqualAge + 1);
String[] lessEqualReplacementValue = new String[] {lessEqualTime.format(formatter)};
qt.setValue(lessEqualReplacementValue);
qt.setValue(lessEqualReplacementValue);
qt.setField(replacementField);
qt.setType(replacementType);
break;
case GREATER_OR_EQUAL:
// Because dates are stored as the "greatest date" being the date in the future,
Expand All @@ -206,6 +207,8 @@ private static void convertAgeToDob(QueryObject queryObject, int utcMinuteOffset
LocalDate greaterOrEqualTime = localDate.minusYears(greaterOrEqualAge);
String[] greaterOrEqualVal = new String[] {greaterOrEqualTime.format(formatter)};
qt.setValue(greaterOrEqualVal);
qt.setField(replacementField);
qt.setType(replacementType);
break;
case GREATER:
// Because dates are stored as the "greatest date" being the date in the future,
Expand All @@ -214,7 +217,9 @@ private static void convertAgeToDob(QueryObject queryObject, int utcMinuteOffset
int greaterAge = Integer.parseInt(qt.getValue()[0]);
LocalDate greaterTime = localDate.minusYears(greaterAge);
String[] greaterValue = new String[] {greaterTime.format(formatter)};
qt.setValue(greaterValue);
qt.setValue(greaterValue);
qt.setField(replacementField);
qt.setType(replacementType);
break;
case EQUAL:
int equalAge = Integer.parseInt(qt.getValue()[0]);
Expand All @@ -225,6 +230,8 @@ private static void convertAgeToDob(QueryObject queryObject, int utcMinuteOffset
qt.setOperator(BETWEEN);
String[] replacementValueEqual = new String[] {equalAgeStart.format(formatter), equalAgeFinish.format(formatter)};
qt.setValue(replacementValueEqual);
qt.setField(replacementField);
qt.setType(replacementType);
break;
case NOT_EQUAL:
int notEqualAge = Integer.parseInt(qt.getValue()[0]);
Expand All @@ -235,6 +242,8 @@ private static void convertAgeToDob(QueryObject queryObject, int utcMinuteOffset
qt.setOperator(NOT_BETWEEN);
String[] replacementValueNotEqual = new String[] {notEqualAgeStart.format(formatter), notEqualAgeFinish.format(formatter)};
qt.setValue(replacementValueNotEqual);
qt.setField(replacementField);
qt.setType(replacementType);
break;
default:
String message = "No conversion from age to date for query operator of " + qt.getOperator();
Expand Down