Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Datetime serialization fix (backport #7089) [release/4.8.x] #7102

Merged
merged 1 commit into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@itwin/ecschema-metadata",
"comment": "",
"type": "none"
}
],
"packageName": "@itwin/ecschema-metadata"
}
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export namespace XmlSerializationUtils {
propertyElement.textContent = propertyValue.toString();
return;
case PrimitiveType.DateTime:
propertyElement.textContent = (propertyValue as Date).getTime().toString();
propertyElement.textContent = new Date(propertyValue).getTime().toString();
return;
case PrimitiveType.Point2d:
propertyElement.textContent = `${propertyValue.x},${propertyValue.y}`;
Expand Down
9 changes: 9 additions & 0 deletions core/ecschema-metadata/src/test/Metadata/Class.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1318,6 +1318,11 @@ describe("ECClass", () => {
typeName: "dateTime",
name: "DateTime",
},
{
type: "PrimitiveProperty",
typeName: "dateTime",
name: "DateTimeString",
},
{
type: "PrimitiveProperty",
typeName: "point2d",
Expand Down Expand Up @@ -1354,6 +1359,7 @@ describe("ECClass", () => {
Long: 100,
Double: 200,
DateTime: new Date(nowTicks),
DateTimeString: "2021-08-19T16:37:42.278",
Point2D: { x: 100, y: 200 },
Point3D: { x: 100, y: 200, z: 300 },
IGeometry: "geometry",
Expand All @@ -1362,6 +1368,7 @@ describe("ECClass", () => {

testClass.addCustomAttribute(ca);
const serialized = await testClass.toXml(newDom);
const expectedTimeFromString = new Date("2021-08-19T16:37:42.278").getTime();

let element = getCAPropertyValueElement(serialized, "TestCustomAttribute", "TrueBoolean");
expect(element.textContent).to.equal("True");
Expand All @@ -1375,6 +1382,8 @@ describe("ECClass", () => {
expect(element.textContent).to.equal("200");
element = getCAPropertyValueElement(serialized, "TestCustomAttribute", "DateTime");
expect(element.textContent).to.equal(nowTicks.toString());
element = getCAPropertyValueElement(serialized, "TestCustomAttribute", "DateTimeString");
expect(element.textContent).to.equal(expectedTimeFromString.toString());
element = getCAPropertyValueElement(serialized, "TestCustomAttribute", "Point2D");
expect(element.textContent).to.equal("100,200");
element = getCAPropertyValueElement(serialized, "TestCustomAttribute", "Point3D");
Expand Down
10 changes: 10 additions & 0 deletions core/ecschema-metadata/src/test/Metadata/Property.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,11 @@ describe("Property", () => {
typeName: "dateTime",
name: "DateTime",
},
{
type: "PrimitiveProperty",
typeName: "dateTime",
name: "DateTimeString",
},
{
type: "PrimitiveProperty",
typeName: "point2d",
Expand Down Expand Up @@ -517,6 +522,7 @@ describe("Property", () => {
Long: 100,
Double: 200,
DateTime: new Date(nowTicks),
DateTimeString: "2021-08-19T16:37:42.278",
Point2D: { x: 100, y: 200 },
Point3D: { x: 100, y: 200, z: 300 },
IGeometry: "geometry",
Expand All @@ -525,6 +531,7 @@ describe("Property", () => {

property.addCustomAttribute(ca);
const serialized = await property.toXml(newDom);
const expectedTimeFromString = new Date("2021-08-19T16:37:42.278").getTime();

let element = getCAPropertyValueElement(serialized, "TestCustomAttribute", "TrueBoolean");
expect(element.textContent).to.equal("True");
Expand All @@ -538,6 +545,8 @@ describe("Property", () => {
expect(element.textContent).to.equal("200");
element = getCAPropertyValueElement(serialized, "TestCustomAttribute", "DateTime");
expect(element.textContent).to.equal(nowTicks.toString());
element = getCAPropertyValueElement(serialized, "TestCustomAttribute", "DateTimeString");
expect(element.textContent).to.equal(expectedTimeFromString.toString());
element = getCAPropertyValueElement(serialized, "TestCustomAttribute", "Point2D");
expect(element.textContent).to.equal("100,200");
element = getCAPropertyValueElement(serialized, "TestCustomAttribute", "Point3D");
Expand Down Expand Up @@ -1399,3 +1408,4 @@ describe("NavigationProperty (Deserialization not fully implemented)", () => {
});
});
});

Loading