ftype-time: check for NULL from gmtime() and localtime().

On Windows, they return NULL for times prior to the Epoch.
This commit is contained in:
Guy Harris 2022-01-04 15:35:18 -08:00
parent 72a4210828
commit ec0aaf1811
1 changed files with 8 additions and 2 deletions

View File

@ -343,12 +343,18 @@ abs_time_to_ftrepr_dfilter(wmem_allocator_t *scope,
if (use_utc) {
tm = gmtime(&nstime->secs);
strftime(datetime_format, sizeof(datetime_format), "\"%Y-%m-%d %H:%M:%S%%sZ\"", tm);
if (tm != NULL)
strftime(datetime_format, sizeof(datetime_format), "\"%Y-%m-%d %H:%M:%S%%sZ\"", tm);
else
snprintf(datetime_format, sizeof(datetime_format), "Not representable");
}
else {
tm = localtime(&nstime->secs);
/* Displaying the timezone could be made into a preference. */
strftime(datetime_format, sizeof(datetime_format), "\"%Y-%m-%d %H:%M:%S%%s%z\"", tm);
if (tm != NULL)
strftime(datetime_format, sizeof(datetime_format), "\"%Y-%m-%d %H:%M:%S%%s%z\"", tm);
else
snprintf(datetime_format, sizeof(datetime_format), "Not representable");
}
if (nstime->nsecs == 0)