<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/62082>62082</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[libc++][format][chrono] Subsecond part of `duration` is not correctly formatted
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
frederick-vs-ja
</td>
</tr>
</table>
<pre>
Example
```C++
#include <chrono>
#include <cstdint>
#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 ([Godbolt link](https://godbolt.org/z/PcPd8j1PW)):
```
00:39.000023 40[101/103]s
00:01.0000000487 1511[1/1024]s
```
Expected output:
```
00:39.223300 40[101/103]s
00:01.4755859375 1511[1/1024]s
```
It seems that we should convert (via `duration_cast`) `__fraction` to `precision` before writing its `count()`.
https://github.com/llvm/llvm-project/blob/9d4df97ff0ef459316cdb55f17eaea9fe9b1c1d5/libcxx/include/__chrono/formatter.h#L87
https://github.com/llvm/llvm-project/blob/9d4df97ff0ef459316cdb55f17eaea9fe9b1c1d5/libcxx/include/__chrono/formatter.h#L101-L109
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzMVU2P4ygQ_TXlC-oICuOPgw-duL1aaVZqaQ57jDDghB7HRIC7e_bXr3CcSWbUo9HcRrKC8165eK8oQIZgD5MxDYgtiDaTczw63wzeaOOt-vLwGh5eZNY7_bV5epen82iAtkAfoaCXZwe4Tc8FRW4nNc7aEOA7dfRucsCfPiRD1HaKP2EH50_yZ6R1IXojTzd6-bVTJCdpJ8AKsF6ZclVGCCEhauCPwB-Vm2NKBHx3A9cp08cI5ZYmFMU_l-EzlC1Z0LIFsZtSDN59fLWa3vXsZbRuSkqn-F3YQgDfMcoSzihPHvgTlNt8SY018KviP0juRSzm39QywdgPetPf71vjfnF2s_dmisTN8TxHQpJwsf3L6d6NkYx2-gKiBayOMZ7DYqID7A4XfuP8AbD7D7B7Vs-6emHP_6ap0-yPH05KUz14vaGUUuQkpyC2S9G7VHPRhrswypYwSmlelWRxJraXUMxvsR_aeno_GxWNXn39Sg4i55T-Uk5eClGJmpfiN-X8HUkw5hRIPMpI3gwJRzePmig3vRofU9VfrSRQ0Ouq75UMMWXBOsH7_eClWtqhoCS6hJ29UTasUG8G5w158zba6UBsDClEuXmK674r6OYi5oeltPE49xvlToDdOL5eh4ezdy9GRcCuH10P2NU610NdDgM1Qy5qzgqleyEGVhppZD2YumeKaZES2F69vwN26-kA2O33a3Njd9ki0fjNEZB_qsr7Uv1p6hhlD58YrTPdcF3zWmamYUXFsCgqyrJjU-WM5WaoeVWgYoXWOAx1xUxR9FVthMpsgxQ5zVkaOLLNwKmqUClKB2SGScipOUk7bpKztKcyG8JsmgJphdkoezOG5SJAnMwbWch0cog2881SjX4-BMjpaEMMtyzRxnG5QZLh9ToQLYjtekYt76tv0ZLPcx-McpMmZ-kjccN9P6Yes4FMLhLlvDcqjl_JtVQ6m_3Y_PbKLUYCYLcY_T8AAP__fVT2Ng">