1 ///////////////////////////////////////////////////////////
2 // Softwarebauelemente II, Aufgabe O2.1
3 //
4 // author: Stephan Brumme
5 // last changes: February 26, 2001
6
7 #if !defined(AFX_DATE_H__A8EA7861_08E1_11D5_9BB7_A8652B9FDD20__INCLUDED_)
8 #define AFX_DATE_H__A8EA7861_08E1_11D5_9BB7_A8652B9FDD20__INCLUDED_
9
10 #if _MSC_VER > 1000
11 #pragma once
12 #endif // _MSC_VER > 1000
13
14
15 // for basic class behaviour
16 #include "BasicClass.h"
17
18
19 ///////////////////////////////////////////////////////////
20 // the CDate class is based upon the Gregorian calender
21 // it DOES work for year between ca. 1600 and <2^31
22 // no year validation is performed
23 //
24 // general order of parameters: dd/mm/yyyy
25
26 class CDate : public CBasicClass
{
27 public:
28 // constructor, default value is 0/0/00 (invalid date !)
29 CDate(int nDay=0, int nMonth=0, int nYear=0);
30
31 // show attributes
32 friend ostream& operator<<(ostream &mystream, const CDate& date);
33 // return class name
34 static char* ClassnameOf() { return "CDate"; }
35
36 // return current date
37 static CDate GetToday();
38
39 // validate a date
40 bool IsValid() const;
41 // determine whether it is a leap year
42 static bool IsLeapYear(int nYear);
43
44 // copy constructors
45 // non virtual
46 CDate& operator = (const CDate &date);
47 // virtual
48 virtual bool Copy (const CDate *date);
49
50 // compare two dates
51 // non virtual
52 bool operator ==(const CDate &date) const;
53 // virtual
54 virtual bool EqualValue(CDate *date) const;
55
56
57 // set attributes, returns validility of date
58 bool SetDay (int nDay);
59 bool SetMonth(int nMonth);
60 bool SetYear (int nYear);
61
62 // return attributes
63 int GetDay () const;
64 int GetMonth() const;
65 int GetYear () const;
66
67 // constants for month names'
68 enum { JANUARY = 1, FEBRUARY = 2, MARCH = 3, APRIL = 4,
69 MAY = 5, JUNE = 6, JULY = 7, AUGUST = 8,
70 SEPTEMBER = 9, OCTOBER =10, NOVEMBER =11, DECEMBER =12 };
71
72 protected:
73 // used to perform proper display in derived classes
74 virtual ostream& OutStream(ostream& mystream, bool bDebug=false) const;
75
76 private:
77 // attributes
78 int m_nDay;
79 int m_nMonth;
80 int m_nYear;
81 };
82
83
84 #endif // !defined(AFX_DATE_H__A8EA7861_08E1_11D5_9BB7_A8652B9FDD20__INCLUDED_)
85
86