Skip to content

Commit

Permalink
[Tables] Don't deserialize DateTime to avoid losing precision (Azure#…
Browse files Browse the repository at this point in the history
…12650)

Fixes Azure#12646

Tables service supports ns precision DateTime however JavaScript doesn't. As part of entity deserialization, whenever we get a property with type Edm.DateTime we parse it into a JavaScript Date object, which can lead to losing precision.

To fix this we need to disable the default deserialization for Edm.DateTime and give the user an "edm" object, similar to what we do for Guid and Int64

```typescript
{
partitionKey: "p1",
rowKey: "r1",
blahblah: {type: "DateTime", value:"the date"}
}
```
  • Loading branch information
joheredi authored Nov 20, 2020
1 parent 54f8879 commit 1810528
Show file tree
Hide file tree
Showing 10 changed files with 74 additions and 77 deletions.
3 changes: 3 additions & 0 deletions sdk/tables/data-tables/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## 1.0.0-beta.4 (Unreleased)

### Breaking Changes

- Don't deserialize DateTime into a JavaScript Date to avoid losing precision [#12650](https://github.com/Azure/azure-sdk-for-js/pull/12650)

## 1.0.0-beta.3 (2020-11-12)

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion sdk/tables/data-tables/review/data-tables.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export type DeleteTableResponse = TableDeleteHeaders & {
// @public
export interface Edm<T extends EdmTypes> {
type: T;
value: T extends "Binary" ? Uint8Array : T extends "Boolean" ? boolean : T extends "DateTime" ? Date : T extends "Double" ? number : T extends "Int32" ? number : string;
value: T extends "Binary" ? Uint8Array : T extends "Boolean" ? boolean : T extends "Double" ? number : T extends "Int32" ? number : string;
}

// @public
Expand Down
2 changes: 0 additions & 2 deletions sdk/tables/data-tables/src/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -398,8 +398,6 @@ export interface Edm<T extends EdmTypes> {
? Uint8Array
: T extends "Boolean"
? boolean
: T extends "DateTime"
? Date
: T extends "Double"
? number
: T extends "Int32"
Expand Down
2 changes: 1 addition & 1 deletion sdk/tables/data-tables/src/serialization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ function getTypedObject(value: any, type: string): any {
case Edm.String:
return value;
case Edm.DateTime:
return new Date(value);
return { value, type: "DateTime" };
case Edm.Int64:
return { value, type: "Int64" };
case Edm.Guid:
Expand Down
Loading

0 comments on commit 1810528

Please sign in to comment.