Date.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2020-08-14
  6. * Changed: 2020-08-14
  7. *
  8. * */
  9. #include <iomanip>
  10. #include <sstream>
  11. #include "Date.hpp"
  12. ls_std::Date::Date() : Class("Date")
  13. {
  14. this->timestamp = std::time(nullptr);
  15. this->init();
  16. }
  17. ls_std::Date & ls_std::Date::operator+(int _value) {
  18. this->timestamp += (_value * 86400);
  19. return *this;
  20. }
  21. bool ls_std::Date::after(Date foreignDate) {
  22. return this->timestamp > foreignDate.getTime();
  23. }
  24. bool ls_std::Date::before(Date foreignDate) {
  25. return this->timestamp < foreignDate.getTime();
  26. }
  27. time_t ls_std::Date::getTime() {
  28. return this->timestamp;
  29. }
  30. void ls_std::Date::setTime(time_t _timestamp) {
  31. this->timestamp = _timestamp;
  32. this->init();
  33. }
  34. std::string ls_std::Date::toString() {
  35. std::stringstream _stream {};
  36. _stream << std::put_time(this->localTime, "%Y-%m-%d %H:%M:%S");
  37. return _stream.str();
  38. }
  39. void ls_std::Date::init() {
  40. this->localTime = std::localtime(&this->timestamp);
  41. this->localTime->tm_mon += 1;
  42. }