Loading [MathJax]/extensions/tex2jax.js
cpp-stat-bench 0.24.0
Benchmark library with statistics for C++.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
system_time_point.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2021 MusicScience37 (Kenta Kabashima)
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
21
22#include <fmt/chrono.h>
23#include <fmt/format.h>
24#include <time.h>
25
26namespace fmt {
27
28auto formatter<stat_bench::clock::SystemTimePoint>::format(
30 format_context& context) const -> format_context::iterator {
31 const auto time_point = val.time_point();
32 const auto time_sec =
33 std::chrono::time_point_cast<std::chrono::seconds>(time_point);
34 const auto time_tm =
35 fmt::localtime(std::chrono::system_clock::to_time_t(time_sec));
36 const auto time_usec =
37 std::chrono::duration_cast<std::chrono::microseconds>(
38 time_point - time_sec)
39 .count();
40
41 return fmt::format_to(
42 context.out(), "{0:%FT%T}.{1:06d}{0:%z}", time_tm, time_usec);
43}
44
45} // namespace fmt
Class of time points of system clocks.
Namespace of fmt library.
Definition of SystemTimePoint class.