Skip to content

Commit bc12243

Browse files
Enhance OData date handling: Add ISO8601_DATE_DATETIME_REGEX for improved date string serialization and remove deprecated DateTime and DateTimeOffset converters from keyConverters.
1 parent 7c4eba2 commit bc12243

File tree

3 files changed

+7
-43
lines changed

3 files changed

+7
-43
lines changed

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

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const GUID_REGEX = /^(\{{0,1}([0-9a-fA-F]){8}-([0-9a-fA-F]){4}-([0-9a-fA-F]){4}-
1717

1818
const VERBOSE_DATE_REGEX = /^\/Date\((-?\d+)((\+|-)?(\d+)?)\)\/$/;
1919
const ISO8601_DATE_REGEX = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?(Z|[-+]{1}\d{2}(:?)(\d{2})?)?$/;
20+
const ISO8601_DATE_DATETIME_REGEX = /^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])(T\d{2}:\d{2}:\d{2}(\.\d+)?(Z|[-+]{1}\d{2}(:?)(\d{2})?)?)?$/;
2021

2122
// Request processing
2223
const JSON_VERBOSE_MIME_TYPE = 'application/json;odata=verbose';
@@ -443,8 +444,8 @@ const serializeValueV2 = (value, fieldType?: string) => {
443444
return value.valueOf();
444445
}
445446

446-
if (typeof value === 'string' && fieldType !== 'String' && ISO8601_DATE_REGEX.test(value)) {
447-
return formatISO8601(new Date(value), false, false);
447+
if (typeof value === 'string' && !fieldType && ISO8601_DATE_DATETIME_REGEX.test(value)) {
448+
return serializeValueV2(new EdmLiteral(value));
448449
}
449450

450451
if (typeof value === 'string') {
@@ -489,28 +490,6 @@ export const keyConverters = {
489490
Single: (value) => (value instanceof EdmLiteral ? value : new EdmLiteral(`${value}f`)),
490491

491492
Decimal: (value) => (value instanceof EdmLiteral ? value : new EdmLiteral(`${value}m`)),
492-
493-
DateTime: (value) => {
494-
if (value instanceof Date) {
495-
return value;
496-
}
497-
498-
if (typeof value === 'string') {
499-
const date = new Date(value);
500-
if (isNaN(date.getTime())) {
501-
throw new Error(`Invalid DateTime value: ${value}`);
502-
}
503-
return date;
504-
}
505-
506-
if (typeof value === 'number') {
507-
return new Date(value);
508-
}
509-
510-
throw new Error(`Cannot convert ${typeof value} to DateTime`);
511-
},
512-
513-
DateTimeOffset: (value) => keyConverters.DateTime(value),
514493
};
515494

516495
export const convertPrimitiveValue = (type, value) => {

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1247,9 +1247,7 @@ export type ODataStoreOptions<
12471247
* @default {}
12481248
* @public
12491249
*/
1250-
fieldTypes?: {
1251-
[fieldName: string]: 'String' | 'Int32' | 'Int64' | 'Guid' | 'Boolean' | 'Single' | 'Decimal' | 'DateTime' | 'DateTimeOffset';
1252-
};
1250+
fieldTypes?: any;
12531251
/**
12541252
* @docid
12551253
* @public
@@ -1264,10 +1262,10 @@ export type ODataStoreOptions<
12641262
/**
12651263
* @docid
12661264
* @type string|object
1267-
* @acceptValues "String"|"Int32"|"Int64"|"Guid"|"Boolean"|"Single"|"Decimal"|"DateTime"|"DateTimeOffset"
1265+
* @acceptValues "String"|"Int32"|"Int64"|"Guid"|"Boolean"|"Single"|"Decimal"
12681266
* @public
12691267
*/
1270-
keyType?: 'String' | 'Int32' | 'Int64' | 'Guid' | 'Boolean' | 'Single' | 'Decimal' | 'DateTime' | 'DateTimeOffset' | any;
1268+
keyType?: 'String' | 'Int32' | 'Int64' | 'Guid' | 'Boolean' | 'Single' | 'Decimal' | any;
12711269
/**
12721270
* @docid
12731271
* @public

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

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3887,18 +3887,7 @@ declare module DevExpress.common.data {
38873887
/**
38883888
* [descr:ODataStoreOptions.fieldTypes]
38893889
*/
3890-
fieldTypes?: {
3891-
[fieldName: string]:
3892-
| 'String'
3893-
| 'Int32'
3894-
| 'Int64'
3895-
| 'Guid'
3896-
| 'Boolean'
3897-
| 'Single'
3898-
| 'Decimal'
3899-
| 'DateTime'
3900-
| 'DateTimeOffset';
3901-
};
3890+
fieldTypes?: any;
39023891
/**
39033892
* [descr:ODataStoreOptions.filterToLower]
39043893
*/
@@ -3918,8 +3907,6 @@ declare module DevExpress.common.data {
39183907
| 'Boolean'
39193908
| 'Single'
39203909
| 'Decimal'
3921-
| 'DateTime'
3922-
| 'DateTimeOffset'
39233910
| any;
39243911
/**
39253912
* [descr:ODataStoreOptions.url]

0 commit comments

Comments
 (0)