Skip to content

Commit 193ec79

Browse files
committed
fix(ComputerUsageProfile): cannot edit time start and time stop
1 parent 752a65a commit 193ec79

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
@@ -77,8 +77,8 @@ public function getEnergyPerDay(DateTimeInterface $day): TrackedFloat
7777
$power = $this->getPower();
7878

7979
$day_s = $day->format('Y-m-d');
80-
$start_date = DateTime::createFromFormat('Y-m-d H:i:s', $day_s . ' ' . $usage_profile->fields['time_start']);
81-
$stop_date = DateTime::createFromFormat('Y-m-d H:i:s', $day_s . ' ' . $usage_profile->fields['time_stop']);
80+
$start_date = DateTime::createFromFormat('Y-m-d H:i:s', $day_s . ' ' . $usage_profile->fields['time_start'] . ':00');
81+
$stop_date = DateTime::createFromFormat('Y-m-d H:i:s', $day_s . ' ' . $usage_profile->fields['time_stop'] . ':00');
8282
$delta_time = $stop_date->getTimestamp() - $start_date->getTimestamp();
8383

8484
// units:
@@ -109,10 +109,10 @@ public function getCarbonEmissionPerDay(DateTimeInterface $day, Zone $zone): ?Tr
109109
// Convert to integers
110110
$seconds_start[0] = (int) $seconds_start[0];
111111
$seconds_start[1] = (int) $seconds_start[1];
112-
$seconds_start[2] = (int) $seconds_start[2];
112+
$seconds_start[2] = 0;
113113
$seconds_stop[0] = (int) $seconds_stop[0];
114114
$seconds_stop[1] = (int) $seconds_stop[1];
115-
$seconds_stop[2] = (int) $seconds_stop[2];
115+
$seconds_stop[2] = 0;
116116

117117
$start_time = clone $day;
118118
$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
@@ -82,20 +82,20 @@ public function testPrepareInputForAdd()
8282
$this->assertEquals($expected, $result);
8383

8484
$input = [
85-
'time_start' => '09:00:00',
85+
'time_start' => '09:00',
8686
];
8787
$result = $instance->prepareInputForAdd($input);
8888
$expected = [
89-
'time_start' => '09:00:00',
89+
'time_start' => '09:00',
9090
];
9191
$this->assertEquals($expected, $result);
9292

9393
$input = [
94-
'time_stop' => '17:00:00',
94+
'time_stop' => '17:00',
9595
];
9696
$result = $instance->prepareInputForAdd($input);
9797
$expected = [
98-
'time_stop' => '17:00:00',
98+
'time_stop' => '17:00',
9999
];
100100
$this->assertEquals($expected, $result);
101101
}
@@ -124,20 +124,20 @@ public function testPrepareInputForUpdate()
124124
$this->assertEquals($expected, $result);
125125

126126
$input = [
127-
'time_start' => '09:00:00',
127+
'time_start' => '09:00',
128128
];
129129
$result = $instance->prepareInputForUpdate($input);
130130
$expected = [
131-
'time_start' => '09:00:00',
131+
'time_start' => '09:00',
132132
];
133133
$this->assertEquals($expected, $result);
134134

135135
$input = [
136-
'time_stop' => '17:00:00',
136+
'time_stop' => '17:00',
137137
];
138138
$result = $instance->prepareInputForUpdate($input);
139139
$expected = [
140-
'time_stop' => '17:00:00',
140+
'time_stop' => '17:00',
141141
];
142142
$this->assertEquals($expected, $result);
143143
}

tests/units/Dashboard/ProviderTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,8 @@ public function testGetSumPowerPerModel()
270270
$country = $this->getUniqueString();
271271
$usage_profile = [
272272
'name' => 'Test laptop usage profile',
273-
'time_start' => "09:00:00",
274-
'time_stop' => "17:00:00",
273+
'time_start' => "09:00",
274+
'time_stop' => "17:00",
275275
'day_1' => 1,
276276
'day_2' => 1,
277277
'day_3' => 1,
@@ -328,8 +328,8 @@ public function testGetUsageCarbonEmissionPerMonth()
328328
{
329329
$usage_profile = [
330330
'name' => 'Test laptop usage profile',
331-
'time_start' => "09:00:00",
332-
'time_stop' => "17:00:00",
331+
'time_start' => "09:00",
332+
'time_stop' => "17:00",
333333
'day_1' => 1,
334334
'day_2' => 1,
335335
'day_3' => 1,

tests/units/Engine/V1/ComputerTest.php

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

5252
const TEST_LAPTOP_USAGE_PROFILE = [
5353
'name' => 'Test laptop usage profile',
54-
'time_start' => "09:00:00",
55-
'time_stop' => "17:00:00",
54+
'time_start' => "09:00",
55+
'time_stop' => "17:00",
5656
'day_1' => 1,
5757
'day_2' => 1,
5858
'day_3' => 1,
@@ -67,8 +67,8 @@ class ComputerTest extends EngineTestCase
6767

6868
const TEST_SERVER_USAGE_PROFILE = [
6969
'name' => 'Test server usage profile',
70-
'time_start' => "00:00:00",
71-
'time_stop' => "23:00:00",
70+
'time_start' => "00:00",
71+
'time_stop' => "23:00",
7272
'day_1' => 1,
7373
'day_2' => 1,
7474
'day_3' => 1,
@@ -170,8 +170,8 @@ public function getCarbonEmissionPerDateProvider(): \Generator
170170

171171
$profile = [
172172
'name' => 'Test laptop usage profile',
173-
'time_start' => "09:30:00",
174-
'time_stop' => "17:00:00",
173+
'time_start' => "09:30",
174+
'time_stop' => "17:00",
175175
'day_1' => 1,
176176
'day_2' => 1,
177177
'day_3' => 1,
@@ -190,8 +190,8 @@ public function getCarbonEmissionPerDateProvider(): \Generator
190190

191191
$profile = [
192192
'name' => 'Test laptop usage profile',
193-
'time_start' => "09:00:00",
194-
'time_stop' => "17:15:00",
193+
'time_start' => "09:00",
194+
'time_stop' => "17:15",
195195
'day_1' => 1,
196196
'day_2' => 1,
197197
'day_3' => 1,
@@ -210,8 +210,8 @@ public function getCarbonEmissionPerDateProvider(): \Generator
210210

211211
$profile = [
212212
'name' => 'Test laptop usage profile',
213-
'time_start' => "09:15:00",
214-
'time_stop' => "09:45:00",
213+
'time_start' => "09:15",
214+
'time_stop' => "09:45",
215215
'day_1' => 1,
216216
'day_2' => 1,
217217
'day_3' => 1,

tests/units/Engine/V1/MonitorTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ public function getEnergyPerDayProvider(): \Generator
8686
{
8787
$profile = [
8888
'name' => 'Test laptop usage profile',
89-
'time_start' => "09:00:00",
90-
'time_stop' => "17:00:00",
89+
'time_start' => "09:00",
90+
'time_stop' => "17:00",
9191
'day_1' => 1,
9292
'day_2' => 1,
9393
'day_3' => 1,
@@ -115,8 +115,8 @@ public function getEnergyPerDayProvider(): \Generator
115115

116116
$profile = [
117117
'name' => 'Test laptop usage profile',
118-
'time_start' => "09:00:00",
119-
'time_stop' => "17:00:00",
118+
'time_start' => "09:00",
119+
'time_stop' => "17:00",
120120
'day_1' => 1,
121121
'day_2' => 1,
122122
'day_3' => 1,
@@ -154,8 +154,8 @@ public function getCarbonEmissionPerDateProvider(): \Generator
154154

155155
$usage_profile = [
156156
'name' => 'Test laptop usage profile',
157-
'time_start' => "09:00:00",
158-
'time_stop' => "17:00:00",
157+
'time_start' => "09:00",
158+
'time_stop' => "17:00",
159159
'day_1' => 1,
160160
'day_2' => 1,
161161
'day_3' => 1,

tests/units/Impact/History/ComputerTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ public function testEvaluateItem()
101101
'date_mod' => null,
102102
]);
103103
$usage_profile = $this->createItem(ComputerUsageProfile::class, [
104-
'time_start' => '09:00:00',
105-
'time_stop' => '18:00:00',
104+
'time_start' => '09:00',
105+
'time_stop' => '18:00',
106106
'day_1' => '1',
107107
'day_2' => '1',
108108
'day_3' => '1',

tests/units/Impact/History/MonitorTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ public function testEvaluateItem()
106106
'locations_id' => $location->getID(),
107107
]);
108108
$usage_profile = $this->createItem(ComputerUsageProfile::class, [
109-
'time_start' => '09:00:00',
110-
'time_stop' => '18:00:00',
109+
'time_start' => '09:00',
110+
'time_stop' => '18:00',
111111
'day_1' => '1',
112112
'day_2' => '1',
113113
'day_3' => '1',
@@ -680,8 +680,8 @@ public function testMonitorIsHistorizable()
680680
'buy_date' => '2024-01-01',
681681
]);
682682
$usage_profile = $this->createItem(ComputerUsageProfile::class, [
683-
'time_start' => '09:00:00',
684-
'time_stop' => '18:00:00',
683+
'time_start' => '09:00',
684+
'time_stop' => '18:00',
685685
'day_1' => '1',
686686
'day_2' => '1',
687687
'day_3' => '1',

0 commit comments

Comments
 (0)