Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SUPINT-2411: Analysis: Expose a format attribute for nuxeo-date-picker #935

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions ui/widgets/nuxeo-date-picker.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,13 @@ import { I18nBehavior } from '../nuxeo-i18n-behavior.js';
type: Boolean,
value: false,
},
/**
* Use this property to provide custom date format
*/
format: {
type: String,
value: '',
},
};
}

Expand Down Expand Up @@ -188,9 +195,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.format ? this.format : moment.localeData().longformat('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
Loading