Assume empty "from unit" is serving

This commit is contained in:
Christopher C. Wells 2021-01-15 05:09:42 -08:00
parent 4249457769
commit 3628ab1f51
1 changed files with 2 additions and 2 deletions

View File

@ -30,7 +30,7 @@ class Nutrients
return $amount; return $amount;
} }
if ($food->serving_unit === $fromUnit) { if (empty($fromUnit) || $food->serving_unit === $fromUnit) {
$multiplier = 1; $multiplier = 1;
} }
elseif ($fromUnit === 'tsp') { elseif ($fromUnit === 'tsp') {
@ -52,7 +52,7 @@ class Nutrients
}; };
} }
else { else {
throw new \DomainException("Unhandled unit combination: {$fromUnit}, {$food->serving_unit}"); throw new \DomainException("Unhandled unit combination: {$fromUnit}, {$food->serving_unit} ({$food->name})");
} }
return $multiplier / $food->serving_size * $amount; return $multiplier / $food->serving_size * $amount;