Skip to content

Commit

Permalink
Expand C deserialization support for xen-api dates
Browse files Browse the repository at this point in the history
Signed-off-by: Danilo Del Busso <danilo.delbusso@cloud.com>
  • Loading branch information
danilo-delbusso committed Sep 9, 2024
1 parent 92811ed commit d000344
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion ocaml/sdk-gen/c/autogen/src/xen_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -950,7 +950,26 @@ static void parse_into(xen_session *s, xmlNode *value_node,
{
struct tm tm;
memset(&tm, 0, sizeof(tm));
strptime((char *)string, "%Y%m%dT%H:%M:%S", &tm);
// We only support basic ISO8601 since the C SDK only
// connects to the XML-RPC backend
char *formats[] = {
// no dashes, no colons
"%Y%m%dT%H%M%S",
// no dashes, with colons
"%Y%m%dT%H:%M:%S",
// dashes and colons
"%Y-%m-%dT%H:%M:%S",
};
int num_formats = sizeof(formats) / sizeof(formats[0]);

for (int i = 0; i < num_formats; i++)
{
if (strptime((char *)string, formats[i], &tm) != NULL)
{
break;
}
}

((time_t *)value)[slot] = (time_t)mktime(&tm);
free(string);
}
Expand Down

0 comments on commit d000344

Please sign in to comment.