Skip to content

Commit

Permalink
SUPINT-2411: Analysis: Expose a format attribute for nuxeo-date-picker
Browse files Browse the repository at this point in the history
  • Loading branch information
swarnadipa-dev committed Sep 3, 2024
1 parent 890e0b5 commit 49195b4
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions ui/widgets/nuxeo-date-picker.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,15 @@ import { I18nBehavior } from '../nuxeo-i18n-behavior.js';
type: Boolean,
value: false,
},

/**
* Use this property to provide custom date format
*
*/
dateFormat: {
type: String,
value: ""

Check failure on line 135 in ui/widgets/nuxeo-date-picker.js

View workflow job for this annotation

GitHub Actions / lint

Missing trailing comma
}

Check failure on line 136 in ui/widgets/nuxeo-date-picker.js

View workflow job for this annotation

GitHub Actions / lint

Missing trailing comma
};
}

Expand Down Expand Up @@ -188,9 +197,10 @@ import { I18nBehavior } from '../nuxeo-i18n-behavior.js';
moment.locale(window.nuxeo.I18n.language ? window.nuxeo.I18n.language.split('-')[0] : 'en');
// tell vaadin-date-picker how to display dates since default behavior is US locales (MM-DD-YYYY)
// this way we can take advantage of moment locale and use the date format that is most suitable for the user
this.$.date.set('i18n.formatDate', (date) => this._moment(date).format(moment.localeData().longDateFormat('L')));
const convertedFormat = this.dateFormat ? this.dateFormat : moment.localeData().longDateFormat('L');
this.$.date.set('i18n.formatDate', (date) => this._moment(date).format(convertedFormat));
this.$.date.set('i18n.parseDate', (text) => {
const date = this._moment(text, moment.localeData().longDateFormat('L'));
const date = this._moment(text, convertedFormat);
return {
day: date.get('D'),
month: date.get('M'),
Expand Down

0 comments on commit 49195b4

Please sign in to comment.