Date.hpp 1.4 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: 2022-05-09
  7. *
  8. * */
  9. #ifndef LS_STD_DATE_HPP
  10. #define LS_STD_DATE_HPP
  11. #include <ls_std/core/Class.hpp>
  12. #include <ctime>
  13. namespace ls
  14. {
  15. namespace std
  16. {
  17. namespace time
  18. {
  19. class Date : public ls::std::core::Class
  20. {
  21. public:
  22. Date();
  23. ~Date() override = default;
  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. bool after(const ls::std::time::Date &_foreignDate) const;
  31. bool before(const ls::std::time::Date &_foreignDate) const;
  32. int getDay();
  33. int getHour();
  34. int getMinute();
  35. int getMonth();
  36. int getSecond();
  37. time_t getTime() const;
  38. int getYear();
  39. void setTime(time_t _timestamp);
  40. ::std::string toString();
  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. }
  50. }
  51. #endif