001/*
002 * ObjectLab, http://www.objectlab.co.uk/open is sponsoring the ObjectLab Kit.
003 *
004 * Based in London, we are world leaders in the design and development
005 * of bespoke applications for the securities financing markets.
006 *
007 * <a href="http://www.objectlab.co.uk/open">Click here to learn more</a>
008 *           ___  _     _           _   _          _
009 *          / _ \| |__ (_) ___  ___| |_| |    __ _| |__
010 *         | | | | '_ \| |/ _ \/ __| __| |   / _` | '_ \
011 *         | |_| | |_) | |  __/ (__| |_| |__| (_| | |_) |
012 *          \___/|_.__// |\___|\___|\__|_____\__,_|_.__/
013 *                   |__/
014 *
015 *                     www.ObjectLab.co.uk
016 *
017 * $Id$
018 *
019 * Copyright 2006 the original author or authors.
020 *
021 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
022 * use this file except in compliance with the License. You may obtain a copy of
023 * the License at
024 *
025 * http://www.apache.org/licenses/LICENSE-2.0
026 *
027 * Unless required by applicable law or agreed to in writing, software
028 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
029 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
030 * License for the specific language governing permissions and limitations under
031 * the License.
032 */
033package net.objectlab.kit.datecalc.common;
034
035/**
036 * Interface that defines a financial market way of calculating difference in
037 * days, month (or part of) and year (or part of).
038 *
039 * @author Benoit Xhenseval
040 *
041 * @param <E>
042 *            a representation of a date, typically JDK: Date, Calendar;
043 *            Joda:LocalDate, YearMonthDay
044 *
045 */
046public interface PeriodCountCalculator<E> {
047    /**
048     * This calculates the number of days between 2 dates, it follows the given
049     * basis which means that the result could vary between the same 2 dates if
050     * the basis is different.
051     *
052     * @param start
053     *            the start date
054     * @param end
055     *            the end date
056     * @param basis
057     *            the basis to use
058     * @return number of days between end and start.
059     */
060    int dayDiff(final E start, final E end, PeriodCountBasis basis);
061
062    // -----------------------------------------------------------------------
063    //
064    // ObjectLab, world leaders in the design and development of bespoke
065    // applications for the securities financing markets.
066    // www.ObjectLab.co.uk
067    //
068    // -----------------------------------------------------------------------
069
070    /**
071     * This calculates the number of months (or fraction) between 2 dates, it
072     * follows the given basis which means that the result could vary between
073     * the same 2 dates if the basis is different.
074     *
075     * @param start
076     *            the start date
077     * @param end
078     *            the end date
079     * @param basis
080     *            the basis to use
081     * @return number of months between end and start.
082     */
083    double monthDiff(final E start, final E end, PeriodCountBasis basis);
084
085    /**
086     * This calculates the number of years (or fraction) between 2 dates, it
087     * follows the given basis which means that the result could vary between
088     * the same 2 dates if the basis is different.
089     *
090     * @param start
091     *            the start date
092     * @param end
093     *            the end date
094     * @param basis
095     *            the basis to use
096     * @return number of months between end and start.
097     */
098    double yearDiff(final E start, final E end, PeriodCountBasis basis);
099}
100
101/*
102 * ObjectLab, http://www.objectlab.co.uk/open is sponsoring the ObjectLab Kit.
103 *
104 * Based in London, we are world leaders in the design and development
105 * of bespoke applications for the securities financing markets.
106 *
107 * <a href="http://www.objectlab.co.uk/open">Click here to learn more about us</a>
108 *           ___  _     _           _   _          _
109 *          / _ \| |__ (_) ___  ___| |_| |    __ _| |__
110 *         | | | | '_ \| |/ _ \/ __| __| |   / _` | '_ \
111 *         | |_| | |_) | |  __/ (__| |_| |__| (_| | |_) |
112 *          \___/|_.__// |\___|\___|\__|_____\__,_|_.__/
113 *                   |__/
114 *
115 *                     www.ObjectLab.co.uk
116 */