everyonce / migrate-orientdb-to-amazon-neptune

0 stars 0 forks source link

Date conversion not properly handling orientdb export dates for 1970-01-01 #2

Open characode opened 1 year ago

characode commented 1 year ago

Modified this line https://github.com/everyonce/migrate-orientdb-to-amazon-neptune/blob/main/converter/process.js#L180

To the following: if ((p.type==6 || p.type==19) && thisValue !== "") {

Orientdb database export uses unix time format and exports dates of 1970-01-01 as 0 https://orientdb.com/docs/2.2.x/Managing-Dates.html

characode commented 1 year ago

Here is final change for

`function getRow(rowObject) { let thisClassName=rowObject["@class"]; let thisClass = sourceClasses[thisClassName]; let rowArray=[formatLabel(thisClassName), formatID(rowObject["@rid"])]; if (thisClass["superClass"] && thisClass["superClass"]=="E") { rowArray=[thisClassName, formatID(rowObject["@rid"])]; rowArray.push(formatID(rowObject["out"]), formatID(rowObject["in"])); } sourceClasses[thisClassName]["properties"].forEach((p) => { let d; let thisValue = rowObject[p.name]??""; if ((p.type==6 || p.type==19) && thisValue !== "") { // DATES require conversion try { d = new Date(thisValue);

    //Orientdb database export uses unix time format and exports dates of 1970-01-01 as 0
    //https://orientdb.com/docs/2.2.x/Managing-Dates.html
    //This accounts for those dates and just logs for information purposes
    if ((thisValue===0)) {
      console.log("Decoding Date:", d, " -> ISO String.  Value in JSON: ", thisValue, " - ", p.name, ":", p.type, " field. Converted to " + d.toISOString() + "RID: "+  rowObject["@rid"]);
    }

    thisValue = d.toISOString();
  } catch (e) {
    try {
      d = new Date(thisValue / 1000);
      thisValue = d.toISOString();
    } catch (e) {
      try {
        d = new Date(thisValue/1000000);
        thisValue = d.toISOString();
      } catch (e) {
        process.stdout.write("\n");
        console.log("Problem Decoding Date:", d, " -> ISO String.  Value in JSON: ", thisValue, " - ", p.name, ":", p.type, " field.");
      }
    }
  }
} 
if(p.name=="externalIdentifier"){
    thisValue = rowObject["@rid"];
}
rowArray.push(thisValue);

}); return rowArray; }`