mirror of
https://github.com/Gnucash/gnucash.git
synced 2024-11-26 19:00:18 -06:00
[gnc-date][API] find locale's start of week using ICU.
gnc_start_of_week * ICU has a mature C++ api, so prefer that one in our C++ code * Use PERR instead of fprintf for consistent reporting * Add the ICU specific linker flags to the test case
This commit is contained in:
parent
bdbb06b722
commit
ec6602adf9
@ -48,6 +48,7 @@ extern "C"
|
||||
}
|
||||
|
||||
#include <cinttypes>
|
||||
#include <unicode/calendar.h>
|
||||
|
||||
#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)
|
||||
{
|
||||
|
@ -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.
|
||||
|
@ -99,6 +99,7 @@ set(gtest_qof_LIBS
|
||||
${GOBJECT_LDFLAGS}
|
||||
${GMODULE_LDFLAGS}
|
||||
${GTHREAD_LDFLAGS}
|
||||
${ICU4C_I18N_LDFLAGS}
|
||||
${Boost_LIBRARIES}
|
||||
${GTEST_LIB})
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user