// -*- c++ -*-

/*
 * Jakelib2 - General purpose C++ library
 * Copyright (C) 2001 Florian Wolff  (florian@donuz.de)
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * $Id: GregorianCalendar.h,v 1.7 2003/09/07 08:03:41 florian Exp $
 */

#ifndef INCLUDE_JAKELIB2_UTIL_GREGORIANCALENDAR_H
# define INCLUDE_JAKELIB2_UTIL_GREGORIANCALENDAR_H
# include "Calendar.h"

namespace jakelib {
  namespace util {


    /**
     * Implements a Gregorian calendar. Years before 1970 are not yet handled!
     *
     * @class GregorianCalendar
     * @version $Id: GregorianCalendar.h,v 1.7 2003/09/07 08:03:41 florian Exp $
     * @author Florian 'Overflo' Wolff (florian@donuz.de)
     */
    class GregorianCalendar : public Calendar
    {
    public:

      /**
       * Creates a new \c GregorianCalendar with default timezone and 
       * the current time.
       */
      GregorianCalendar();

      /**
       * Creates a new \c GregorianCalendar with default timezone and 
       * the specified time in milliseconds since 1970.
       */
      GregorianCalendar(jlong millis);

      /**
       * Create a new \c GregorianCalendar for the specified date.
       */
      GregorianCalendar(jint year, jint month, jint date,
                        jint hour = 0, jint minute = 0,
                        jint second = 0);

      /**
       * @todo To be implemented
       */
      void add(Field field, jint amount);

      /**
       * @todo To be implemented
       */
      void roll(Field field, jboolean up);

      jint getMinimum(Field field);

      jint getMaximum(Field field);

      jint getGreatestMinimum(Field field);

      jint getLeastMaximum(Field field);

      jint getActualMinimum(Field field);

      jint getActualMaximum(Field field);

      /**
       * Determines whether the given year is a leap year.
       *
       * It is, historically incorrectly, assumed that before the Gregorian calendar
       * was instituted in 1582 every forth year was a leap year.
       */
      jboolean isLeapYear(jint year);

      /**
       * Returns the date when the Gregorian calendar was instituted (Oct 15th, 1582).
       * @todo To be implemented
       */
      Date* getGregorianChange();

    protected:

      void computeFields();

      void computeTime();

    private:

      /**
       * Return the number of leap years since 1970 for the
       * the specified year.
       */
      jint leapYearsSince1970(jint year);

      JAKELIB_DECLARE_CLASS(GregorianCalendar);
    };
  }
}

#endif
