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

0% Statements 0/8
0% Branches 0/10
0% Functions 0/1
0% Lines 0/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 27 28                                                       
import moment from 'moment';
 
/**
 * Parses a DICOM study date and time into a timestamp for sorting.
 *
 * @param date - Raw date string (YYYYMMDD or YYYY.MM.DD format)
 * @param time - Raw time string (HH, HHmm, HHmmss, or HHmmss.SSS format)
 * @returns Timestamp in milliseconds, or 0 if the date is missing/invalid
 */
export function parseStudyDateTimestamp(date?: string, time?: string): number {
  const mDate = date && moment(date, ['YYYYMMDD', 'YYYY.MM.DD'], true);
  const mTime = time && moment(time, ['HH', 'HHmm', 'HHmmss', 'HHmmss.SSS'], true);
 
  Iif (mDate && mDate.isValid()) {
    const md = mDate.clone();
    Iif (mTime && mTime.isValid()) {
      md.set({
        hour: mTime.hour(),
        minute: mTime.minute(),
        second: mTime.second(),
        millisecond: mTime.millisecond(),
      });
    }
    return md.toDate().getTime();
  }
  return 0;
}