This is an archive of the discontinued LLVM Phabricator instance.

[libc++][format][chrono] Fix incorrect subsecond part of `duration` in format string "%S"
AbandonedPublic

Authored by Mordante on May 4 2023, 9:38 AM.

Details

Reviewers
Guo-Shiyu
foad
Group Reviewers
Restricted Project
Summary

associated github issue: #62082

for example:

#include <chrono>
#include <format>
#include <iostream>

int main()
{
    std::cout << std::format("{0:%M:%S} {0}\n", std::chrono::duration<int, std::ratio<101, 103>>{40});
    std::cout << std::format("{0:%M:%S} {0}\n", std::chrono::duration<int, std::ratio<1, 1024>>{1511});
}

current output:

00:39.000023 40[101/103]s
00:01.0000000487 1511[1/1024]s

fixed:

00:39.223300 40[101/103]s
00:01.4755850000 1511[1/1024]s

Diff Detail

Event Timeline

Guo-Shiyu created this revision.May 4 2023, 9:38 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 4 2023, 9:38 AM
Herald added a subscriber: StephenFan. · View Herald Transcript
Guo-Shiyu requested review of this revision.May 4 2023, 9:38 AM
nikic edited reviewers, added: Restricted Project; removed: nikic.May 4 2023, 9:41 AM
philnik set the repository for this revision to rG LLVM Github Monorepo.
Herald added 1 blocking reviewer(s): Restricted Project. · View Herald TranscriptMay 4 2023, 9:43 AM
foad resigned from this revision.May 5 2023, 12:16 AM

Not my area.

Mordante requested changes to this revision.May 6 2023, 6:33 AM

Thanks for working on this! For your next upload can you either use the arc tool or a diff with a high context. That way it's easier to review the patch in context.

Can you also add tests for this change, for example the ones in the bug report. (I think using microseconds does not give the proper resolution, but that's easier to validate with tests and the CI.)

This revision now requires changes to proceed.May 6 2023, 6:33 AM
jwakely added a subscriber: jwakely.May 8 2023, 7:19 AM

(I think using microseconds does not give the proper resolution, but that's easier to validate with tests and the CI.)

Yeah, I think the second value should be formatted as 00:01.4755859375

Are you still interested to work on this patch?

Mordante commandeered this revision.Jul 10 2023, 10:40 AM
Mordante edited reviewers, added: Guo-Shiyu; removed: Mordante.

The original author seems to be MIA, I've created D154851 instead. Commandeering to abandon this patch.

Mordante abandoned this revision.Jul 10 2023, 10:41 AM