Advertisement
PyK0T1K

Google Table, JIRA Time Support

Aug 15th, 2024 (edited)
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function parseTimeString(timeString)
  2. {
  3.   var days = 0, hours = 0, minutes = 0;
  4.  
  5.   var dayMatch = timeString.match(/(\d+)d/);
  6.   var hourMatch = timeString.match(/(\d+)h/);
  7.   var minuteMatch = timeString.match(/(\d+)min/);
  8.  
  9.   if (dayMatch)
  10.   {
  11.     days = parseInt(dayMatch[1], 10) * 8;
  12.   }
  13.  
  14.   if (hourMatch)
  15.   {
  16.     hours = parseInt(hourMatch[1], 10);
  17.   }
  18.  
  19.   if (minuteMatch)
  20.   {
  21.     minutes = parseInt(minuteMatch[1], 10);
  22.   }
  23.  
  24.   return days + hours + minutes / 60;
  25. }
  26.  
  27. function convertHoursToTimeString(hours)
  28. {
  29.   var days = Math.floor(hours / 8);
  30.   var remainingHours = hours % 8;
  31.   var fullHours = Math.floor(remainingHours);
  32.   var minutes = Math.round((remainingHours - fullHours) * 60);
  33.  
  34.   var result = '';
  35.   if (days > 0)
  36.   {
  37.     result += days + 'd ';
  38.   }
  39.  
  40.   if (fullHours > 0 || days == 0)
  41.   {
  42.     result += fullHours + 'h ';
  43.   }
  44.  
  45.   if (minutes > 0) {
  46.     result += minutes + 'min';
  47.   }
  48.  
  49.   return result.trim();
  50. }
  51.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement