diff --git a/libgnucash/engine/gnc-date.cpp b/libgnucash/engine/gnc-date.cpp index 1e3236d5fc..48b3c062df 100644 --- a/libgnucash/engine/gnc-date.cpp +++ b/libgnucash/engine/gnc-date.cpp @@ -48,6 +48,7 @@ extern "C" } #include +#include #include "gnc-date.h" #include "gnc-date-p.h" @@ -201,6 +202,30 @@ gnc_gmtime (const time64 *secs) } +gint +gnc_start_of_week (void) +{ + /* icu's day of week is 1 based. Using 0 here to mean unset or error while setting */ + static int cached_result = 0; + + if (!cached_result) + { + UErrorCode err = U_ZERO_ERROR; + auto cal = icu::Calendar::createInstance (err); + if (!cal) + { + PERR("ICU error: %s\n", u_errorName (err)); + return 0; + } + + /* 1 for sunday, 2 for monday, etc. */ + cached_result = cal->getFirstDayOfWeek (err); + delete cal; + } + + return cached_result; +} + time64 gnc_mktime (struct tm* time) { diff --git a/libgnucash/engine/gnc-date.h b/libgnucash/engine/gnc-date.h index aed8d0a2df..b911fa58b9 100644 --- a/libgnucash/engine/gnc-date.h +++ b/libgnucash/engine/gnc-date.h @@ -185,6 +185,11 @@ struct tm* gnc_localtime_r (const time64 *secs, struct tm* time); */ struct tm* gnc_gmtime (const time64 *secs); +/** \brief returns an integer corresponding to locale start of week + * \return An integer 1=Sunday, 2=Monday etc. If error, return 0. + */ +gint gnc_start_of_week (void); + /** \brief calculate seconds from the epoch given a time struct * \param time: A struct tm* containing the date-time information. * The time is understood to be in the current local time zone. diff --git a/libgnucash/engine/test/CMakeLists.txt b/libgnucash/engine/test/CMakeLists.txt index 1f84c4d6c9..d9eb581d24 100644 --- a/libgnucash/engine/test/CMakeLists.txt +++ b/libgnucash/engine/test/CMakeLists.txt @@ -99,6 +99,7 @@ set(gtest_qof_LIBS ${GOBJECT_LDFLAGS} ${GMODULE_LDFLAGS} ${GTHREAD_LDFLAGS} + ${ICU4C_I18N_LDFLAGS} ${Boost_LIBRARIES} ${GTEST_LIB})