- π©πͺGermany Anybody Porta Westfalica
Could someone please provide this as MR instead for easier review and commenting?
For example, converting temperature from Fahrenheit to Fahrenheit assumes I want to convert to Kelvin. Wait, you may ask why would I convert from the same unit to the same unit. Well in my use case the user is selecting the input unit for the field. I created a custom formatter to display the temperature as multiple units in the front end.
Here is a sample of the code:
Custom Formatter:
$source->convert(TemperatureUnit::FAHRENHEIT);
web/modules/custom/symmetri_physical/src/Plugin/Field/FieldFormatter/MeasurementTemperatureRangeFormatter.php
public function convert($new_unit) {
...
case TemperatureUnit::FAHRENHEIT:
if ($new_unit == TemperatureUnit::CELSIUS) {
// @see http://www.rapidtables.com/convert/temperature/fahrenheit-to-celsius.htm
$new_number = Calculator::divide(Calculator::subtract($this->number, '32'), '1.8');
}
else {
// http://www.rapidtables.com/convert/temperature/fahrenheit-to-kelvin.htm
$new_number = Calculator::divide(Calculator::add($this->number, '459.67'), '1.8');
}
break;
}
I will submit a patch shortly.
Needs review
1.0
Code
Not all content is available!
It's likely this issue predates Contrib.social: some issue and comment data are missing.
Could someone please provide this as MR instead for easier review and commenting?