Date.hpp 1.4 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: 2023-02-06
  7. *
  8. * */
  9. #ifndef LS_STD_DATE_HPP
  10. #define LS_STD_DATE_HPP
  11. #include <ctime>
  12. #include <ls-std/core/Class.hpp>
  13. #include <ls-std/os/dynamic-goal.hpp>
  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;
  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. [[nodiscard]] int getDay();
  30. [[nodiscard]] int getHour();
  31. [[nodiscard]] int getMinute();
  32. [[nodiscard]] int getMonth();
  33. [[nodiscard]] int getSecond();
  34. [[nodiscard]] time_t getTime() const;
  35. [[nodiscard]] int getYear();
  36. void setTime(time_t _timestamp);
  37. [[nodiscard]] ::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