Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor formatDate and formatDateShort #4249

Merged
merged 4 commits into from
Dec 4, 2022
Merged

Refactor formatDate and formatDateShort #4249

merged 4 commits into from
Dec 4, 2022

Conversation

nekiro
Copy link
Member

@nekiro nekiro commented Nov 10, 2022

Pull Request Prelude

Changes Proposed

Use fmt in formatDate and formatDateShort

Issues addressed:
None

@nekiro nekiro changed the title Refactor formatDate Refactor formatDate and formatDateShort Nov 10, 2022
@ranisalt
Copy link
Member

ranisalt commented Nov 10, 2022

Idea: create macros FMT_DATE_SHORT and FMT_DATE_LONG and use it like that:

#define FMT_DATE_SHORT "{:%d %b %Y}"

...

disconnectClient(fmt::format("Your IP has been banned until " FMT_DATE_SHORT " by {:s}.\n\nReason specified:\n{:s}", fmt::localtime(banInfo.expiresAt), banInfo.bannedBy, banInfo.reason), version);

OR

Create a function formatDate that takes a time_t and a format string:

constexpr std::string_view FMT_DATE_SHORT = "{:%d/%m/%Y %H:%M:%S}"

...

std::string formatDate(time_t time, std::string_view format) {
  return fmt::format(format, fmt::localtime(time));
}

...

formatDate(time, FMT_DATE_SHORT);

@nekiro nekiro merged commit 1e1003f into master Dec 4, 2022
@nekiro nekiro deleted the nekiro-patch-1 branch December 4, 2022 15:14
dudantas added a commit to dudantas/canary that referenced this pull request Dec 8, 2022
EPuncker pushed a commit to EPuncker/forgottenserver that referenced this pull request May 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants