From d88985f7ee6292058d8ba017dc7ee50217df6bf3 Mon Sep 17 00:00:00 2001 From: mjkhan21 Date: Mon, 2 Sep 2024 15:23:07 +0900 Subject: [PATCH] =?UTF-8?q?dateDiff(Date,=20int)=20->=20add(Date,=20int)?= =?UTF-8?q?=20=EC=88=98=EC=A0=95,=20getDates(Date,=20int)=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../foundation/component/AbstractBean.java | 27 +++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/main/java/cokr/xit/foundation/component/AbstractBean.java b/src/main/java/cokr/xit/foundation/component/AbstractBean.java index 7244100..e19ab17 100644 --- a/src/main/java/cokr/xit/foundation/component/AbstractBean.java +++ b/src/main/java/cokr/xit/foundation/component/AbstractBean.java @@ -1,6 +1,9 @@ package cokr.xit.foundation.component; +import java.util.Collections; import java.util.Date; +import java.util.List; +import java.util.stream.IntStream; import javax.annotation.Resource; @@ -92,12 +95,32 @@ public abstract class AbstractBean extends AbstractComponent { return isEmpty(logName) ? super.log() : Log.get(logName); } - /**주어진 Date에 지정한 날짜수만큼의 차이의 Date를 반환한다. + /**주어진 날짜에 지정한 수만큼 더한 날짜를 반환한다. * @param date 날짜 * @param days 날짜수 * @return 새 Date */ - protected static Date dateDiff(Date date, int days) { + protected static Date add(Date date, int days) { return new Date(date.getTime() + (1000L * 60L * 60L * 24L * days)); } + + /**주어진 날짜부터 지정한 수만큼 증가하는 날짜들을 반환한다. + * @param date 날짜 + * @param days 날짜수 + * + * @return 주어진 날짜부터 지정한 날짜수만큼 더한 날짜들 + */ + protected static List getDates(Date date, int days) { + if (date == null) + return Collections.emptyList(); + if (days == 0) + return List.of(date); + + return IntStream.range(0, Math.abs(days)).boxed() + .map(num -> add(date, days > 0 ? num : -num)) + .toList(); + } } \ No newline at end of file