summaryrefslogtreecommitdiff
path: root/zen/format_unit.cpp
diff options
context:
space:
mode:
authorB. Stack <bgstack15@gmail.com>2022-09-07 14:49:22 -0400
committerB. Stack <bgstack15@gmail.com>2022-09-07 14:49:22 -0400
commit47c88c433d17948fab1d8e1d76121a72fe5938cb (patch)
treefbc1dea58a6b28f1af4a9e9b2bc8e3e1d23b2103 /zen/format_unit.cpp
parentMerge branch 'b11.23' into 'master' (diff)
downloadFreeFileSync-47c88c433d17948fab1d8e1d76121a72fe5938cb.tar.gz
FreeFileSync-47c88c433d17948fab1d8e1d76121a72fe5938cb.tar.bz2
FreeFileSync-47c88c433d17948fab1d8e1d76121a72fe5938cb.zip
add upstream 11.24
Diffstat (limited to 'zen/format_unit.cpp')
-rw-r--r--zen/format_unit.cpp27
1 files changed, 21 insertions, 6 deletions
diff --git a/zen/format_unit.cpp b/zen/format_unit.cpp
index 2aa6e094..8b3fccfe 100644
--- a/zen/format_unit.cpp
+++ b/zen/format_unit.cpp
@@ -168,12 +168,27 @@ std::wstring zen::formatNumber(int64_t n)
std::wstring zen::formatUtcToLocalTime(time_t utcTime)
{
- auto errorMsg = [&] { return _("Error") + L" (time_t: " + numberTo<std::wstring>(utcTime) + L')'; };
+ auto fmtFallback = [utcTime] //don't take "no" for an answer!
+ {
+ if (const TimeComp tc = getUtcTime(utcTime);
+ tc != TimeComp())
+ {
+ wchar_t buf[128] = {}; //the only way to format abnormally large or invalid modTime: std::strftime() will fail!
+ if (const int rv = std::swprintf(buf, std::size(buf), L"%d-%02d-%02d %02d:%02d:%02d GMT", tc.year, tc.month, tc.day, tc.hour, tc.minute, tc.second);
+ 0 < rv && rv < std::ssize(buf))
+ return std::wstring(buf, rv);
+ }
+
+ return L"time_t = " + numberTo<std::wstring>(utcTime);
+ };
const TimeComp& loc = getLocalTime(utcTime); //returns TimeComp() on error
- std::wstring dateString = utfTo<std::wstring>(formatTime(Zstr("%x %X"), loc));
- return !dateString.empty() ? dateString : errorMsg();
+ /*const*/ std::wstring dateTimeFmt = utfTo<std::wstring>(formatTime(Zstr("%x %X"), loc));
+ if (dateTimeFmt.empty())
+ return fmtFallback();
+
+ return dateTimeFmt;
}
@@ -188,9 +203,9 @@ WeekDay impl::getFirstDayOfWeekImpl() //throw SysError
const char* firstDay = ::nl_langinfo(_NL_TIME_FIRST_WEEKDAY); //[1-Sunday, 7-Saturday]
ASSERT_SYSERROR(firstDay && 1 <= *firstDay && *firstDay <= 7);
- const int weekDayStartSunday = *firstDay;
- const int weekDayStartMonday = (weekDayStartSunday - 1 + 6) % 7; //+6 == -1 in Z_7
- // [0-Monday, 6-Sunday]
+ const int weekDayStartSunday = *firstDay; //[1-Sunday, 7-Saturday]
+ const int weekDayStartMonday = (weekDayStartSunday - 2 + 7) % 7; //[0-Monday, 6-Sunday] 7 == 0 in Z_7
+
return static_cast<WeekDay>(weekDayStartMonday);
}
bgstack15