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