mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-20 17:15:51 +02:00
Allow to parse ranges for ParameterDTO which just contain two dots
This commit is contained in:
parent
5612a790fb
commit
376c7e7a6f
2 changed files with 13 additions and 3 deletions
|
@ -72,9 +72,9 @@ class ParameterDTO
|
||||||
group: $group);
|
group: $group);
|
||||||
}
|
}
|
||||||
|
|
||||||
//If the attribute contains "..." or a tilde we assume it is a range
|
//If the attribute contains ".." or "..." or a tilde we assume it is a range
|
||||||
if (preg_match('/(\.{3}|~)/', $value) === 1) {
|
if (preg_match('/(\.{2,3}|~)/', $value) === 1) {
|
||||||
$parts = preg_split('/\s*(\.{3}|~)\s*/', $value);
|
$parts = preg_split('/\s*(\.{2,3}|~)\s*/', $value);
|
||||||
if (count($parts) === 2) {
|
if (count($parts) === 2) {
|
||||||
//Try to extract number and unit from value (allow leading +)
|
//Try to extract number and unit from value (allow leading +)
|
||||||
if ($unit === null || trim($unit) === '') {
|
if ($unit === null || trim($unit) === '') {
|
||||||
|
|
|
@ -70,6 +70,16 @@ class ParameterDTOTest extends TestCase
|
||||||
'test'
|
'test'
|
||||||
];
|
];
|
||||||
|
|
||||||
|
//Test ranges
|
||||||
|
yield [
|
||||||
|
new ParameterDTO('test', value_min: 1.0, value_max: 2.0, unit: 'kg', symbol: 'm', group: 'test'),
|
||||||
|
'test',
|
||||||
|
'1.0..2.0',
|
||||||
|
'kg',
|
||||||
|
'm',
|
||||||
|
'test'
|
||||||
|
];
|
||||||
|
|
||||||
//Test ranges with tilde
|
//Test ranges with tilde
|
||||||
yield [
|
yield [
|
||||||
new ParameterDTO('test', value_min: -1.0, value_max: 2.0, unit: 'kg', symbol: 'm', group: 'test'),
|
new ParameterDTO('test', value_min: -1.0, value_max: 2.0, unit: 'kg', symbol: 'm', group: 'test'),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue