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, |
---|
11 | int yr = 0, int mth = 1, int d = 1, |
---|
12 | int hr = 0, int min = 0, int sec = 0) |
---|
13 | : relCalendar(cal) |
---|
14 | , year(yr), month(mth), day(d), hour(hr), minute(min), second(sec) |
---|
15 | { |
---|
16 | if(!this->checkDate()) |
---|
17 | WARNING("La date initialisée a été modifiée car elle était incorrecte par rapport au calendrier souhaité."); |
---|
18 | } |
---|
19 | |
---|
20 | Date(const Date& d) |
---|
21 | : relCalendar(d.getRelCalendar()), |
---|
22 | year(d.year), month(d.month) , day(d.day), |
---|
23 | hour(d.hour), minute(d.minute), second(d.second) |
---|
24 | { |
---|
25 | if(!this->checkDate()) |
---|
26 | WARNING("La date initialisée a été modifiée car elle était incorrecte par rapport au calendrier souhaité."); |
---|
27 | } |
---|
28 | |
---|
29 | Date& operator=(const Date& d) |
---|
30 | { |
---|
31 | // relCalendar = d.getRelCalendar(); << inutile si fonction bien utilisée |
---|
32 | year = d.year; month = d.month ; day = d.day; |
---|
33 | hour = d.hour; minute = d.minute; second = d.second; |
---|
34 | return (*this); |
---|
35 | } |
---|
36 | |
---|
37 | inline operator Time(void); // Retourne le nombre de secondes écoulées depuis la date initiale définie dans le calendrier. |
---|
38 | inline bool checkDate(void); // Vérifie la validité de la date. |
---|
39 | |
---|
40 | std::string toString(void) const |
---|
41 | { std::ostringstream oss; oss << (*this); return (string(oss.str())); } |
---|
42 | |
---|
43 | friend std::ostream& operator<<(std::ostream& out, const Date& d) |
---|
44 | { |
---|
45 | out << d.day << '/' << d.month << '/' << d.year << '-' |
---|
46 | << d.hour << ':' << d.minute << ':' << d.second; |
---|
47 | return (out); |
---|
48 | } |
---|
49 | |
---|
50 | friend std::istream& operator>>(std::istream& in, Date& d) // Non testée. |
---|
51 | { |
---|
52 | char c = '/'; // Le caractÚre c est utilisé pour "recueillir" les séparateurs "/" et ":". |
---|
53 | in >> d.day >> c >> d.month >> c >> d.year >> c; |
---|
54 | in >> d.hour >> c >> d.minute >> c >> d.second; |
---|
55 | if(!d.checkDate()) |
---|
56 | WARNING("La date initialisée (depuis une chaîne de caractÚres) a été modifiée car elle était incorrecte par rapport au calendrier souhaité."); |
---|
57 | return (in); |
---|
58 | } |
---|
59 | |
---|
60 | /// Divers accesseurs. |
---|
61 | int getYear (void) const { return (year ); } |
---|
62 | int getMonth (void) const { return (month ); } |
---|
63 | int getDay (void) const { return (day ); } |
---|
64 | int getHour (void) const { return (hour ); } |
---|
65 | int getMinute(void) const { return (minute); } |
---|
66 | int getSecond(void) const { return (second); } |
---|
67 | |
---|
68 | void setYear (int newyear) { year = newyear; } |
---|
69 | void setMonth (int newmonth) { month = newmonth; } |
---|
70 | |
---|
71 | void addMonth (int value) |
---|
72 | {// Value doit être égale à 1 ou -1. |
---|
73 | month += value; |
---|
74 | if (month == 13) { year++; month = 1 ; } |
---|
75 | if (month == 0 ) { year--; month = 12; } |
---|
76 | } |
---|
77 | |
---|
78 | const AbstractCalendar& getRelCalendar(void) const { return (relCalendar); } |
---|
79 | |
---|
80 | ~Date(void) |
---|
81 | {/* Ne rien faire de plus */} |
---|
82 | |
---|
83 | public : /* static */ |
---|
84 | |
---|
85 | static Date FromString(const string& str, const AbstractCalendar& cal); |
---|
86 | |
---|
87 | private : |
---|
88 | |
---|
89 | const AbstractCalendar& relCalendar; // Calendrier lié à la Date. |
---|
90 | int year, month, day, hour, minute, second; // Année, mois, ... |
---|
91 | |
---|
92 | }; // class Date |
---|
93 | |
---|
94 | } // namespace XMLIOSERVER |
---|
95 | |
---|
96 | #endif // __XMLIO_DATE__ |
---|