1 | #ifndef __XMLIO_DATE__ |
---|
2 | #define __XMLIO_DATE__ |
---|
3 | |
---|
4 | namespace XMLIOSERVER |
---|
5 | { |
---|
6 | class Date |
---|
7 | { |
---|
8 | public : |
---|
9 | |
---|
10 | Date(const AbstractCalendar& cal, int yr = 0, int mth = 0, int d = 0, int hr = 0, int min = 0 , int sec = 0) : relCalendar(cal) |
---|
11 | , year(yr), month(mth), day(d), hour(hr), minute(min), second(sec) |
---|
12 | {/* Ne rien faire de plus */} |
---|
13 | |
---|
14 | Date(const Date& d) : relCalendar(d.relCalendar) |
---|
15 | , year(d.year), month(d.month), day(d.day), hour(d.hour), minute(d.minute), second(d.second) |
---|
16 | {/* Ne rien faire de plus */} |
---|
17 | |
---|
18 | operator Time(void); // Retourne le nombre de secondes écoulées depuis la date initiale définie dans le calendrier. |
---|
19 | |
---|
20 | friend std::ostream& operator<<(std::ostream& out, const Date& d) |
---|
21 | { |
---|
22 | out << d.day << "/" << d.month << "/" << d.year << "-" |
---|
23 | << d.hour << ":" << d.minute << ":" << d.second; |
---|
24 | return (out); |
---|
25 | } |
---|
26 | |
---|
27 | friend std::istream& operator>>(std::istream& in, Date& d) // Non testée. |
---|
28 | { |
---|
29 | char c = '/'; // Le caractÚre c est utilisé pour "recueillir" les séparateurs "/" et ":". |
---|
30 | in >> d.day >> c >> d.month >> c >> d.year >> c; |
---|
31 | in >> d.hour >> c >> d.minute >> c >> d.second; |
---|
32 | return (in); |
---|
33 | } |
---|
34 | |
---|
35 | static Date FromString(const string& str, const AbstractCalendar& cal); |
---|
36 | |
---|
37 | /// Divers accesseurs. |
---|
38 | int getYear (void) const { return (year); } |
---|
39 | int getMonth (void) const { return (month); } |
---|
40 | int getDay (void) const { return (day); } |
---|
41 | int getHour (void) const { return (hour); } |
---|
42 | int getMinute(void) const { return (minute); } |
---|
43 | int getSecond(void) const { return (second); } |
---|
44 | |
---|
45 | void setMonth (int newmonth) { month = newmonth; } |
---|
46 | |
---|
47 | void addMonth (int value) |
---|
48 | {// Value doit être égale à 1 ou -1. |
---|
49 | month += value; |
---|
50 | if (month == 13) { year++; month = 1 ; } |
---|
51 | if (month == 0 ) { year--; month = 12; } |
---|
52 | } |
---|
53 | void setYear (int newyear) { year = newyear; } |
---|
54 | |
---|
55 | const AbstractCalendar& getRelCalendar(void) const { return (relCalendar); } |
---|
56 | |
---|
57 | ~Date() |
---|
58 | {/* Ne rien faire de plus */} |
---|
59 | |
---|
60 | private : |
---|
61 | |
---|
62 | const AbstractCalendar& relCalendar; // Calendrier lié à la Date. |
---|
63 | int year, month, day, hour, minute, second; // Année, mois, ... |
---|
64 | |
---|
65 | }; // class Date |
---|
66 | |
---|
67 | } // namespace XMLIOSERVER |
---|
68 | |
---|
69 | #endif // __XMLIO_DATE__ |
---|