data_birthday.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*
  2. This file is part of Telegram Desktop,
  3. the official desktop application for the Telegram messaging service.
  4. For license and copyright information please follow this link:
  5. https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
  6. */
  7. #pragma once
  8. namespace Data {
  9. class Birthday final {
  10. public:
  11. constexpr Birthday() = default;
  12. Birthday(int day, int month, int year = 0);
  13. [[nodiscard]] static Birthday FromSerialized(int value);
  14. [[nodiscard]] int serialize() const;
  15. [[nodiscard]] bool valid() const;
  16. [[nodiscard]] int day() const;
  17. [[nodiscard]] int month() const;
  18. [[nodiscard]] int year() const;
  19. explicit operator bool() const {
  20. return valid();
  21. }
  22. friend inline constexpr auto operator<=>(Birthday, Birthday) = default;
  23. friend inline constexpr bool operator==(Birthday, Birthday) = default;
  24. static constexpr auto kYearMin = 1875;
  25. static constexpr auto kYearMax = 2100;
  26. private:
  27. int _value = 0;
  28. };
  29. [[nodiscard]] QString BirthdayText(Birthday date);
  30. [[nodiscard]] QString BirthdayCake();
  31. [[nodiscard]] int BirthdayAge(Birthday date);
  32. [[nodiscard]] bool IsBirthdayToday(Birthday date);
  33. [[nodiscard]] rpl::producer<bool> IsBirthdayTodayValue(Birthday date);
  34. } // namespace Data