Need a unique gift idea?
A Pastebin account makes a great Christmas gift
SHARE
TWEET

Untitled

a guest Dec 7th, 2018 54 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. export const formatDurationUtils = durationObject => {
  2.   const duration = ['00H', '00M', '00S'];
  3.  
  4.   if (durationObject.hours) {
  5.     duration[0] = `${durationObject.hours || '00'}H`;
  6.   }
  7.  
  8.   if (durationObject.mins) {
  9.     duration[1] = `${durationObject.mins || '00'}M`;
  10.   }
  11.  
  12.   if (durationObject.secs) {
  13.     duration[2] = `${durationObject.secs || '00'}S`;
  14.   }
  15.  
  16.   return `DT${duration.join('')}`;
  17. };
  18.  
  19. export const formatExcelDurationToMDSDuration = sheetDuration => {
  20.   if (!sheetDuration || parseInt(sheetDuration) < 0) {
  21.     return '';
  22.   }
  23.  
  24.   let hours = Math.floor(sheetDuration / 3600);
  25.   let mins = Math.floor((sheetDuration - hours * 3600) / 60);
  26.   let secs = sheetDuration - hours * 3600 - mins * 60;
  27.  
  28.   hours = hours < 10 ? `0${hours}` : hours;
  29.   mins = mins < 10 ? `0${mins}` : mins;
  30.   secs = secs < 10 ? `0${secs}` : secs;
  31.  
  32.   return formatDurationUtils({ hours, mins, secs });
  33. };
  34.  
  35. export const convertMDSDurationToSeconds = formattedDuration => {
  36.   try {
  37.     const durationArray = formattedDuration.match(/[0-99]+/g) || [
  38.       '00',
  39.       '00',
  40.       '00'
  41.     ];
  42.     //if formattedDuration = "DT22H33M21S"
  43.     //durationArray is ['22', '33', '21'];
  44.     const finalResult =
  45.       parseInt(durationArray[0]) * 3600 +
  46.       parseInt(durationArray[1]) * 60 +
  47.       parseInt(durationArray[2]);
  48.  
  49.     return finalResult;
  50.   } catch (error) {
  51.     return 0;
  52.   }
  53. };
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top