date.hpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #ifndef __XIOS_CDate__
  2. #define __XIOS_CDate__
  3. /// XIOS headers ///
  4. #include "xios_spl.hpp"
  5. #include "exception.hpp"
  6. #include "duration.hpp"
  7. namespace xios
  8. {
  9. /// ////////////////////// Déclarations ////////////////////// ///
  10. class CCalendar;
  11. class CDate
  12. {
  13. public :
  14. /// Constructeurs ///
  15. //!< Create an empty date associated to no calendar
  16. CDate(void);
  17. //!< Create an empty date associated to the specified calendar
  18. CDate(const CCalendar& cal);
  19. //!< Create a date associated to the specified calendar
  20. CDate(const CCalendar& cal, int yr, int mth, int d,
  21. int hr = 0, int min = 0, int sec = 0);
  22. CDate(const CDate& odate);
  23. CDate(const CDate* const odate); // Not implemented yet
  24. /// Destructeur ///
  25. ~CDate(void);
  26. /// Opérateurs ///
  27. CDate& operator=(const CDate& date);
  28. bool operator==(const CDate& date);
  29. friend StdOStream& operator<<(StdOStream& out, const CDate& date);
  30. friend StdIStream& operator>>(StdIStream& in, CDate& date);
  31. //!< Return the number of seconds since the time origin fixed when creating the calendar
  32. operator Time(void) const;
  33. /// Traitements ///
  34. bool checkDate(void); // Vérifie la validité de la date.
  35. /// Divers accesseurs ///
  36. int getYear (void) const;
  37. int getMonth (void) const;
  38. int getDay (void) const;
  39. int getHour (void) const;
  40. int getMinute(void) const;
  41. int getSecond(void) const;
  42. //!< Get the calendar associated to the date
  43. const CCalendar& getRelCalendar(void) const;
  44. bool hasRelCalendar(void) const;
  45. //!< Get the number of seconds since the beginning of the year
  46. int getSecondOfYear() const;
  47. //!< Get the number of days (expressed as a real number) since the beginning of the year
  48. double getDayOfYear() const;
  49. //!< Get the fraction of the current year as a real number between 0 and 1
  50. double getFractionOfYear() const;
  51. //!< Get the number of seconds since the beginning of the day
  52. int getSecondOfDay() const;
  53. //!< Get the fraction of the current day as a real number between 0 and 1
  54. double getFractionOfDay() const;
  55. /// Mutateurs ///
  56. void setYear (int newyear);
  57. void setMonth (int newmonth);
  58. void setDay (int newday);
  59. void setHour (int newhour);
  60. void setMinute(int newminute);
  61. void setSecond(int newsecond);
  62. void setDate(int yr, int mth, int d,
  63. int hr = 0, int min = 0, int sec = 0);
  64. void addMonth (int value);
  65. //!< Set the calendar associated to the date
  66. bool setRelCalendar(const CCalendar& relCalendar);
  67. /// Autres ///
  68. StdString toString(void) const;
  69. StdString getStryyyymmdd(void) const;
  70. string getStr(const string& str) const;
  71. public : /* static */
  72. static CDate FromString(const StdString& str, const CCalendar& calendar);
  73. private :
  74. /// Propriétés privées ///
  75. const CCalendar* relCalendar; //!< Calendar associated to the date
  76. int year, month, day, hour, minute, second; // Année, mois, ...
  77. }; // class CDate;
  78. } // namespace xios
  79. #endif // __XIOS_CDate__