Skip to content

Commit

Permalink
add deprecated notation for changed function
Browse files Browse the repository at this point in the history
  • Loading branch information
hks2002 committed May 18, 2024
1 parent 8dcdcb4 commit 4d11551
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 16 deletions.
2 changes: 1 addition & 1 deletion trantor/utils/AsyncFileLogger.cc
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ void AsyncFileLogger::LoggerFile::switchLog(bool openNewOne)
// NOTE: Remember to update initFilenameQueue() if name format changes
std::string newName =
filePath_ + fileBaseName_ + "." +
creationDate_.toCustomizedFormattedString("%y%m%d-%H%M%S") +
creationDate_.toCustomFormattedString("%y%m%d-%H%M%S") +
std::string(seq) + fileExtName_;
#if !defined(_WIN32) || defined(__MINGW32__)
rename(fileFullName_.c_str(), newName.c_str());
Expand Down
14 changes: 7 additions & 7 deletions trantor/utils/Date.cc
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ std::string Date::toFormattedString(bool showMicroseconds) const
}
return buf;
}
std::string Date::toCustomizedFormattedString(const std::string &fmtStr,
bool showMicroseconds) const
std::string Date::toCustomFormattedString(const std::string &fmtStr,
bool showMicroseconds) const
{
char buf[256] = {0};
time_t seconds =
Expand All @@ -163,9 +163,9 @@ std::string Date::toCustomizedFormattedString(const std::string &fmtStr,
snprintf(decimals, sizeof(decimals), ".%06d", microseconds);
return std::string(buf) + decimals;
}
void Date::toCustomizedFormattedString(const std::string &fmtStr,
char *str,
size_t len) const
void Date::toCustomFormattedString(const std::string &fmtStr,
char *str,
size_t len) const
{
// not safe
time_t seconds =
Expand Down Expand Up @@ -323,8 +323,8 @@ Date Date::fromDbString(const std::string &datetime)
static_cast<double>(timezoneOffset()));
}

std::string Date::toCustomizedFormattedStringLocal(const std::string &fmtStr,
bool showMicroseconds) const
std::string Date::toCustomFormattedStringLocal(const std::string &fmtStr,
bool showMicroseconds) const
{
char buf[256] = {0};
time_t seconds =
Expand Down
67 changes: 59 additions & 8 deletions trantor/utils/Date.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ class TRANTOR_EXPORT Date
*/
std::string toFormattedString(bool showMicroseconds) const;

/* clang-format off */
/**
* @brief Generate a UTC time string formatted by the @p fmtStr
* @param fmtStr is the format string for the function strftime()
Expand All @@ -211,11 +212,27 @@ class TRANTOR_EXPORT Date
* @p showMicroseconds is false
* - "2018-01-01 10:10:25:102414" if the @p fmtStr is "%Y-%m-%d %H:%M:%S"
* and the @p showMicroseconds is true
* @deprecated Replaced by toCustomFormattedString
*/
std::string toCustomizedFormattedString(
const std::string &fmtStr,
bool showMicroseconds = false) const;

[[deprecated("Replaced by toCustomFormattedString")]]
std::string toCustomedFormattedString(const std::string &fmtStr,
bool showMicroseconds = false) const
{
return toCustomFormattedString(fmtStr, showMicroseconds);
};
/* clang-format on */
/**
* @brief Generate a UTC time string formatted by the @p fmtStr
* @param fmtStr is the format string for the function strftime()
* @param showMicroseconds whether the microseconds are returned.
* @note Examples:
* - "2018-01-01 10:10:25" if the @p fmtStr is "%Y-%m-%d %H:%M:%S" and the
* @p showMicroseconds is false
* - "2018-01-01 10:10:25:102414" if the @p fmtStr is "%Y-%m-%d %H:%M:%S"
* and the @p showMicroseconds is true
*/
std::string toCustomFormattedString(const std::string &fmtStr,
bool showMicroseconds = false) const;
/**
* @brief Generate a local time zone string, the format of the string is
* same as the method toFormattedString
Expand All @@ -225,14 +242,30 @@ class TRANTOR_EXPORT Date
*/
std::string toFormattedStringLocal(bool showMicroseconds) const;

/* clang-format off */
/**
* @brief Generate a local time zone string formatted by the @p fmtStr
*
* @param fmtStr
* @param showMicroseconds
* @return std::string
* @deprecated Replaced by toCustomFormattedString
*/
std::string toCustomizedFormattedStringLocal(
[[deprecated("Replaced by toCustomFormattedStringLocal")]]
std::string toCustomedFormattedStringLocal(const std::string &fmtStr,
bool showMicroseconds = false) const
{
return toCustomFormattedStringLocal(fmtStr, showMicroseconds);
}
/* clang-format on */
/**
* @brief Generate a local time zone string formatted by the @p fmtStr
*
* @param fmtStr
* @param showMicroseconds
* @return std::string
*/
std::string toCustomFormattedStringLocal(
const std::string &fmtStr,
bool showMicroseconds = false) const;

Expand Down Expand Up @@ -262,16 +295,34 @@ class TRANTOR_EXPORT Date
*/
static Date fromDbString(const std::string &datetime);

/* clang-format off */
/**
* @brief Generate a UTC time string.
*
* @param fmtStr The format string.
* @param str The string buffer for the generated time string.
* @param len The length of the string buffer.
* @deprecated Replaced by toCustomFormattedString
*/
[[deprecated("Replaced by toCustomFormattedString")]]
void toCustomedFormattedString(const std::string &fmtStr,
char *str,
size_t len) const
{
toCustomFormattedString(fmtStr, str, len);
}
/* clang-format on */

/**
* @brief Generate a UTC time string.
*
* @param fmtStr The format string.
* @param str The string buffer for the generated time string.
* @param len The length of the string buffer.
*/
void toCustomizedFormattedString(const std::string &fmtStr,
char *str,
size_t len) const; // UTC
void toCustomFormattedString(const std::string &fmtStr,
char *str,
size_t len) const; // UTC

/**
* @brief Return true if the time point is in a same second as another.
Expand Down

0 comments on commit 4d11551

Please sign in to comment.