Skip to content

Commit 2352599

Browse files
Change OData store default value of deserializeDates
1 parent 448d48f commit 2352599

File tree

4 files changed

+51
-9
lines changed

4 files changed

+51
-9
lines changed

packages/devextreme/js/__internal/data/odata/m_query_adapter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ const compileCriteria = (() => {
106106

107107
return formatter(
108108
serializePropName(fieldName),
109-
serializeValue(value, protocolVersion),
109+
serializeValue(value, protocolVersion, fieldTypes?.[fieldName]),
110110
);
111111
};
112112

packages/devextreme/js/__internal/data/odata/m_utils.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -415,20 +415,20 @@ export const serializePropName = (propName) => (propName instanceof EdmLiteral
415415
? propName.valueOf()
416416
: propName.replace(/\./g, '/'));
417417

418-
const serializeValueV4 = (value) => {
418+
const serializeValueV4 = (value, fieldType) => {
419419
if (value instanceof Date) {
420420
return formatISO8601(value, false, false);
421421
}
422422
if (value instanceof Guid) {
423423
return value.valueOf();
424424
}
425425
if (Array.isArray(value)) {
426-
return `[${value.map((item) => serializeValueV4(item)).join(',')}]`;
426+
return `[${value.map((item) => serializeValueV4(item, fieldType)).join(',')}]`;
427427
}
428-
return serializeValueV2(value);
428+
return serializeValueV2(value, fieldType);
429429
};
430430

431-
const serializeValueV2 = (value) => {
431+
const serializeValueV2 = (value, fieldType) => {
432432
if (value instanceof Date) {
433433
return serializeDate(value);
434434
}
@@ -438,19 +438,22 @@ const serializeValueV2 = (value) => {
438438
if (value instanceof EdmLiteral) {
439439
return value.valueOf();
440440
}
441+
if (fieldType && ['Date', 'DateTimeOffset'].includes(fieldType)) {
442+
return value;
443+
}
441444
if (typeof value === 'string') {
442445
return serializeString(value);
443446
}
444447
return String(value);
445448
};
446449

447-
export const serializeValue = (value, protocolVersion) => {
450+
export const serializeValue = (value, protocolVersion, fieldType) => {
448451
switch (protocolVersion) {
449452
case 2:
450453
case 3:
451454
return serializeValueV2(value);
452455
case 4:
453-
return serializeValueV4(value);
456+
return serializeValueV4(value, fieldType);
454457
default: throw errors.Error('E4002');
455458
}
456459
};

packages/devextreme/js/common/data.d.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1130,8 +1130,16 @@ export type ODataContextOptions = {
11301130
/**
11311131
* @docid
11321132
* @public
1133+
* @default false
1134+
* @deprecated Use processDatesAsUtc instead
11331135
*/
11341136
deserializeDates?: boolean;
1137+
/**
1138+
* @docid
1139+
* @public
1140+
* @default false
1141+
*/
1142+
processDatesAsUtc?: boolean;
11351143
/**
11361144
* @docid
11371145
* @public
@@ -1232,8 +1240,16 @@ export type ODataStoreOptions<
12321240
/**
12331241
* @docid
12341242
* @public
1243+
* @default false
1244+
* @deprecated Use processDatesAsUtc instead
12351245
*/
12361246
deserializeDates?: boolean;
1247+
/**
1248+
* @docid
1249+
* @public
1250+
* @default false
1251+
*/
1252+
processDatesAsUtc?: boolean;
12371253
/**
12381254
* @docid
12391255
* @type_function_param1 e:Error
@@ -1247,7 +1263,9 @@ export type ODataStoreOptions<
12471263
* @default {}
12481264
* @public
12491265
*/
1250-
fieldTypes?: any;
1266+
fieldTypes?: {
1267+
[fieldName: string]: 'String' | 'Int32' | 'Int64' | 'Guid' | 'Boolean' | 'Single' | 'Decimal' | 'Date' | 'DateTimeOffset';
1268+
};
12511269
/**
12521270
* @docid
12531271
* @public

packages/devextreme/ts/dx.all.d.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3703,8 +3703,13 @@ declare module DevExpress.common.data {
37033703
}) => void;
37043704
/**
37053705
* [descr:ODataContextOptions.deserializeDates]
3706+
* @deprecated [depNote:ODataContextOptions.deserializeDates]
37063707
*/
37073708
deserializeDates?: boolean;
3709+
/**
3710+
* [descr:ODataContextOptions.processDatesAsUtc]
3711+
*/
3712+
processDatesAsUtc?: boolean;
37083713
/**
37093714
* [descr:ODataContextOptions.entities]
37103715
*/
@@ -3786,8 +3791,13 @@ declare module DevExpress.common.data {
37863791
}) => void;
37873792
/**
37883793
* [descr:ODataStoreOptions.deserializeDates]
3794+
* @deprecated [depNote:ODataStoreOptions.deserializeDates]
37893795
*/
37903796
deserializeDates?: boolean;
3797+
/**
3798+
* [descr:ODataStoreOptions.processDatesAsUtc]
3799+
*/
3800+
processDatesAsUtc?: boolean;
37913801
/**
37923802
* [descr:ODataStoreOptions.errorHandler]
37933803
*/
@@ -3799,7 +3809,18 @@ declare module DevExpress.common.data {
37993809
/**
38003810
* [descr:ODataStoreOptions.fieldTypes]
38013811
*/
3802-
fieldTypes?: any;
3812+
fieldTypes?: {
3813+
[fieldName: string]:
3814+
| 'String'
3815+
| 'Int32'
3816+
| 'Int64'
3817+
| 'Guid'
3818+
| 'Boolean'
3819+
| 'Single'
3820+
| 'Decimal'
3821+
| 'Date'
3822+
| 'DateTimeOffset';
3823+
};
38033824
/**
38043825
* [descr:ODataStoreOptions.filterToLower]
38053826
*/

0 commit comments

Comments
 (0)