Skip to content

fix: change the format of the ascTime() function #3398

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

Open
wants to merge 2 commits into
base: v3/master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/utils/string.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,11 @@ inline std::string ascTime(const time_t *t) {
struct tm timeinfo;
localtime_r(t, &timeinfo);
char tstr[std::size("Www Mmm dd hh:mm:ss yyyy")];
strftime(tstr, std::size(tstr), "%c", &timeinfo);
// `%c` is equivalent to `%a %b %e %T %Y` with a fixed length, even though zero-padded
// month of day is optional, depending on the locale. This would lead to an empty space, e.g.,
// `Sat Jun 7 11:46:23 2025` (notice the two spaces before the day of month).
// Use `%d` instead and enforce padding.
strftime(tstr, std::size(tstr), "%a %b %d %T %Y", &timeinfo);
return tstr;
}

Expand Down
Loading