SHARE
TWEET

Json Transform Time

a guest Dec 11th, 2019 112 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // computes nicely formatted duration from given minutes
  2. (function(i){
  3.  
  4.     var d = Math.floor(i / (24 * 60));
  5.     var h = Math.floor((i / 60) - (24 * d));
  6.     var m = Math.round(i - 60 * (24 * d + h));
  7.     var result = '';
  8.  
  9.     // days
  10.     if (d > 0) {
  11.         result = result + d;
  12.         if (d == 1) {
  13.             result = d + " Tag";
  14.         } else {
  15.             result = d + " Tage";
  16.         }
  17.     }
  18.  
  19.     // hours
  20.     if (h > 0) {
  21.         if (result != '') {
  22.             result = result + ', ';
  23.         }
  24.         result = result + h;
  25.         if (h == 1) {
  26.             result = result + ' Stunde';
  27.         } else {
  28.             result = result + ' Stunden';
  29.         }
  30.     }
  31.    
  32.     // minutes
  33.     if (m > 0) {
  34.         if (result != '') {
  35.             result = result + ', ';
  36.         }
  37.         result = result + m;
  38.         if (m == 1) {
  39.             result = result + ' Minute';
  40.         } else {
  41.             result = result + ' Minuten';
  42.         }
  43.     }
  44.  
  45.     return result;
  46. })(input)
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