add test for timestamp millisec

This commit is contained in:
CK Tan 2021-07-04 19:41:16 -07:00
parent bf0447ab49
commit 45921ae3db
3 changed files with 22 additions and 28 deletions

View file

@ -1,5 +1,5 @@
odt1 = 1979-05-27T07:32:00Z
odt2 = 1979-05-27T00:32:00-07:00
odt3 = 1979-05-27T00:32:00.999999-07:00
odt4 = 1979-05-27T00:32:00.1-07:00
odt4 = 1979-05-27T00:32:00.01-07:00

View file

@ -2,5 +2,5 @@
odt1 = 1979-05-27T07:32:00Z,
odt2 = 1979-05-27T00:32:00-07:00,
odt3 = 1979-05-27T00:32:00.999-07:00,
odt4 = 1979-05-27T00:32:00.100-07:00,
odt4 = 1979-05-27T00:32:00.010-07:00,
}

View file

@ -93,6 +93,24 @@ static void print_string(const char* s)
static void print_array(toml_array_t* arr);
static void print_timestamp(toml_datum_t d)
{
if (d.u.ts->year) {
printf("%04d-%02d-%02d%s", *d.u.ts->year, *d.u.ts->month, *d.u.ts->day,
d.u.ts->hour ? "T" : "");
}
if (d.u.ts->hour) {
printf("%02d:%02d:%02d", *d.u.ts->hour, *d.u.ts->minute, *d.u.ts->second);
if (d.u.ts->millisec) {
printf(".%03d", *d.u.ts->millisec);
}
if (d.u.ts->z) {
printf("%s", d.u.ts->z);
}
}
}
static void print_table(toml_table_t* curtab)
{
@ -165,19 +183,7 @@ static void print_table(toml_table_t* curtab)
if (d.ok) {
prindent();
printf("%s = ", key);
if (d.u.ts->year) {
printf("%04d-%02d-%02d%s", *d.u.ts->year, *d.u.ts->month, *d.u.ts->day,
d.u.ts->hour ? "T" : "");
}
if (d.u.ts->hour) {
printf("%02d:%02d:%02d", *d.u.ts->hour, *d.u.ts->minute, *d.u.ts->second);
if (d.u.ts->millisec) {
printf(".%d", *d.u.ts->millisec);
}
if (d.u.ts->z) {
printf("%s", d.u.ts->z);
}
}
print_timestamp(d);
printf(",\n");
free(d.u.ts);
continue;
@ -254,19 +260,7 @@ static void print_array(toml_array_t* curarr)
d = toml_timestamp_at(curarr, i);
if (d.ok) {
prindent();
if (d.u.ts->year) {
printf("%04d-%02d-%02d%s", *d.u.ts->year, *d.u.ts->month, *d.u.ts->day,
d.u.ts->hour ? "T" : "");
}
if (d.u.ts->hour) {
printf("%02d:%02d:%02d", *d.u.ts->hour, *d.u.ts->minute, *d.u.ts->second);
if (d.u.ts->millisec) {
printf(".%d", *d.u.ts->millisec);
}
if (d.u.ts->z) {
printf("%s", d.u.ts->z);
}
}
print_timestamp(d);
printf(",\n");
free(d.u.ts);
continue;