127 nullptr, flags, &st, customFormat,
nullptr, 0,
nullptr);
138 nullptr, flags, &st, customFormat, wbuf.data(), requiredSize,
nullptr);
145 int utf8len = WideCharToMultiByte(CP_UTF8, 0, wbuf.c_str(), -1,
nullptr, 0,
nullptr,
nullptr);
147 WideCharToMultiByte(CP_UTF8, 0, wbuf.c_str(), -1, &output[0], utf8len,
nullptr,
nullptr);
201 inline static std::string
formatTime(std::time_t t,
bool includeSeconds)
203#ifdef MUSX_RUNNING_ON_WINDOWS
207 localtime_s(&tm, &t);
208 st.wYear = WORD(tm.tm_year + 1900);
209 st.wMonth = WORD(tm.tm_mon + 1);
210 st.wDay = WORD(tm.tm_mday);
211 st.wHour = WORD(tm.tm_hour);
212 st.wMinute = WORD(tm.tm_min);
213 st.wSecond = WORD(tm.tm_sec);
214 st.wMilliseconds = 0;
218 if (!includeSeconds) {
219 flags = TIME_NOSECONDS;
223 int requiredSize = GetTimeFormatEx(
224 nullptr, flags, &st,
nullptr,
nullptr, 0);
226 if (requiredSize == 0) {
227 throw std::system_error(GetLastError(), std::system_category());
231 std::wstring wbuf(requiredSize, L
'\0');
234 int result = GetTimeFormatEx(
235 nullptr, flags, &st,
nullptr, wbuf.data(), requiredSize);
238 throw std::system_error(GetLastError(), std::system_category());
242 int utf8len = WideCharToMultiByte(CP_UTF8, 0, wbuf.c_str(), -1,
nullptr, 0,
nullptr,
nullptr);
243 std::string output(utf8len,
'\0');
244 WideCharToMultiByte(CP_UTF8, 0, wbuf.c_str(), -1, &output[0], utf8len,
nullptr,
nullptr);
245 output.resize(utf8len - 1);
252 localtime_r(&t, &tm);
254 const char* fmt =
nullptr;
256 if (includeSeconds) {
261 const char* tfmt = nl_langinfo(T_FMT);
262 if (tfmt && std::strchr(tfmt,
'H')) {
266 fmt = is24h ?
"%H:%M" :
"%I:%M %p";
269 std::ostringstream oss;
270 oss.imbue(std::locale(
""));
271 oss << std::put_time(&tm, fmt);