std::wstring ConvertRfc822ToLocal(const std::wstring& datetime) { auto time = ConvertRfc822(datetime); std::tm local_tm = {0}; if (localtime_s(&local_tm, &time) != 0) return datetime; std::string result(100, '\0'); std::strftime(&result.at(0), result.size(), "%a, %d %b %Y %H:%M:%S", &local_tm); TIME_ZONE_INFORMATION time_zone_info = {0}; const auto time_zone_id = GetTimeZoneInformation(&time_zone_info); const auto bias = time_zone_info.Bias + time_zone_info.DaylightBias; std::wstring sign = bias <= 0 ? L"+" : L"-"; int hh = std::abs(bias) / 60; int mm = std::abs(bias) % 60; std::wstring result_with_tz = StrToWstr(result) + L" " + sign + PadChar(ToWstr(hh), L'0', 2) + PadChar(ToWstr(mm), L'0', 2); return result_with_tz; }
Date::operator std::wstring() const { // Convert to YYYY-MM-DD return PadChar(ToWstr(year), '0', 4) + L"-" + PadChar(ToWstr(month), '0', 2) + L"-" + PadChar(ToWstr(day), '0', 2); }