code: private Duration getDuration(TimeUnit units, Double duration)
     {
        Duration result = null;
        if (duration != null)
        {
           double durationValue = duration.doubleValue() * 100.0;
  
           switch (units)
           {
              case MINUTES:
              {
                 durationValue *= MINUTES_PER_DAY;
                 break;
              }
  
              case HOURS:
              {
                 durationValue *= HOURS_PER_DAY;
                 break;
              }
  
              case DAYS:
              {
                 durationValue *= 3.0;
                 break;
              }
  
              case WEEKS:
              {
                 durationValue *= 0.6;
                 break;
              }
  
              case MONTHS:
              {
                 durationValue *= 0.15;
                 break;
              }
  
              default:
              {
                 throw new IllegalArgumentException("Unsupported time units " + units);
              }
           }
  
           durationValue = Math.round(durationValue) / 100.0;
  
           result = Duration.getInstance(durationValue, units);
        }
  
        return result;
     }
docs: Read a duration.
  
  @param units duration units
  @param duration duration value
  @return Duration instance