linked-data-dotnet/json-ld.net

JsonLd to NQuads changes DataTime values to non-standard values

ludgerey opened this issue · 4 comments

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> .
[...]

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));
}

This might be fixed in d953401 as a part of #14.

Indeed, this looks like the same issue

Closing this as fixed in 1.0.5
5bdd4e8