UNPKG

comindware.core.ui

Version:

Comindware Core UI provides the basic components like editors, lists, dropdowns, popups that we so desperately need while creating Marionette-based single-page applications.

37 lines (32 loc) 1.23 kB
import { dateHelpers } from 'utils'; export default { getDateDisplayValue(value?: string, format: string): string { let formattedDisplayValue; if (value === null) { formattedDisplayValue = ''; } else { formattedDisplayValue = moment(value).format(format || dateHelpers.getFormat('dateISO')); } return formattedDisplayValue; }, tryGetValidMoment(value?: string, format: string): string { const sortedMom = this.getPrioritySortedFormats(format).map(f => moment(value, f)); return sortedMom.find(mom => mom.isValid()); }, getPrioritySortedFormats(format) { const formatPriority = [moment.ISO_8601, dateHelpers.getFormat('dateISO')]; format && formatPriority.push(format); return formatPriority; }, getTimeDisplayValue(value?: string, format: string): string { let formattedValue; if (value === null || value === '') { formattedValue = ''; } else if (format) { formattedValue = moment(value).format(format); } else { formattedValue = dateHelpers.getDisplayTime(moment(value)); } return formattedValue; } };