Skip to content

Commit

Permalink
Merge pull request #3222 from NCI-Agency/GH-3220-use-now
Browse files Browse the repository at this point in the history
Use 'now' instead of the end-of-day in UTC
  • Loading branch information
VassilIordanov authored Sep 30, 2020
2 parents 0878df9 + c1bec52 commit 025c266
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/main/java/mil/dds/anet/beans/Report.java
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,7 @@ public List<AuthorizationGroup> getAuthorizationGroups() {

@JsonIgnore
public boolean isFutureEngagement() {
return engagementDate != null && engagementDate.isAfter(Utils.endOfToday());
return engagementDate != null && engagementDate.isAfter(Instant.now());
}

@GraphQLQuery(name = "engagementStatus")
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/mil/dds/anet/search/AbstractReportSearcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Sets;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
Expand All @@ -29,7 +30,6 @@
import mil.dds.anet.database.ReportDao;
import mil.dds.anet.search.AbstractSearchQueryBuilder.Comparison;
import mil.dds.anet.utils.DaoUtils;
import mil.dds.anet.utils.Utils;

public abstract class AbstractReportSearcher extends AbstractSearcher<Report, ReportSearchQuery>
implements IReportSearcher {
Expand Down Expand Up @@ -177,11 +177,11 @@ protected void buildQuery(Set<String> subFields, ReportSearchQuery query) {
switch (es) {
case HAPPENED:
engagementStatusClauses.add(" reports.\"engagementDate\" <= :endOfHappened");
DaoUtils.addInstantAsLocalDateTime(qb.sqlArgs, "endOfHappened", Utils.endOfToday());
DaoUtils.addInstantAsLocalDateTime(qb.sqlArgs, "endOfHappened", Instant.now());
break;
case FUTURE:
engagementStatusClauses.add(" reports.\"engagementDate\" > :startOfFuture");
DaoUtils.addInstantAsLocalDateTime(qb.sqlArgs, "startOfFuture", Utils.endOfToday());
DaoUtils.addInstantAsLocalDateTime(qb.sqlArgs, "startOfFuture", Instant.now());
break;
case CANCELLED:
engagementStatusClauses.add(" reports.state = :cancelledState");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package mil.dds.anet.threads;

import java.lang.invoke.MethodHandles;
import java.time.Instant;
import java.util.List;
import java.util.Map;
import mil.dds.anet.AnetObjectEngine;
import mil.dds.anet.beans.AnetEmail;
import mil.dds.anet.beans.Report;
import mil.dds.anet.database.ReportDao;
import mil.dds.anet.emails.FutureEngagementUpdated;
import mil.dds.anet.utils.Utils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -43,7 +43,7 @@ private void runInternal() {
// afterwards this report needs to go through the approval process of past
// engagements.
List<Report> reports =
AnetObjectEngine.getInstance().getReportDao().getFutureToPastReports(Utils.endOfToday());
AnetObjectEngine.getInstance().getReportDao().getFutureToPastReports(Instant.now());

// update to draft state and send emails to the authors to let them know we updated their
// report.
Expand Down
9 changes: 0 additions & 9 deletions src/main/java/mil/dds/anet/utils/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.lang.invoke.MethodHandles;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
Expand Down Expand Up @@ -450,14 +449,6 @@ private static Pattern domainToRegexPattern(final String domain, final String wi
return Pattern.compile("^" + regex + "$");
}


// Returns an instant representing the very end of today.
// Used to determine if a date is tomorrow or later.
public static Instant endOfToday() {
return Instant.now().atZone(DaoUtils.getDefaultZoneId()).withHour(23).withMinute(59)
.withSecond(59).withNano(999999999).toInstant();
}

/**
* Resizes an image.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import mil.dds.anet.test.integration.utils.TestBeans;
import mil.dds.anet.threads.AnetEmailWorker;
import mil.dds.anet.threads.FutureEngagementWorker;
import mil.dds.anet.utils.Utils;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -119,7 +118,7 @@ public void testReportDueInFuture() {
public void testReportDueEndToday() {
final AnetObjectEngine engine = AnetObjectEngine.getInstance();
final Report report = createTestReport("testReportDueEndToday_1");
report.setEngagementDate(Utils.endOfToday());
report.setEngagementDate(Instant.now());
engine.getReportDao().update(report);

expectedIds.add("testReportDueEndToday_1");
Expand Down Expand Up @@ -197,7 +196,7 @@ public void testApprovalStepReport() {
ra.setStep(step);
ra.setStepUuid(step.getUuid());
ra.setType(ActionType.APPROVE);
ra.setCreatedAt(Utils.endOfToday());
ra.setCreatedAt(Instant.now());
engine.getReportActionDao().insert(ra);

unexpectedIds.add("testApprovalStepReport_1");
Expand Down

0 comments on commit 025c266

Please sign in to comment.