Dgraph Live cannot parse negative years

Moved from GitHub dgraph/5778

Posted by EnricoMi:

What version of Dgraph are you using?

v20.03.3

Have you tried reproducing the issue with the latest release?

Yes

What is the hardware spec (RAM, OS)?

Unrelated

Steps to reproduce the issue (command/config used to run Dgraph).

Start a fresh temporary dgraph instance with docker:

docker run -it --rm dgraph/standalone:v20.03.3 /bin/bash

Inside, run the following commands:

dgraph zero > /dev/null 2>&1 < /dev/null &
dgraph alpha --lru_mb 1024 > /dev/null 2>&1 < /dev/null &
echo "<a> <p> \"-0001-02-03\"^^<http://www.w3.org/2001/XMLSchema#date> ." > a.rdf

Wait a bit until dgraph alpha is up, then

dgraph live --files a.rdf

It fails on the date value with:

Error while processing data file "a.rdf": During parsing chunk in processLoadFile: while parsing line "<a> <p> \"-0001-02-03\"^^<http://www.w3.org/2001/XMLSchema#date> .\n": parsing time "-0001-02-03" as "2006-01-02T15:04:05": cannot parse "-0001-02-03" as "2006"

Negative years are defined by XMLSchema as BC: https://www.w3.org/TR/xmlschema-2/#dateTime.

Expected behaviour and actual result.

The example date should be parsed as -0001-02-03, i.e. 3rd of February of year 1 BC.

anurags92 commented :

I think we parse date time here. Does this package support negative years?

@Anurag It looks like it does not support negative years: https://stackoverflow.com/questions/51578482/parsing-dates-with-negative-year-in-go

The problem on top of time.Parse is that func ParseTime picks the format based on the length of the string, where the negative year makes the string longer than expected by dateFormatYMD. Looks like negative years need to be handled for all formats inside func ParseTime.

1 Like

Yes, you are correct. This can be extended to support negative years.

Can we add this to sprint, @Shekar