diff --git a/index.cds b/index.cds index 147e6be..f637c20 100644 --- a/index.cds +++ b/index.cds @@ -84,7 +84,8 @@ annotate ChangeView with @(UI: { RequestAtLeast: [ parentKey, serviceEntity, - serviceEntityPath + serviceEntityPath, + valueDataType ], SortOrder : [{ Property : createdAt, diff --git a/lib/localization.js b/lib/localization.js index 2fd5b39..0ed6275 100644 --- a/lib/localization.js +++ b/lib/localization.js @@ -101,6 +101,20 @@ const _getLabelI18nKeyOnEntity = function (entityName, /** optinal */ attribute) return def['@Common.Label'] || def['@title']; }; +const dateFormatOptions = { + year: 'numeric', + month: 'short', + day: 'numeric', +} +const _localizeDates = (change, locale) => { + if (change.valueDataType === 'cds.Date') { + if (change.valueChangedFrom) + change.valueChangedFrom = new Date(change.valueChangedFrom).toLocaleDateString(locale.replaceAll('_', '-'), dateFormatOptions) //locale.replace because en_GB is unknown to function and it has to be en-GB + if (change.valueChangedTo) + change.valueChangedTo = new Date(change.valueChangedTo).toLocaleDateString(locale.replaceAll('_', '-'), dateFormatOptions) + } +} + const localizeLogFields = function (data, locale) { if (!locale) return for (const change of data) { @@ -108,6 +122,7 @@ const localizeLogFields = function (data, locale) { _localizeAttribute(change, locale); _localizeEntityType(change, locale); _localizeDefaultObjectID(change, locale); + _localizeDates(change, locale); } }; module.exports = {