Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/Services/InfoProviderSystem/DTOs/ParameterDTO.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,13 @@ public static function parseValueField(string $name, string|float $value, ?strin

//If both parts have the same unit and both values are numerical, we'll save it as range
if ($unit === $unit2 && is_numeric($number) && is_numeric($number2)) {
//If the parameter contains AWG in name or unit and min/max order is "wrong", swap it
if (preg_match('/AWG/', $name . $unit) === 1 && $number > $number2) {
$tmp = $number;
$number = $number2;
$number2 = $tmp;
}

return new self(name: $name, value_text: $value_text2, value_min: (float) $number,
value_max: (float) $number2, unit: $unit, symbol: $symbol, group: $group);
}
Expand Down
10 changes: 10 additions & 0 deletions tests/Services/InfoProviderSystem/DTOs/ParameterDTOTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,16 @@ public static function parseValueFieldDataProvider(): \Generator
'test'
];

//Test inverse AWG range
yield [
new ParameterDTO('test', value_min: 14, value_max: 22, unit: 'AWG', symbol: 'm', group: 'test'),
'test',
'22..14',
'AWG',
'm',
'test'
];

//Test ranges with tilde
yield [
new ParameterDTO('test', value_min: -1.0, value_max: 2.0, unit: 'kg', symbol: 'm', group: 'test'),
Expand Down
Loading