diff --git a/java/google/registry/model/common/TimedTransitionProperty.java b/java/google/registry/model/common/TimedTransitionProperty.java index ff5681719..d98f17614 100644 --- a/java/google/registry/model/common/TimedTransitionProperty.java +++ b/java/google/registry/model/common/TimedTransitionProperty.java @@ -125,6 +125,17 @@ public class TimedTransitionProperty copyUntilJustBefore(DateTime asOfDate) { + return new TimedTransitionProperty<>(backingMap.headMap(asOfDate, false)); + } + /** * Returns a new mutable {@code TimedTransitionProperty} representing the given map of DateTime * to value, with transitions constructed using the given {@code TimedTransition} subclass. diff --git a/java/google/registry/model/domain/DomainResource.java b/java/google/registry/model/domain/DomainResource.java index 46ed38b3c..5c3a0202f 100644 --- a/java/google/registry/model/domain/DomainResource.java +++ b/java/google/registry/model/domain/DomainResource.java @@ -217,6 +217,37 @@ public class DomainResource extends DomainBase implements ForeignKeyedEppResourc return ImmutableSet.copyOf(gracePeriodStatuses); } + /** + * Returns the Registry Grace Period expiration date for the specified type of grace period for + * this domain, or null if there is no grace period of the specified type. + */ + public Optional getGracePeriodExpirationTime(GracePeriodStatus gracePeriodType) { + for (GracePeriod gracePeriod : getGracePeriods()) { + if (gracePeriod.getType() == gracePeriodType) { + return Optional.of(gracePeriod.getExpirationTime()); + } + } + return Optional.absent(); + } + + /** + * Checks to see if the domain is in a particular type of grace period at the specified time. We + * only check the expiration time, because grace periods are always assumed to start at the + * beginning of time. This could be confusing if asOfDate is in the past. For instance, the Add + * Grace Period will appear to last from the beginning of time until 5 days after the domain is + * created. + */ + public boolean doesAnyGracePeriodOfTypeExpireAfter( + GracePeriodStatus gracePeriodType, DateTime asOfDate) { + for (GracePeriod gracePeriod : getGracePeriods()) { + if ((gracePeriod.getType() == gracePeriodType) + && gracePeriod.getExpirationTime().isAfter(asOfDate)) { + return true; + } + } + return false; + } + /** * The logic in this method, which handles implicit server approval of transfers, very closely * parallels the logic in {@code DomainTransferApproveFlow} which handles explicit client