LocalDateTime
aと a DateTime
( Joda 1.3を使用) を取り、それらが互いに 30 分以内にあるかどうかを判断するメソッドを作成しようとしています。これが私が思いつく最善の方法ですが、より良い/よりクリーンで効率的な方法が必要であることはわかっています:
public boolean isWithin30MinsOfEachOther(LocalDateTime localDateTime, DateTime dateTime) {
return (
localDateTime.getYear() == dateTime.getYear() &&
localDateTime.getMonthOfYear() == dateTime.getMonthOfYear() &&
localDateTime.getDayOfMonth() == dateTime.getDayOfMonth() &&
localDateTime.getHourOfDay() == dateTime.getHourOfDay() &&
Math.abs((localDateTime.getMinuteOfHour() - dateTime.getMinuteOfHour())) <= 30
);
)
localDateTime
言うまでもなく、たとえば、2012 年 12 月 31 日 23:58:00 でありdateTime
、2013 年 1 月 1 日 00:01:00 である場合、これはうまくいかないと思います。2 つの異なる月と日の開始/終了についても同じことが言えます。助言がありますか?前もって感謝します。