Date.hpp 1.3 KB

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