Skip to content

Commit

Permalink
Merge pull request #295 from tvup/hotfix/use_correct_datetime_to_find…
Browse files Browse the repository at this point in the history
…_year_end_transition

Hotfix/use correct datetime to find year end transition
  • Loading branch information
tvup authored Oct 27, 2024
2 parents 98983eb + 8de2d08 commit 3b43dc0
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 42 deletions.
36 changes: 2 additions & 34 deletions app/Services/GetElprisenSpotPrices.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
namespace App\Services;

use App\Services\Interfaces\GetSpotPricesInterface;
use Carbon\CarbonTimeZone;
use DateTime;
use DateTimeZone;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Http;
Expand Down Expand Up @@ -75,41 +72,12 @@ private function getPricesForDay(

$array = $response->json();

$timeZone = new DateTimeZone('Europe/Copenhagen');

$start = new DateTime(
Carbon::parse($start_date, 'Europe/Copenhagen')->startOfYear()->toDateString(),
$timeZone
);
$end = new DateTime(
Carbon::parse($end_date, 'Europe/Copenhagen')->startOfYear()->addYear()->toDateString(),
$timeZone
);

$transitions = $timeZone->getTransitions((int) $start->format('U'), (int) $end->format('U'));
$year_late_transition = $transitions[2];
$late_transition_end_hour = Carbon::parse($year_late_transition['time'])->timezone('Europe/Copenhagen');

$first = false;
if ($format == self::FORMAT_INTERNAL) {
$new_array = [];
foreach ($array as $data) {
$carbon = Carbon::parse($data['time_start'], 'Europe/Copenhagen');
if (!$first && $carbon->eq($late_transition_end_hour)) {
$first = true;
/** @var CarbonTimeZone $timezone */
$timezone = CarbonTimeZone::create('+2');
$timeZone2 = new DateTimeZone($timezone->getName());
$late_transition_end_hour2 = Carbon::create(2022, 10, 30, 2, 0, 0, $timeZone2); //TODO: Should be created from $late_transition_end_hour
if (!$late_transition_end_hour2) {
throw new \Exception('Could not create late_transition_end_hour2');
}
$nice_one = $late_transition_end_hour2->format('c');
$new_array[$nice_one] = $data['DKK_per_kWh'] * 1000;
} else {
$hour = $carbon->format('c');
$new_array[$hour] = $data['DKK_per_kWh'] * 1000;
}
$hour = $carbon->format('c');
$new_array[$hour] = $data['DKK_per_kWh'] * 1000;
}
$response = $new_array;
}
Expand Down
5 changes: 1 addition & 4 deletions app/Services/GetSmartMeMeterData.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,7 @@ public function getInterval(string $start_date_copenhagen, string $to_date = nul
/** @var CarbonTimeZone $timeZone2 */
$timeZone2 = CarbonTimeZone::create('+2');
$timeZone2 = new DateTimeZone($timeZone2->getName());
$late_transition_end_hour2 = Carbon::create(2022, 10, 30, 2, 0, 0, $timeZone2); //TODO: Should be created from $late_transition_end_hour
if (!$late_transition_end_hour2) {
throw new \Exception('Could not create late_transition_end_hour2');
}
$late_transition_end_hour2 = Carbon::parse($year_late_transition['time'])->subHour()->timezone($timeZone2);
$nice_one = $late_transition_end_hour2->format('c');

$to_date = Carbon::parse($to_date, 'Europe/Copenhagen');
Expand Down
5 changes: 1 addition & 4 deletions app/Services/GetSpotPrices.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,7 @@ public function getData(string $start_date = null, string $end_date = null, stri
/** @var CarbonTimeZone $timezone */
$timezone = CarbonTimeZone::create('+2');
$timeZone2 = new DateTimeZone($timezone->getName());
$late_transition_end_hour2 = Carbon::create(2022, 10, 30, 2, 0, 0, $timeZone2); //TODO: Should be created from $late_transition_end_hour
if (!$late_transition_end_hour2) {
throw new \Exception('Could not create late_transition_end_hour2');
}
$late_transition_end_hour2 = Carbon::parse($year_late_transition['time'])->subHour()->timezone($timeZone2);
$nice_one = $late_transition_end_hour2->format('c');
$new_array[$nice_one] = $data['SpotPriceDKK'];
} else {
Expand Down

0 comments on commit 3b43dc0

Please sign in to comment.