JsonLd to NQuads changes DataTime values to non-standard values
ludgerey opened this issue · 4 comments
ludgerey commented
var jsonLdString = "..." // contains "2015-06-22T17:37:04.1656245+02:00"
var jsonLd = JSONUtils.FromString(jsonLdString);
var nquads = (string) JsonLdProcessor.ToRDF(jsonLd, new NQuadTripleCallback()); // contains "06/22/2015 17:37:04"I am using your library to convert json-ld to nquads but it changes xsd-datetime-format to something else. It should prevent the previous format or it should use a format that is compatible with the provided type ("http://www.w3.org/2001/XMLSchema#dateTime").
Extract from JSON-LD:
[...]
"ns:date": {
"@type": "xsd:dateTime",
"@value": "2015-06-22T17:37:04.1656245+02:00"
},
[...]
Extract from NQuad:
[...]
<http://ns#EmailMessage-8259dce5-eb15-4dc8-bace-40c138fc594f> <http://ns#date> "06/22/2015 17:37:04"^^<http://www.w3.org/2001/XMLSchema#dateTime> <http://ns#EmailMessage-8259dce5-eb15-4dc8-bace-40c138fc594f> .
[...]
ludgerey commented
My hack for this:
var jsonLd = JSONUtils.FromString(jsonLdString);
var nquads = (string) JsonLdProcessor.ToRDF(jsonLd, new NQuadTripleCallback());
// restore DateTimes
var regex = new Regex(@"""([^""]+)""\^\^<http://www.w3.org/2001/XMLSchema#dateTime>");
var matches = regex.Matches(nquads);
foreach (Match match in matches)
{
var dateStr = match.Groups[1].Value;
var date = DateTime.Parse(dateStr, new CultureInfo("en-US"));
nquads = nquads.Replace(dateStr, XmlConvert.ToString(date, XmlDateTimeSerializationMode.Local));
}tpluscode commented
Indeed, this looks like the same issue