Skip to content

Commit

Permalink
feat : ZonedDateTimeSupplier 추가
Browse files Browse the repository at this point in the history
- utc ZonedDateTime을 공급하기 위한 supplier 추가
  • Loading branch information
seokho-1116 committed Jun 6, 2024
1 parent b0ec7ca commit f9839b4
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import site.timecapsulearchive.core.domain.capsuleskin.entity.CapsuleSkin;
import site.timecapsulearchive.core.domain.group.entity.Group;
import site.timecapsulearchive.core.domain.member.entity.Member;
import site.timecapsulearchive.core.global.common.supplier.ZonedDateTimeSupplier;
import site.timecapsulearchive.core.global.entity.BaseEntity;

@Entity
Expand Down Expand Up @@ -112,7 +113,7 @@ public boolean isNotCapsuleOpened() {
return false;
}

return dueDate.isAfter(ZonedDateTime.now(ZoneId.of("UTC")));
return dueDate.isAfter(ZonedDateTimeSupplier.utc().get());
}

public void open() {
Expand All @@ -124,7 +125,7 @@ public boolean isTimeCapsule() {
}

public boolean canOpen() {
return dueDate == null || dueDate.isBefore(ZonedDateTime.now(ZoneId.of("UTC")));
return dueDate == null || dueDate.isBefore(ZonedDateTimeSupplier.utc().get());
}

public boolean isAllGroupMemberOpened(Long memberId, Long capsuleId) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package site.timecapsulearchive.core.global.common.supplier;

import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.function.Supplier;

public class ZonedDateTimeSupplier {

private static final String TIME_ZONE = "UTC";

public static Supplier<ZonedDateTime> utc() {
return () -> ZonedDateTime.now(ZoneId.of(TIME_ZONE));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import site.timecapsulearchive.core.domain.capsuleskin.entity.CapsuleSkin;
import site.timecapsulearchive.core.domain.group.entity.Group;
import site.timecapsulearchive.core.domain.member.entity.Member;
import site.timecapsulearchive.core.global.common.supplier.ZonedDateTimeSupplier;
import site.timecapsulearchive.core.global.geography.GeoTransformManager;

public class CapsuleFixture {
Expand All @@ -33,7 +34,7 @@ public static List<Capsule> capsules(int size, Member member, CapsuleSkin capsul

public static Capsule capsule(Member member, CapsuleSkin capsuleSkin, CapsuleType capsuleType) {
return Capsule.builder()
.dueDate(ZonedDateTime.now())
.dueDate(ZonedDateTimeSupplier.utc().get())
.title("testTitle")
.content("testContent")
.type(capsuleType)
Expand Down Expand Up @@ -68,7 +69,7 @@ private static Address getTestAddress() {
*/
public static Capsule groupCapsule(Member member, CapsuleSkin capsuleSkin, Group group) {
return Capsule.builder()
.dueDate(ZonedDateTime.now())
.dueDate(ZonedDateTimeSupplier.utc().get())
.title("testTitle")
.content("testContent")
.type(CapsuleType.GROUP)
Expand Down Expand Up @@ -132,7 +133,7 @@ public static Optional<Capsule> groupCapsuleNotAllMemberOpen(
List<Member> groupMembers
) {
CapsuleBuilder capsuleBuilder = getCapsuleBuilder(memberId);
Capsule capsule = capsuleBuilder.dueDate(ZonedDateTime.now(ZoneId.of("UTC")))
Capsule capsule = capsuleBuilder.dueDate(ZonedDateTimeSupplier.utc().get())
.build();

List<GroupCapsuleOpen> groupCapsuleOpens = GroupCapsuleOpenFixture.groupCapsuleOpens(false,
Expand All @@ -149,7 +150,7 @@ public static Optional<Capsule> groupCapsuleHalfMemberOpen(
List<Member> groupMembers
) {
CapsuleBuilder capsuleBuilder = getCapsuleBuilder(memberId);
Capsule capsule = capsuleBuilder.dueDate(ZonedDateTime.now(ZoneId.of("UTC")))
Capsule capsule = capsuleBuilder.dueDate(ZonedDateTimeSupplier.utc().get())
.build();

List<GroupCapsuleOpen> groupCapsuleOpens = GroupCapsuleOpenFixture.groupCapsuleOpensNotAllOpened(
Expand All @@ -164,7 +165,7 @@ public static Optional<Capsule> groupCapsuleEmptyOpen(
Long capsuleId
) {
CapsuleBuilder capsuleBuilder = getCapsuleBuilder(memberId);
Capsule capsule = capsuleBuilder.dueDate(ZonedDateTime.now(ZoneId.of("UTC")))
Capsule capsule = capsuleBuilder.dueDate(ZonedDateTimeSupplier.utc().get())
.build();

setFieldValue(capsule, "id", capsuleId);
Expand All @@ -178,7 +179,7 @@ public static Optional<Capsule> groupCapsuleAllMemberOpen(
List<Member> groupMembers
) {
CapsuleBuilder capsuleBuilder = getCapsuleBuilder(memberId);
Capsule capsule = capsuleBuilder.dueDate(ZonedDateTime.now(ZoneId.of("UTC")))
Capsule capsule = capsuleBuilder.dueDate(ZonedDateTimeSupplier.utc().get())
.build();

List<GroupCapsuleOpen> groupCapsuleOpens = GroupCapsuleOpenFixture.groupCapsuleOpens(true,
Expand All @@ -195,7 +196,7 @@ public static Optional<Capsule> groupCapsuleExcludeSpecificMember(
List<Member> groupMembers
) {
CapsuleBuilder capsuleBuilder = getCapsuleBuilder(memberId);
Capsule capsule = capsuleBuilder.dueDate(ZonedDateTime.now(ZoneId.of("UTC")))
Capsule capsule = capsuleBuilder.dueDate(ZonedDateTimeSupplier.utc().get())
.build();

List<GroupCapsuleOpen> groupCapsuleOpens = GroupCapsuleOpenFixture.groupCapsuleOpensNotOpenSpecificMemberId(
Expand All @@ -208,7 +209,7 @@ public static Optional<Capsule> groupCapsuleExcludeSpecificMember(

public static Optional<Capsule> groupCapsuleAlreadyOpen(Long memberId, Long capsuleId) {
CapsuleBuilder capsuleBuilder = getCapsuleBuilder(memberId);
Capsule capsule = capsuleBuilder.dueDate(ZonedDateTime.now(ZoneId.of("UTC")))
Capsule capsule = capsuleBuilder.dueDate(ZonedDateTimeSupplier.utc().get())
.build();

setFieldValue(capsule, "id", capsuleId);
Expand Down

0 comments on commit f9839b4

Please sign in to comment.