source: XMLIO_V2/dev/dev_rv/src/XMLIO/abstract_calendar.hpp @ 119

Last change on this file since 119 was 119, checked in by hozdoba, 14 years ago

Quelques modifications supplémentaires apportées aux dates et calendriers.

File size: 3.2 KB
Line 
1#ifndef __XMLIO_ABSTRACT_CALENDAR__
2#define __XMLIO_ABSTRACT_CALENDAR__
3
4namespace XMLIOSERVER
5{
6   typedef enum _monthEnum
7   {  JAN = 1, FEB = 2, MAR = 3, APR = 4 , MAY = 5 , JUN = 6 ,
8      JUL = 7, AUG = 8, SEP = 9, OCT = 10, NOV = 11, DEC = 12  } MonthEnum;
9
10   class AbstractCalendar : public AbstractObject
11   {
12      public :
13
14         virtual int getMonthLength(const Date& d) const
15         { // Retourne la durée du mois en jour.
16            static const int NoLeapMonthLength[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
17            return (NoLeapMonthLength[d.getMonth()-1]);
18         }
19
20         virtual int getYearTotalLength(const Date& d) const { return (365 * 86400); } // Retourne la durée d'une année en seconde.
21
22         virtual int getYearLength  (void) const { return (12); } // Retourne la durée d'une année en mois.
23         virtual int getDayLength   (void) const { return (24); } // Retourne la durée d'un jour en heures.
24         virtual int getHourLength  (void) const { return (60); } // Retourne la durée d'une heure en minute.
25         virtual int getMinuteLength(void) const { return (60); } // Retourne la durée d'une minute en secondes.
26
27         virtual int getNbSecond(const Date& d) const
28         { // Retourne le nombre de secondes écoulées depuis le début de l'année.
29            Date _d0(d); int  nbday = 0;
30
31            for(_d0.setMonth(1); _d0.getMonth() < d.getMonth(); _d0.setMonth(_d0.getMonth()+1))
32               nbday += getMonthLength(_d0);
33            //std::cout << "nombre de jours : " << nbday << std::endl;
34            return ((((nbday + d.getDay()) * getDayLength() + d.getHour())
35                     * getHourLength() + d.getMinute()) * getMinuteLength() + d.getSecond());
36         }
37
38         virtual string getMonthName(int _mi) const
39         {
40            static const string Monthname_str[] =
41               { "january", "february", "march"    , "april"  , "may"     , "june"    ,
42                 "july"   , "august"  , "september", "october", "november", "december" };
43            return(Monthname_str[_mi-1]);
44         }
45
46         virtual const string getMonthShortName(int _mi) const
47         { string value = getMonthName(_mi); value.resize(3); return (value); }
48
49         const Date& getInitDate(void) const { return(initDate); }
50         Date& getCurrentDate(void) { return(currentDate); }
51
52         virtual ~AbstractCalendar()
53         {/* Ne rien faire de plus */}
54
55      protected :
56
57         AbstractCalendar() : AbstractObject(), initDate(*this), currentDate(initDate)
58         {/* Ne rien faire de plus */}
59
60         AbstractCalendar(const string& _id, int yr = 0, int mth = 1, int d = 1, int hr = 0, int min = 0 , int sec = 0)
61            : AbstractObject(_id), initDate(*this, yr, mth, d, hr, min, sec), currentDate(initDate)
62         {/* Ne rien faire de plus */}
63
64         AbstractCalendar(const string& _id, const string& dateStr)
65            : AbstractObject(_id), initDate(Date::FromString(dateStr, *this)), currentDate(initDate)
66         {/* Ne rien faire de plus */}
67
68      private :
69
70         const Date initDate;
71         Date currentDate;
72
73   }; // class AbstractCalendar
74
75} // namespace XMLIOSERVER
76
77#endif // __XMLIO_ABSTRACT_CALENDAR__
Note: See TracBrowser for help on using the repository browser.