summaryrefslogtreecommitdiff
path: root/zen/format_unit.cpp
diff options
context:
space:
mode:
authorB Stack <bgstack15@gmail.com>2020-10-02 14:42:30 -0400
committerB Stack <bgstack15@gmail.com>2020-10-02 14:42:30 -0400
commit8aaf029ab6046eb8cbe600a548d176c1418bd99a (patch)
treed8a89392817379e3036c42eedebf33d4fb372dfd /zen/format_unit.cpp
parentMerge branch '11.1' into 'master' (diff)
downloadFreeFileSync-8aaf029ab6046eb8cbe600a548d176c1418bd99a.tar.gz
FreeFileSync-8aaf029ab6046eb8cbe600a548d176c1418bd99a.tar.bz2
FreeFileSync-8aaf029ab6046eb8cbe600a548d176c1418bd99a.zip
add upstream 11.2
Diffstat (limited to 'zen/format_unit.cpp')
-rw-r--r--zen/format_unit.cpp39
1 files changed, 39 insertions, 0 deletions
diff --git a/zen/format_unit.cpp b/zen/format_unit.cpp
index 4984c1d7..0d75a9d4 100644
--- a/zen/format_unit.cpp
+++ b/zen/format_unit.cpp
@@ -7,12 +7,16 @@
#include "format_unit.h"
#include <ctime>
#include <cstdio>
+#include <stdexcept>
#include "basic_math.h"
+#include "sys_error.h"
#include "i18n.h"
#include "time.h"
#include "globals.h"
#include "utf.h"
+ #include <iostream>
+ #include <langinfo.h>
#include <clocale> //thousands separator
#include "utf.h" //
@@ -181,3 +185,38 @@ std::wstring zen::formatUtcToLocalTime(time_t utcTime)
}
+
+
+WeekDay impl::getFirstDayOfWeekImpl() //throw SysError
+{
+ /* testing: change locale via command line
+ ---------------------------------------
+ LC_TIME=en_DK.utf8 => Monday
+ LC_TIME=en_US.utf8 => Sunday */
+
+ 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]
+ return static_cast<WeekDay>(weekDayStartMonday);
+}
+
+
+WeekDay zen::getFirstDayOfWeek()
+{
+ static const WeekDay weekDay = []
+ {
+ try
+ {
+ return impl::getFirstDayOfWeekImpl(); //throw SysError
+ }
+ catch (const SysError& e)
+ {
+ throw std::runtime_error(std::string(__FILE__) + '[' + numberTo<std::string>(__LINE__) + "] Failed to get first day of the week." + "\n\n" +
+ utfTo<std::string>(e.toString()));
+ }
+ }();
+ return weekDay;
+}
bgstack15