Skip to content

Commit bb1cb92

Browse files
committed
fix(ComputerUsageProfile): cannot edit time start and time stop
1 parent 0f28326 commit bb1cb92

File tree

8 files changed

+39
-39
lines changed

8 files changed

+39
-39
lines changed

src/ComputerUsageProfile.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ protected function inputIntegrityCheck(array $input): array
111111
*/
112112
protected function isValidTime(string $time): bool
113113
{
114-
$time_pattern = '/^([01]\d|2[0-3]):[0-5]\d:[0-5]\d$/';
114+
$time_pattern = '/^([01]\d|2[0-3]):[0-5]\d$/';
115115
$found = preg_match($time_pattern, $time, $matches);
116116
return ($found === 1);
117117
}

src/Engine/V1/AbstractSwitchable.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ public function getEnergyPerDay(DateTimeInterface $day): TrackedFloat
7979
$power = $this->getPower();
8080

8181
$day_s = $day->format('Y-m-d');
82-
$start_date = DateTime::createFromFormat('Y-m-d H:i:s', $day_s . ' ' . $usage_profile->fields['time_start']);
83-
$stop_date = DateTime::createFromFormat('Y-m-d H:i:s', $day_s . ' ' . $usage_profile->fields['time_stop']);
82+
$start_date = DateTime::createFromFormat('Y-m-d H:i:s', $day_s . ' ' . $usage_profile->fields['time_start'] . ':00');
83+
$stop_date = DateTime::createFromFormat('Y-m-d H:i:s', $day_s . ' ' . $usage_profile->fields['time_stop'] . ':00');
8484
$delta_time = $stop_date->getTimestamp() - $start_date->getTimestamp();
8585

8686
// units:
@@ -111,10 +111,10 @@ public function getCarbonEmissionPerDay(DateTimeInterface $day, Source_Zone $sou
111111
// Convert to integers
112112
$seconds_start[0] = (int) $seconds_start[0];
113113
$seconds_start[1] = (int) $seconds_start[1];
114-
$seconds_start[2] = (int) $seconds_start[2];
114+
$seconds_start[2] = 0;
115115
$seconds_stop[0] = (int) $seconds_stop[0];
116116
$seconds_stop[1] = (int) $seconds_stop[1];
117-
$seconds_stop[2] = (int) $seconds_stop[2];
117+
$seconds_stop[2] = 0;
118118

119119
$start_time = clone $day;
120120
$start_time->setTime($seconds_start[0], $seconds_start[1], $seconds_start[2]);

tests/units/ComputerUsageProfileTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,20 +83,20 @@ public function testPrepareInputForAdd()
8383
$this->assertEquals($expected, $result);
8484

8585
$input = [
86-
'time_start' => '09:00:00',
86+
'time_start' => '09:00',
8787
];
8888
$result = $instance->prepareInputForAdd($input);
8989
$expected = [
90-
'time_start' => '09:00:00',
90+
'time_start' => '09:00',
9191
];
9292
$this->assertEquals($expected, $result);
9393

9494
$input = [
95-
'time_stop' => '17:00:00',
95+
'time_stop' => '17:00',
9696
];
9797
$result = $instance->prepareInputForAdd($input);
9898
$expected = [
99-
'time_stop' => '17:00:00',
99+
'time_stop' => '17:00',
100100
];
101101
$this->assertEquals($expected, $result);
102102
}
@@ -125,20 +125,20 @@ public function testPrepareInputForUpdate()
125125
$this->assertEquals($expected, $result);
126126

127127
$input = [
128-
'time_start' => '09:00:00',
128+
'time_start' => '09:00',
129129
];
130130
$result = $instance->prepareInputForUpdate($input);
131131
$expected = [
132-
'time_start' => '09:00:00',
132+
'time_start' => '09:00',
133133
];
134134
$this->assertEquals($expected, $result);
135135

136136
$input = [
137-
'time_stop' => '17:00:00',
137+
'time_stop' => '17:00',
138138
];
139139
$result = $instance->prepareInputForUpdate($input);
140140
$expected = [
141-
'time_stop' => '17:00:00',
141+
'time_stop' => '17:00',
142142
];
143143
$this->assertEquals($expected, $result);
144144
}

tests/units/Dashboard/ProviderTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -526,8 +526,8 @@ public function testGetSumPowerPerModel()
526526
$country = $this->getUniqueString();
527527
$usage_profile = [
528528
'name' => 'Test laptop usage profile',
529-
'time_start' => "09:00:00",
530-
'time_stop' => "17:00:00",
529+
'time_start' => "09:00",
530+
'time_stop' => "17:00",
531531
'day_1' => 1,
532532
'day_2' => 1,
533533
'day_3' => 1,
@@ -593,8 +593,8 @@ public function testGetUsageCarbonEmissionPerMonth()
593593
{
594594
$usage_profile = [
595595
'name' => 'Test laptop usage profile',
596-
'time_start' => "09:00:00",
597-
'time_stop' => "17:00:00",
596+
'time_start' => "09:00",
597+
'time_stop' => "17:00",
598598
'day_1' => 1,
599599
'day_2' => 1,
600600
'day_3' => 1,

tests/units/Engine/V1/ComputerTest.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ class ComputerTest extends EngineTestCase
5555

5656
const TEST_LAPTOP_USAGE_PROFILE = [
5757
'name' => 'Test laptop usage profile',
58-
'time_start' => "09:00:00",
59-
'time_stop' => "17:00:00",
58+
'time_start' => "09:00",
59+
'time_stop' => "17:00",
6060
'day_1' => 1,
6161
'day_2' => 1,
6262
'day_3' => 1,
@@ -71,8 +71,8 @@ class ComputerTest extends EngineTestCase
7171

7272
const TEST_SERVER_USAGE_PROFILE = [
7373
'name' => 'Test server usage profile',
74-
'time_start' => "00:00:00",
75-
'time_stop' => "23:00:00",
74+
'time_start' => "00:00",
75+
'time_stop' => "23:00",
7676
'day_1' => 1,
7777
'day_2' => 1,
7878
'day_3' => 1,
@@ -188,8 +188,8 @@ public function getCarbonEmissionPerDateProvider(): \Generator
188188

189189
$profile = [
190190
'name' => 'Test laptop usage profile',
191-
'time_start' => "09:30:00",
192-
'time_stop' => "17:00:00",
191+
'time_start' => "09:30",
192+
'time_stop' => "17:00",
193193
'day_1' => 1,
194194
'day_2' => 1,
195195
'day_3' => 1,
@@ -208,8 +208,8 @@ public function getCarbonEmissionPerDateProvider(): \Generator
208208

209209
$profile = [
210210
'name' => 'Test laptop usage profile',
211-
'time_start' => "09:00:00",
212-
'time_stop' => "17:15:00",
211+
'time_start' => "09:00",
212+
'time_stop' => "17:15",
213213
'day_1' => 1,
214214
'day_2' => 1,
215215
'day_3' => 1,
@@ -228,8 +228,8 @@ public function getCarbonEmissionPerDateProvider(): \Generator
228228

229229
$profile = [
230230
'name' => 'Test laptop usage profile',
231-
'time_start' => "09:15:00",
232-
'time_stop' => "09:45:00",
231+
'time_start' => "09:15",
232+
'time_stop' => "09:45",
233233
'day_1' => 1,
234234
'day_2' => 1,
235235
'day_3' => 1,

tests/units/Engine/V1/MonitorTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ public function getEnergyPerDayProvider(): \Generator
8989
{
9090
$profile = [
9191
'name' => 'Test laptop usage profile',
92-
'time_start' => "09:00:00",
93-
'time_stop' => "17:00:00",
92+
'time_start' => "09:00",
93+
'time_stop' => "17:00",
9494
'day_1' => 1,
9595
'day_2' => 1,
9696
'day_3' => 1,
@@ -118,8 +118,8 @@ public function getEnergyPerDayProvider(): \Generator
118118

119119
$profile = [
120120
'name' => 'Test laptop usage profile',
121-
'time_start' => "09:00:00",
122-
'time_stop' => "17:00:00",
121+
'time_start' => "09:00",
122+
'time_stop' => "17:00",
123123
'day_1' => 1,
124124
'day_2' => 1,
125125
'day_3' => 1,
@@ -162,8 +162,8 @@ public function getCarbonEmissionPerDateProvider(): \Generator
162162
$this->createCarbonIntensityData($source_zone, $thursday, $intensity);
163163
$usage_profile = [
164164
'name' => 'Test laptop usage profile',
165-
'time_start' => "09:00:00",
166-
'time_stop' => "17:00:00",
165+
'time_start' => "09:00",
166+
'time_stop' => "17:00",
167167
'day_1' => 1,
168168
'day_2' => 1,
169169
'day_3' => 1,

tests/units/Impact/History/ComputerTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ public function testEvaluateItem()
118118
'date_mod' => null,
119119
]);
120120
$usage_profile = $this->createItem(ComputerUsageProfile::class, [
121-
'time_start' => '09:00:00',
122-
'time_stop' => '18:00:00',
121+
'time_start' => '09:00',
122+
'time_stop' => '18:00',
123123
'day_1' => '1',
124124
'day_2' => '1',
125125
'day_3' => '1',

tests/units/Impact/History/MonitorTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ public function testEvaluateItem()
127127
'locations_id' => $glpi_location->getID(),
128128
]);
129129
$usage_profile = $this->createItem(ComputerUsageProfile::class, [
130-
'time_start' => '09:00:00',
131-
'time_stop' => '18:00:00',
130+
'time_start' => '09:00',
131+
'time_stop' => '18:00',
132132
'day_1' => '1',
133133
'day_2' => '1',
134134
'day_3' => '1',
@@ -704,8 +704,8 @@ public function testMonitorIsHistorizable()
704704
'buy_date' => '2024-01-01',
705705
]);
706706
$usage_profile = $this->createItem(ComputerUsageProfile::class, [
707-
'time_start' => '09:00:00',
708-
'time_stop' => '18:00:00',
707+
'time_start' => '09:00',
708+
'time_stop' => '18:00',
709709
'day_1' => '1',
710710
'day_2' => '1',
711711
'day_3' => '1',

0 commit comments

Comments
 (0)