diff --git a/date.h b/date.h index cf28bd5..77cbe5c 100644 --- a/date.h +++ b/date.h @@ -4021,14 +4021,18 @@ format(const std::locale& loc, std::basic_string fmt, } auto& f = use_facet>(loc); basic_ostringstream os; - auto tt = system_clock::to_time_t( - floor(sys_time{tp.time_since_epoch()})); + auto ld = floor(tp); + auto ymd = year_month_day{ld}; + auto hms = make_time(floor(tp - ld)); std::tm tm{}; -#ifndef _MSC_VER - gmtime_r(&tt, &tm); -#else - gmtime_s(&tm, &tt); -#endif + tm.tm_sec = static_cast(hms.seconds().count()); + tm.tm_min = static_cast(hms.minutes().count()); + tm.tm_hour = static_cast(hms.hours().count()); + tm.tm_mday = static_cast(unsigned{ymd.day()}); + tm.tm_mon = static_cast(unsigned{ymd.month()} - 1); + tm.tm_year = int{ymd.year()} - 1900; + tm.tm_wday = static_cast(unsigned{weekday{ld}}); + tm.tm_yday = static_cast((ld - local_days{ymd.year()/1/1}).count()); f.put(os, os, os.fill(), &tm, fmt.data(), fmt.data() + fmt.size()); return os.str(); }