All files / platform/ui-next/src/utils formatDICOMDate.ts

75% Statements 6/8
50% Branches 3/6
100% Functions 1/1
75% Lines 6/8

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26                      1216x       1216x 1216x 1216x   1216x       1216x    
import moment from 'moment';
import i18n from 'i18next';
 
/**
 * Formats DICOM date.
 *
 * @param {string} date
 * @param {string} strFormat
 * @returns {string} formatted date.
 */
export function formatDICOMDate(date: string, strFormat?: string): string {
  Iif (!date) {
    return '';
  }
 
  const format = strFormat ?? i18n.t('Common:localDateFormat', 'MMM D, YYYY');
  const locale = i18n.language || 'en';
  const parsed = moment(date, ['YYYYMMDD', 'YYYY.MM.DD'], true);
 
  Iif (!parsed.isValid()) {
    return moment(date).locale(locale).format(format);
  }
 
  return parsed.locale(locale).format(format);
}