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 {
28 public:
29 // constructor, default value is 0/0/00 (invalid date !)
30 CDate(int nDay=0, int nMonth=0, int nYear=0);
31
32 // show attributes
33 friend ostream& operator<<(ostream &mystream, const CDate& date);
34 // return class name
35 static char* ClassnameOf() { return "CDate"; }
36
37 // return current date
38 static CDate GetToday();
39
40 // validate a date
41 bool IsValid() const;
42 // determine whether it is a leap year
43 static bool IsLeapYear(int nYear);
44
45 // copy constructors
46 // non virtual
47 CDate& operator = (const CDate &date);
48 // virtual
49 virtual bool Copy (const CDate *date);
50
51 // compare two dates
52 // non virtual
53 bool operator ==(const CDate &date) const;
54 // virtual
55 virtual bool EqualValue(CDate *date) const;
56
57
58 // set attributes, returns validility of date
59 bool SetDay (int nDay);
60 bool SetMonth(int nMonth);
61 bool SetYear (int nYear);
62
63 // return attributes
64 int GetDay () const;
65 int GetMonth() const;
66 int GetYear () const;
67
68 // constants for month names'
69 enum { JANUARY = 1, FEBRUARY = 2, MARCH = 3, APRIL = 4,
70 MAY = 5, JUNE = 6, JULY = 7, AUGUST = 8,
71 SEPTEMBER = 9, OCTOBER =10, NOVEMBER =11, DECEMBER =12 };
72
73 protected:
74 // used to perform proper display in derived classes
75 virtual ostream& OutStream(ostream& mystream, bool bDebug=false) const;
76
77 private:
78 // attributes
79 int m_nDay;
80 int m_nMonth;
81 int m_nYear;
82 };
83
84
85 #endif // !defined(AFX_DATE_H__A8EA7861_08E1_11D5_9BB7_A8652B9FDD20__INCLUDED_)
86