119 nullptr, flags, &st, customFormat,
nullptr, 0,
nullptr);
130 nullptr, flags, &st, customFormat, wbuf.data(), requiredSize,
nullptr);
137 int utf8len = WideCharToMultiByte(CP_UTF8, 0, wbuf.c_str(), -1,
nullptr, 0,
nullptr,
nullptr);
139 WideCharToMultiByte(CP_UTF8, 0, wbuf.c_str(), -1, &output[0], utf8len,
nullptr,
nullptr);
197 inline static std::string
formatTime(std::time_t t,
bool includeSeconds)
199#ifdef MUSX_RUNNING_ON_WINDOWS
203 localtime_s(&tm, &t);
204 st.wYear = WORD(tm.tm_year + 1900);
205 st.wMonth = WORD(tm.tm_mon + 1);
206 st.wDay = WORD(tm.tm_mday);
207 st.wHour = WORD(tm.tm_hour);
208 st.wMinute = WORD(tm.tm_min);
209 st.wSecond = WORD(tm.tm_sec);
210 st.wMilliseconds = 0;
214 if (!includeSeconds) {
215 flags = TIME_NOSECONDS;
219 int requiredSize = GetTimeFormatEx(
220 nullptr, flags, &st,
nullptr,
nullptr, 0);
222 if (requiredSize == 0) {
223 throw std::system_error(GetLastError(), std::system_category());
227 std::wstring wbuf(requiredSize, L
'\0');
230 int result = GetTimeFormatEx(
231 nullptr, flags, &st,
nullptr, wbuf.data(), requiredSize);
234 throw std::system_error(GetLastError(), std::system_category());
238 int utf8len = WideCharToMultiByte(CP_UTF8, 0, wbuf.c_str(), -1,
nullptr, 0,
nullptr,
nullptr);
239 std::string output(utf8len,
'\0');
240 WideCharToMultiByte(CP_UTF8, 0, wbuf.c_str(), -1, &output[0], utf8len,
nullptr,
nullptr);
241 output.resize(utf8len - 1);
248 localtime_r(&t, &tm);
250 const char* fmt =
nullptr;
252 if (includeSeconds) {
257 const char* tfmt = nl_langinfo(T_FMT);
258 if (tfmt && std::strchr(tfmt,
'H')) {
262 fmt = is24h ?
"%H:%M" :
"%I:%M %p";
265 std::ostringstream oss;
267 oss.imbue(std::locale(
""));
268 }
catch (
const std::runtime_error&) {
269 oss.imbue(std::locale::classic());
271 oss << std::put_time(&tm, fmt);