/** * Copyright (C) 2009 - present by OpenGamma Inc. and the OpenGamma group of companies * * Please see distribution for license. */ package com.opengamma.analytics.financial.schedule; import java.util.ArrayList; import java.util.List; import org.threeten.bp.LocalDate; import org.threeten.bp.ZonedDateTime; import com.opengamma.util.ArgumentChecker; /** * */ public class DailyScheduleCalculator extends Schedule { @Override public LocalDate[] getSchedule(final LocalDate startDate, final LocalDate endDate, final boolean fromEnd, final boolean generateRecursive) { return getSchedule(startDate, endDate); } public LocalDate[] getSchedule(final LocalDate startDate, final LocalDate endDate) { ArgumentChecker.notNull(startDate, "start date"); ArgumentChecker.notNull(endDate, "end date"); ArgumentChecker.isFalse(startDate.isAfter(endDate), "start date must not be after end date"); if (startDate.equals(endDate)) { return new LocalDate[] {startDate}; } final List<LocalDate> dates = new ArrayList<>(); LocalDate date = startDate; while (!date.isAfter(endDate)) { dates.add(date); date = date.plusDays(1); } return dates.toArray(EMPTY_LOCAL_DATE_ARRAY); } @Override public ZonedDateTime[] getSchedule(final ZonedDateTime startDate, final ZonedDateTime endDate, final boolean fromEnd, final boolean generateRecursive) { return getSchedule(startDate, endDate); } public ZonedDateTime[] getSchedule(final ZonedDateTime startDate, final ZonedDateTime endDate) { ArgumentChecker.notNull(startDate, "start date"); ArgumentChecker.notNull(endDate, "end date"); ArgumentChecker.isFalse(startDate.isAfter(endDate), "start date must not be after end date"); if (startDate.equals(endDate)) { return new ZonedDateTime[] {startDate}; } final List<ZonedDateTime> dates = new ArrayList<>(); ZonedDateTime date = startDate; while (!date.isAfter(endDate)) { dates.add(date); date = date.plusDays(1); } return dates.toArray(EMPTY_ZONED_DATE_TIME_ARRAY); } }