Add td_api::birthdate.
This commit is contained in:
parent
7db0e34990
commit
7d0c93fcd9
@ -296,6 +296,7 @@ set(TDLIB_SOURCE
|
||||
td/telegram/BackgroundInfo.cpp
|
||||
td/telegram/BackgroundManager.cpp
|
||||
td/telegram/BackgroundType.cpp
|
||||
td/telegram/Birthdate.cpp
|
||||
td/telegram/BoostManager.cpp
|
||||
td/telegram/BotCommand.cpp
|
||||
td/telegram/BotCommandScope.cpp
|
||||
@ -585,6 +586,7 @@ set(TDLIB_SOURCE
|
||||
td/telegram/BackgroundInfo.h
|
||||
td/telegram/BackgroundManager.h
|
||||
td/telegram/BackgroundType.h
|
||||
td/telegram/Birthdate.h
|
||||
td/telegram/BlockListId.h
|
||||
td/telegram/BoostManager.h
|
||||
td/telegram/BotCommand.h
|
||||
@ -903,6 +905,7 @@ set(TDLIB_SOURCE
|
||||
td/telegram/AuthManager.hpp
|
||||
td/telegram/BackgroundInfo.hpp
|
||||
td/telegram/BackgroundType.hpp
|
||||
td/telegram/Birthdate.hpp
|
||||
td/telegram/BusinessAwayMessage.hpp
|
||||
td/telegram/BusinessAwayMessageSchedule.hpp
|
||||
td/telegram/BusinessConnectedBot.hpp
|
||||
|
@ -306,6 +306,7 @@ function split_file($file, $chunks, $undo) {
|
||||
'BackgroundId' => 'BackgroundId',
|
||||
'background_manager[_(-](?![.]get[(][)])|BackgroundManager' => 'BackgroundManager',
|
||||
'BackgroundType' => 'BackgroundType',
|
||||
'Birthdate' => 'Birthdate',
|
||||
'BotMenuButton|[a-z_]*_menu_button' => 'BotMenuButton',
|
||||
'boost_manager[_(-](?![.]get[(][)])|BoostManager' => 'BoostManager',
|
||||
'bot_info_manager[_(-](?![.]get[(][)])|BotInfoManager' => 'BotInfoManager',
|
||||
|
@ -576,6 +576,10 @@ botMenuButton text:string url:string = BotMenuButton;
|
||||
chatLocation location:location address:string = ChatLocation;
|
||||
|
||||
|
||||
//@description Represents a birthdate of a user @day Day of the month; 1-31 @month Month of the year; 1-12 @year Birth year; 0 if unknown
|
||||
birthdate day:int32 month:int32 year:int32 = Birthdate;
|
||||
|
||||
|
||||
//@class BusinessAwayMessageSchedule @description Describes conditions for sending of away messages by a Telegram Business account
|
||||
|
||||
//@description Send away messages always
|
||||
|
71
td/telegram/Birthdate.cpp
Normal file
71
td/telegram/Birthdate.cpp
Normal file
@ -0,0 +1,71 @@
|
||||
//
|
||||
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2024
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
#include "td/telegram/Birthdate.h"
|
||||
|
||||
#include "td/telegram/ConfigManager.h"
|
||||
|
||||
#include "td/utils/misc.h"
|
||||
|
||||
namespace td {
|
||||
|
||||
void Birthdate::init(int32 day, int32 month, int32 year) {
|
||||
if (year < 1800 || year > 3000) {
|
||||
year = 0;
|
||||
}
|
||||
if (month <= 0 || month > 12 || day <= 0 || day > HttpDate::days_in_month(year, month)) {
|
||||
return;
|
||||
}
|
||||
birthdate_ = day | (month << 5) | (year << 9);
|
||||
}
|
||||
|
||||
Birthdate::Birthdate(telegram_api::object_ptr<telegram_api::birthday> birthday) {
|
||||
if (birthday == nullptr) {
|
||||
return;
|
||||
}
|
||||
init(birthday->day_, birthday->month_, birthday->year_);
|
||||
}
|
||||
|
||||
Birthdate::Birthdate(td_api::object_ptr<td_api::birthdate> birthdate) {
|
||||
if (birthdate == nullptr) {
|
||||
return;
|
||||
}
|
||||
init(birthdate->day_, birthdate->month_, birthdate->year_);
|
||||
}
|
||||
|
||||
td_api::object_ptr<td_api::birthdate> Birthdate::get_birthdate_object() const {
|
||||
if (is_empty()) {
|
||||
return nullptr;
|
||||
}
|
||||
return td_api::make_object<td_api::birthdate>(get_day(), get_month(), get_year());
|
||||
}
|
||||
|
||||
telegram_api::object_ptr<telegram_api::birthday> Birthdate::get_input_birthday() const {
|
||||
int32 flags = 0;
|
||||
auto year = get_year();
|
||||
if (year != 0) {
|
||||
flags |= telegram_api::birthday::YEAR_MASK;
|
||||
}
|
||||
return telegram_api::make_object<telegram_api::birthday>(flags, get_day(), get_month(), year);
|
||||
}
|
||||
|
||||
bool operator==(const Birthdate &lhs, const Birthdate &rhs) {
|
||||
return lhs.birthdate_ == rhs.birthdate_;
|
||||
}
|
||||
|
||||
StringBuilder &operator<<(StringBuilder &string_builder, const Birthdate &birthdate) {
|
||||
if (birthdate.is_empty()) {
|
||||
return string_builder << "unknown birthdate";
|
||||
}
|
||||
string_builder << "birtdate " << birthdate.get_day() << '.' << birthdate.get_month();
|
||||
auto year = birthdate.get_year();
|
||||
if (year != 0) {
|
||||
string_builder << '.' << year;
|
||||
}
|
||||
return string_builder;
|
||||
}
|
||||
|
||||
} // namespace td
|
69
td/telegram/Birthdate.h
Normal file
69
td/telegram/Birthdate.h
Normal file
@ -0,0 +1,69 @@
|
||||
//
|
||||
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2024
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
#pragma once
|
||||
|
||||
#include "td/telegram/td_api.h"
|
||||
#include "td/telegram/telegram_api.h"
|
||||
|
||||
#include "td/utils/common.h"
|
||||
#include "td/utils/StringBuilder.h"
|
||||
|
||||
namespace td {
|
||||
|
||||
class Birthdate {
|
||||
public:
|
||||
Birthdate() = default;
|
||||
|
||||
explicit Birthdate(telegram_api::object_ptr<telegram_api::birthday> birthday);
|
||||
|
||||
explicit Birthdate(td_api::object_ptr<td_api::birthdate> birthdate);
|
||||
|
||||
td_api::object_ptr<td_api::birthdate> get_birthdate_object() const;
|
||||
|
||||
telegram_api::object_ptr<telegram_api::birthday> get_input_birthday() const;
|
||||
|
||||
bool is_empty() const {
|
||||
return birthdate_ == 0;
|
||||
}
|
||||
|
||||
template <class StorerT>
|
||||
void store(StorerT &storer) const;
|
||||
|
||||
template <class ParserT>
|
||||
void parse(ParserT &parser);
|
||||
|
||||
private:
|
||||
int32 birthdate_ = 0;
|
||||
|
||||
int32 get_day() const {
|
||||
return birthdate_ & 31;
|
||||
}
|
||||
|
||||
int32 get_month() const {
|
||||
return (birthdate_ >> 5) & 15;
|
||||
}
|
||||
|
||||
int32 get_year() const {
|
||||
return birthdate_ >> 9;
|
||||
}
|
||||
|
||||
void init(int32 day, int32 month, int32 year);
|
||||
|
||||
friend bool operator==(const Birthdate &lhs, const Birthdate &rhs);
|
||||
|
||||
friend StringBuilder &operator<<(StringBuilder &string_builder, const Birthdate &birthdate);
|
||||
};
|
||||
|
||||
bool operator==(const Birthdate &lhs, const Birthdate &rhs);
|
||||
|
||||
inline bool operator!=(const Birthdate &lhs, const Birthdate &rhs) {
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
StringBuilder &operator<<(StringBuilder &string_builder, const Birthdate &birthdate);
|
||||
|
||||
} // namespace td
|
25
td/telegram/Birthdate.hpp
Normal file
25
td/telegram/Birthdate.hpp
Normal file
@ -0,0 +1,25 @@
|
||||
//
|
||||
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2024
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
#pragma once
|
||||
|
||||
#include "td/telegram/Birthdate.h"
|
||||
|
||||
#include "td/utils/tl_helpers.h"
|
||||
|
||||
namespace td {
|
||||
|
||||
template <class StorerT>
|
||||
void Birthdate::store(StorerT &storer) const {
|
||||
td::store(birthdate_, storer);
|
||||
}
|
||||
|
||||
template <class ParserT>
|
||||
void Birthdate::parse(ParserT &parser) {
|
||||
td::parse(birthdate_, parser);
|
||||
}
|
||||
|
||||
} // namespace td
|
@ -60,15 +60,16 @@ class HttpDate {
|
||||
static bool is_leap(int32 year) {
|
||||
return year % 4 == 0 && (year % 100 != 0 || year % 400 == 0);
|
||||
}
|
||||
static int32 days_in_month(int32 year, int32 month) {
|
||||
static int cnt[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
|
||||
return cnt[month - 1] + (month == 2 && is_leap(year));
|
||||
}
|
||||
static int32 seconds_in_day() {
|
||||
return 24 * 60 * 60;
|
||||
}
|
||||
|
||||
public:
|
||||
static int32 days_in_month(int32 year, int32 month) {
|
||||
static int cnt[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
|
||||
return cnt[month - 1] + (month == 2 && is_leap(year));
|
||||
}
|
||||
|
||||
static Result<int32> to_unix_time(int32 year, int32 month, int32 day, int32 hour, int32 minute, int32 second);
|
||||
static Result<int32> parse_http_date(std::string slice);
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user