Skip to content

Commit 3e607e1

Browse files
committed
Handle formatting "day since 2001-01-01 00:00:00 UTC"
1 parent cacf97b commit 3e607e1

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

lib/formatter.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -1073,7 +1073,9 @@ printTimestamp(
10731073
}
10741074

10751075
if (nchar >= 0) {
1076-
int decimalCount = -(int)floor(log10(resolution));
1076+
int decimalCount = resolution <= 0.0
1077+
? 9 // Nanosecond resolution
1078+
: -(int)floor(log10(resolution));
10771079

10781080
if (decimalCount > -2) {
10791081
n = snprintf(buf+nchar, size,

lib/testUnits.c

+27-3
Original file line numberDiff line numberDiff line change
@@ -2026,9 +2026,9 @@ test_xml(void)
20262026
int status;
20272027
ut_unit* unit1;
20282028
ut_unit* unit2;
2029-
cv_converter* converter;
2030-
char* spec;
2031-
ut_unit* unit;
2029+
cv_converter* converter;
2030+
char* spec;
2031+
ut_unit* unit;
20322032

20332033
ut_set_error_message_handler(ut_write_to_stderr);
20342034
xmlSystem = ut_read_xml(xmlPath);
@@ -2280,6 +2280,29 @@ test_mm2_day2_divide(void)
22802280
ut_free_system(xmlSystem);
22812281
}
22822282

2283+
2284+
test_timeResolution(void)
2285+
{
2286+
ut_system* xmlSystem;
2287+
2288+
ut_set_error_message_handler(ut_write_to_stderr);
2289+
xmlSystem = ut_read_xml(xmlPath);
2290+
CU_ASSERT_PTR_NOT_NULL_FATAL(xmlSystem);
2291+
2292+
// Maximum temporal resolution:
2293+
const char string[] = "day since 2001-01-01 00:00:00.000000000 UTC";
2294+
ut_unit* unit = ut_parse(xmlSystem, string, UT_ASCII);
2295+
CU_ASSERT_PTR_NOT_NULL_FATAL(unit);
2296+
2297+
char buf[128];
2298+
int len = ut_format(unit, buf, sizeof(buf), UT_ASCII | UT_NAMES);
2299+
CU_ASSERT_NOT_EQUAL_FATAL(len, -1);
2300+
printf("test_timeResolution() unit=\"%s\"", buf);
2301+
CU_ASSERT_STRING_EQUAL(buf, string);
2302+
2303+
ut_free(unit);
2304+
}
2305+
22832306
int
22842307
main(
22852308
const int argc,
@@ -2331,6 +2354,7 @@ main(
23312354
CU_ADD_TEST(testSuite, test_parsing);
23322355
CU_ADD_TEST(testSuite, test_visitor);
23332356
CU_ADD_TEST(testSuite, test_xml);
2357+
CU_ADD_TEST(testSuite, test_timeResolution);
23342358
/*
23352359
*/
23362360

0 commit comments

Comments
 (0)