extensions/xnat/src/utils/IO/helpers/generateDateAndTimeLabel.js
/**
 * generateDateTimeAndLabel - Generates a time stamp and a ROICollection label.
 *
 * @param  {string} labelPrefix the prefix for the label, e.g. AIM, RTSTRUCT, etc.
 * @returns {object} An object containing the dateTime and the label.
 */
Generates a time stamp and a ROICollection label.
@param  {string} labelPrefix the prefix for the label, e.g. AIM, RTSTRUCT, etc.
@returns {object} An object containing the dateTime and the label.
Generates a time stamp and a ROICollection label . @param { string } labelPrefix the prefix for the label e . g . AIM RTSTRUCT etc . @returns { object } An object containing the dateTime and the label .
function generateDateTimeAndLabel(labelPrefix) {
  const d = new Date();
  const dateTime = {
    year: d.getFullYear().toString(),
    month: (d.getMonth() + 1).toString(),
    date: d.getDate().toString(),
    hours: d.getHours().toString(),
    minutes: d.getMinutes().toString(),
    seconds: d.getSeconds().toString(),
  };
  Object.keys(dateTime).forEach(element => {
    if (dateTime[`${element}`].length < 2) {
      dateTime[`${element}`] = '0' + dateTime[`${element}`];
    }
  });
  const milliseconds = `00${d.getMilliseconds().toString()}`.slice(-3);
  const dateTimeFormated =
    dateTime.year +
    dateTime.month +
    dateTime.date +
    dateTime.hours +
    dateTime.minutes +
    dateTime.seconds;
  return {
    dateTime: dateTimeFormated,
    label: `${labelPrefix}_${dateTimeFormated.slice(
      0,
      8
    )}_${dateTimeFormated.slice(8, 14)}_${milliseconds}`,
  };
}
function generateDateTimeAndLabel ( labelPrefix ) { const d = new Date ( ) ; const dateTime = { year : d . getFullYear ( ) . toString ( ) , month : ( d . getMonth ( ) + 1 ) . toString ( ) , date : d . getDate ( ) . toString ( ) , hours : d . getHours ( ) . toString ( ) , minutes : d . getMinutes ( ) . toString ( ) , seconds : d . getSeconds ( ) . toString ( ) , } ; Object . keys ( dateTime ) . forEach ( element => { if ( dateTime [ ` ${ element } ` ] . length < 2 ) { dateTime [ ` ${ element } ` ] = '0' + dateTime [ ` ${ element } ` ] ; } } ) ; const milliseconds = ` ${ d . getMilliseconds ( ) . toString ( ) } ` . slice ( - 3 ) ; const dateTimeFormated = dateTime . year + dateTime . month + dateTime . date + dateTime . hours + dateTime . minutes + dateTime . seconds ; return { dateTime : dateTimeFormated , label : ` ${ labelPrefix } ${ dateTimeFormated . slice ( 0 , 8 ) } ${ dateTimeFormated . slice ( 8 , 14 ) } ${ milliseconds } ` , } ; }
generateDateTimeAndLabel - Generates a time stamp and a ROICollection label.
generateDateTimeAndLabel - Generates a time stamp and a ROICollection label .
// Pad with zeros e.g. March: 3 => 03 // Pad milliseconds with zeros