Date.hpp 1.7 KB

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