qxLib
time_string.h
Go to the documentation of this file.
1 /**
2 
3  @file time_string.h
4  @author Khrapov
5  @date 11.01.2026
6  @copyright © Nick Khrapov, 2026. All right reserved.
7 
8 **/
9 #pragma once
10 
13 
14 #include <ctime>
15 
16 namespace qx
17 {
18 
19 /**
20  @brief Format time string to the buffer
21  @tparam out_it_t - output iterator type
22  @param it - output iterator
23  @param chDateDelimiter - char to use as delimiter in date part
24  @param chTimeDelimiter - char to use as delimiter in time part
25 **/
26 template<class out_it_t>
27 inline void append_time_string(out_it_t it, char_type chDateDelimiter, char_type chTimeDelimiter) noexcept
28 {
29  std::time_t t = std::time(nullptr);
30  QX_PUSH_SUPPRESS_MSVC_WARNINGS(4996);
31  std::tm* now = std::localtime(&t);
32  QX_POP_SUPPRESS_WARNINGS();
33 
35  it,
36  QXT("{:02}{}{:02}{}{:04}_{:02}{}{:02}{}{:02}"),
37  now->tm_mday,
38  chDateDelimiter,
39  now->tm_mon,
40  chDateDelimiter,
41  now->tm_year + 1900,
42  now->tm_hour,
43  chTimeDelimiter,
44  now->tm_min,
45  chTimeDelimiter,
46  now->tm_sec);
47 }
48 
49 } // namespace qx
void append_time_string(out_it_t it, char_type chDateDelimiter, char_type chTimeDelimiter) noexcept
Format time string to the buffer.
Definition: time_string.h:27