Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions lib/datetime/local.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,14 @@
*/
int datetime_get_local_timezone(int *minutes)
{
struct tm local_tm, gm_tm;
struct tm *local, *gm;
time_t clock;
DateTime dtl, dtg, dtdiff;

time(&clock);

local = localtime(&clock);
local = localtime_r(&clock, &local_tm);

datetime_set_type(&dtl, DATETIME_ABSOLUTE, DATETIME_YEAR, DATETIME_SECOND,
0);
Expand All @@ -46,7 +47,7 @@ int datetime_get_local_timezone(int *minutes)
datetime_set_minute(&dtl, (int)local->tm_min);
datetime_set_second(&dtl, (double)local->tm_sec);

gm = gmtime(&clock);
gm = gmtime_r(&clock, &gm_tm);

datetime_set_type(&dtg, DATETIME_ABSOLUTE, DATETIME_YEAR, DATETIME_SECOND,
0);
Expand Down Expand Up @@ -80,14 +81,15 @@ int datetime_get_local_timezone(int *minutes)
void datetime_get_local_time(DateTime *dt)
{
time_t clock;
struct tm local_tm;
struct tm *local;

/* first set dt to absolute full date */
datetime_set_type(dt, DATETIME_ABSOLUTE, DATETIME_YEAR, DATETIME_SECOND, 0);

/* get the current date/time */
time(&clock);
local = localtime(&clock);
local = localtime_r(&clock, &local_tm);

/* now put current {year,month,day,hour,minute,second} into dt */
datetime_set_year(dt, (int)local->tm_year + 1900);
Expand Down
12 changes: 10 additions & 2 deletions lib/datetime/same.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@
*/
int datetime_is_same(const DateTime *src, const DateTime *dst)
{
/* WARNING: doesn't allow for padding */
return memcmp(src, dst, sizeof(DateTime)) == 0;
/* Compare field-by-field (DateTime may contain padding) */
return src->year == dst->year &&
src->month == dst->month &&
src->day == dst->day &&
src->hour == dst->hour &&
src->minute == dst->minute &&
src->second == dst->second &&
src->usec == dst->usec &&
src->timezone == dst->timezone;

Comment on lines +24 to +32

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[pre-commit] reported by reviewdog 🐶

Suggested change
return src->year == dst->year &&
src->month == dst->month &&
src->day == dst->day &&
src->hour == dst->hour &&
src->minute == dst->minute &&
src->second == dst->second &&
src->usec == dst->usec &&
src->timezone == dst->timezone;
return src->year == dst->year && src->month == dst->month &&
src->day == dst->day && src->hour == dst->hour &&
src->minute == dst->minute && src->second == dst->second &&
src->usec == dst->usec && src->timezone == dst->timezone;

}
Loading