From 862edd36067e8b935420a0b4ed3f73f048cf9f0f Mon Sep 17 00:00:00 2001 From: Torben Evald Hansen Date: Sun, 27 Oct 2024 15:31:03 +0100 Subject: [PATCH 1/3] Use current year end transition date instead of hardcoded one. --- app/Services/GetSmartMeMeterData.php | 5 +---- app/Services/GetSpotPrices.php | 5 +---- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/app/Services/GetSmartMeMeterData.php b/app/Services/GetSmartMeMeterData.php index 1eae3235..df4229fe 100644 --- a/app/Services/GetSmartMeMeterData.php +++ b/app/Services/GetSmartMeMeterData.php @@ -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'); diff --git a/app/Services/GetSpotPrices.php b/app/Services/GetSpotPrices.php index cb3a3929..cc290079 100644 --- a/app/Services/GetSpotPrices.php +++ b/app/Services/GetSpotPrices.php @@ -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 { From ed8557b499de1b90c4986a62db09457cec38d301 Mon Sep 17 00:00:00 2001 From: Torben Evald Hansen Date: Sun, 27 Oct 2024 15:34:03 +0100 Subject: [PATCH 2/3] Prices from 'elprisenligenu' do not require adjustment due to the switch to winter time, unlike some of the other sources. --- app/Services/GetElprisenSpotPrices.php | 33 ++------------------------ 1 file changed, 2 insertions(+), 31 deletions(-) diff --git a/app/Services/GetElprisenSpotPrices.php b/app/Services/GetElprisenSpotPrices.php index 8d4f225d..49a2bf5c 100644 --- a/app/Services/GetElprisenSpotPrices.php +++ b/app/Services/GetElprisenSpotPrices.php @@ -75,41 +75,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; } From 8de2d081c084dce88e38dcdfd455222864870b96 Mon Sep 17 00:00:00 2001 From: Torben Evald Hansen Date: Sun, 27 Oct 2024 15:36:10 +0100 Subject: [PATCH 3/3] Remove unused DateTime imports for cleanup --- app/Services/GetElprisenSpotPrices.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/app/Services/GetElprisenSpotPrices.php b/app/Services/GetElprisenSpotPrices.php index 49a2bf5c..d4876f28 100644 --- a/app/Services/GetElprisenSpotPrices.php +++ b/app/Services/GetElprisenSpotPrices.php @@ -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;