Skip to content

Commit

Permalink
sys: timeutil: expose and use macro for base year
Browse files Browse the repository at this point in the history
timeutil internally uses 1900 as base year for calculation,
that is hidden from caller context. Thus declared a macro in
the public header file, and uses that macro will let caller adjust the
calulations accordingly.

Signed-off-by: Anuj Pathak <[email protected]>
  • Loading branch information
cx-anuj-pathak authored and carlescufi committed Aug 29, 2024
1 parent b90a507 commit 836514c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 3 additions & 0 deletions include/zephyr/sys/timeutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ extern "C" {
* @{
*/

/* Base Year value use in calculations in "timeutil_timegm64" API */
#define TIME_UTILS_BASE_YEAR 1900

/**
* @brief Convert broken-down time to a POSIX epoch offset in seconds.
*
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/timeutil.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ static int64_t time_days_from_civil(int64_t y,

int64_t timeutil_timegm64(const struct tm *tm)
{
int64_t y = 1900 + (int64_t)tm->tm_year;
int64_t y = TIME_UTILS_BASE_YEAR + (int64_t)tm->tm_year;
unsigned int m = tm->tm_mon + 1;
unsigned int d = tm->tm_mday - 1;
int64_t ndays = time_days_from_civil(y, m, d);
Expand Down

0 comments on commit 836514c

Please sign in to comment.