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

Feature Request: Print std::chrono::time_point #1819

Closed
ubnt-kannan opened this issue Aug 14, 2020 · 1 comment · Fixed by #1837
Closed

Feature Request: Print std::chrono::time_point #1819

ubnt-kannan opened this issue Aug 14, 2020 · 1 comment · Fixed by #1837

Comments

@ubnt-kannan
Copy link

Hello. I love using your library.

I saw this issue but it was closed. Here is my usecase of time_point:

class record {
std::chrono::time_point<std::chrono::system_clock> last_modified, ...;
void init() {
    last_modified = std::chrono::system_clock::now();
}
void expired() {
    return ((std::chrono::system_clock::now() - last_modified) >  std::chrono::hours(8));
}
// Bunch of other operations that add/subtract duration to another time_point member.
};

I want to implement a print() that displays the time_point members. Here is what I do now:

void print() {
    const auto time_c = std::chrono::system_clock::to_time_t(last_modified);
    std::cout << std::ctime(&time_c);
}

I would like to use fmt::print("{}", last_modified) and be done with it. Could you please consider my request?

@vitaut
Copy link
Contributor

vitaut commented Aug 14, 2020

Sure, a PR is welcome.

vitaut pushed a commit that referenced this issue Aug 28, 2020
Add formatters for chrono::time_point and helper overloads for localtime/gmtime(time_point)
Fixes #1819
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 a pull request may close this issue.

2 participants