Date.hpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2020-08-14
  6. * Changed: 2024-05-25
  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. /*
  15. * @class(name: 'Date', package: 'time')
  16. * */
  17. namespace ls::std::time
  18. {
  19. class LS_STD_DYNAMIC_GOAL Date : public ls::std::core::Class
  20. {
  21. public:
  22. Date();
  23. ~Date() noexcept override;
  24. // arithmetic operators
  25. ls::std::time::Date &operator+(int _value);
  26. ls::std::time::Date &operator-(int _value);
  27. ls::std::time::Date &operator+=(int _value);
  28. ls::std::time::Date &operator-=(int _value);
  29. // additional functionality
  30. [[nodiscard]] bool after(const ls::std::time::Date &_foreignDate) const;
  31. [[nodiscard]] bool before(const ls::std::time::Date &_foreignDate) const;
  32. [[nodiscard]] int getDay() const;
  33. [[nodiscard]] int getHour() const;
  34. [[nodiscard]] int getMinute() const;
  35. [[nodiscard]] int getMonth() const;
  36. [[nodiscard]] int getSecond() const;
  37. [[nodiscard]] time_t getTime() const;
  38. [[nodiscard]] int getYear() const;
  39. void setTime(time_t _timestamp);
  40. [[nodiscard]] ::std::string toString() const;
  41. private:
  42. time_t timestamp{};
  43. tm localTime{};
  44. void _decrementByDays(int _value);
  45. void _incrementByDays(int _value);
  46. void _init();
  47. };
  48. }
  49. #endif