Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

Date.h

Go to the documentation of this file.
00001 /*
00002  * Date.h
00003  *
00004  * Smalltalk like class library for C++
00005  * Date manipulation. Header.
00006  *
00007  * Copyright (c) 2005 Milan Cermak
00008  * This class is based on K. E. Gorlen's NIHCL library implementation
00009  */
00010 /*
00011  * This library is free software; you can redistribute it and/or
00012  * modify it under the terms of the GNU Lesser General Public
00013  * License as published by the Free Software Foundation; either
00014  * version 2.1 of the License, or (at your option) any later version.
00015  *
00016  * This library is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00019  * Lesser General Public License for more details.
00020  *
00021  * You should have received a copy of the GNU Lesser General Public
00022  * License along with this library; if not, write to the Free Software
00023  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00024  */
00025 #ifndef __DATE_H
00026 #define __DATE_H
00027 
00028 #include <stlib/Object.h>
00029 
00030 namespace Core {
00031 
00032 class String;
00033 class Stream;
00034 
00035 class Date : public Object // : public Magnitude
00036 {
00037   protected:
00038     unsigned long julian_day_number;   // Not same as Julian date.
00039                     // Jan. 29, 1988 is not the same as 88029 in Julian Day Number.
00040 
00041   private:
00042     Date(unsigned long julianDate);
00043 
00044   public:
00045     Date(int month = 1, int day = 1, int year = 1900);
00046 
00047     /* Class-accessing protocol */
00048     virtual String *className(void) const;
00049 
00050     /* Instance creation protocol */
00051     static Date *today(void);
00052 
00053     /* Accessing protocol */
00055     virtual int month(void) const;
00057     virtual int day(void) const;
00059     virtual int year(void) const;
00061     virtual int weekday(void) const;
00063     virtual int century(void) const;
00064 
00065     static int daysInMonth(int month, int year);
00066 
00067     /* Arithmetics protocol */
00071     virtual Date *addDays(int dayCount);
00077     virtual Date *addMonths(int monthCount);
00081     virtual Date *addYears(int yearCount);
00082 
00083     virtual Date *subtractDays(int dayCount);
00084     virtual Date *subtractMonths(int monthCount);
00085     virtual Date *subtractYears(int yearCount);
00086 
00087     virtual unsigned long dayDifferenceFrom(Date *date);
00088 
00089     /* Comparing protocol */
00090     virtual long hash(void) const;
00091     virtual bool isEqual(const Object *object) const;
00092     virtual bool isEqual(const Object &object) const
00093       { return Object::isEqual(object); }
00094 
00095     /* Converting protocol */
00096     virtual unsigned long asDays(void) const;
00097 
00098     /* Printing protocol */
00099     virtual void printOn(Stream *stream) const;
00100 
00101     /* Testing protocol */
00103     virtual bool isLeapYear(void) const;
00105     static bool isLeapYear(short year);
00106 
00107     /* private protocol */
00108   protected:
00109     static unsigned long julianDay(int month, int day, int year);
00110     void gregorianDate(int &month, int &day, int &year) const;
00111 };
00112 
00113 };
00114 
00115 #endif /* __DATE_H */

Generated on Mon Nov 27 09:47:54 2006 for Smalltalk like C++ Class Library by  doxygen 1.4.2