Skip to content

Commit

Permalink
update :: 시간 나라 설정
Browse files Browse the repository at this point in the history
  • Loading branch information
Umjiseung committed Jul 17, 2024
1 parent 85223cd commit 727322f
Showing 1 changed file with 15 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,18 @@
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.util.Date;
import java.time.ZoneId;
import java.util.List;
import java.util.Objects;


@ServiceWithTransaction
@RequiredArgsConstructor
@Slf4j
public class ChangeEventStatusServiceImpl implements ChangeEventStatusService {

private final EventRepository eventRepository;
private final ZoneId zoneId = ZoneId.of("Asia/Seoul");

public void execute() {
log.info("===================이벤트 스케줄러 시작===================");
Expand All @@ -34,8 +32,10 @@ public void execute() {
}

private void saveChangePast(List<Event> nowEvents) {
for (Event event: nowEvents) {
if (Objects.equals(event.getStarted_at(), LocalDate.now())) {
LocalDate now = LocalDate.now(zoneId);

for (Event event : nowEvents) {
if (Objects.equals(event.getStarted_at(), now)) {
event.changeStatus(Status.PAST);
eventRepository.save(event);
log.info("EventId: {}, status: NOW -> PAST", event.getId());
Expand All @@ -45,21 +45,17 @@ private void saveChangePast(List<Event> nowEvents) {
}

private void saveChangeNow(List<Event> pendingEvents) {
try {

SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
Date now = formatter.parse(String.valueOf(LocalDate.now()));
LocalDate now = LocalDate.now(zoneId);

for (Event event: pendingEvents) {
Date endDate = formatter.parse(String.valueOf(event.getEnded_at()));
for (Event event : pendingEvents) {
LocalDate endDate = event.getEnded_at();

if (now.after(endDate)) {
event.changeStatus(Status.NOW);
eventRepository.save(event);
log.info("EventId: {}, status: PENDING -> NOW", event.getId());
}
if (now.isAfter(endDate)) {
event.changeStatus(Status.NOW);
eventRepository.save(event);
log.info("EventId: {}, status: PENDING -> NOW", event.getId());
}
log.info("===================EventPendingToNow End===================");
} catch (ParseException e) {}
}
log.info("===================EventPendingToNow End===================");
}
}

0 comments on commit 727322f

Please sign in to comment.