Date.hpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2020-08-14
  6. * Changed: 2021-05-22
  7. *
  8. * */
  9. #ifndef LS_STD_DATE_HPP
  10. #define LS_STD_DATE_HPP
  11. #include <ls_std/base/Class.hpp>
  12. #include <ctime>
  13. namespace ls_std
  14. {
  15. class Date : public ls_std::Class
  16. {
  17. public:
  18. Date();
  19. ~Date() override = default;
  20. // arithmetic operators
  21. ls_std::Date &operator+(int _value);
  22. ls_std::Date &operator-(int _value);
  23. ls_std::Date &operator+=(int _value);
  24. ls_std::Date &operator-=(int _value);
  25. // additional functionality
  26. bool after(const ls_std::Date &_foreignDate) const;
  27. bool before(const ls_std::Date &_foreignDate) const;
  28. int getDay();
  29. int getHour();
  30. int getMinute();
  31. int getMonth();
  32. int getSecond();
  33. time_t getTime() const;
  34. int getYear();
  35. void setTime(time_t _timestamp);
  36. std::string toString();
  37. private:
  38. time_t timestamp{};
  39. tm *localTime{};
  40. void _decrementByDays(int _value);
  41. void _incrementByDays(int _value);
  42. void _init();
  43. };
  44. }
  45. #endif