- | = e((string) $quote['quoted_at']) ?> |
+ = e($fmtDateTime((string) $quote['quoted_at'], (string) ($quote['source'] ?? ''))) ?> |
= e($fmtNumber((float) $quote['price'], 4)) ?> = e((string) $quote['currency']) ?> |
= e((string) $quote['source']) ?> |
diff --git a/modules/boersenchecker/partials/home.php b/modules/boersenchecker/partials/home.php
index 242f921..bfe6d98 100644
--- a/modules/boersenchecker/partials/home.php
+++ b/modules/boersenchecker/partials/home.php
@@ -124,7 +124,7 @@
= e((string) $position['instrument_name']) ?>
= $position['latest_price'] !== null ? e(number_format((float) $position['latest_price'], 2, ',', '.')) . ' ' . e((string) $position['latest_currency']) : 'n/a' ?>
- = e((string) ($position['latest_quoted_at'] ?: 'kein Kurs')) ?>
+ = e((string) (($position['latest_quoted_at'] ?? '') !== '' ? $fmtDateTime((string) $position['latest_quoted_at'], (string) ($position['latest_source'] ?? '')) : 'kein Kurs')) ?>
diff --git a/modules/boersenchecker/partials/instruments.php b/modules/boersenchecker/partials/instruments.php
index 51a22f2..4831a06 100644
--- a/modules/boersenchecker/partials/instruments.php
+++ b/modules/boersenchecker/partials/instruments.php
@@ -135,7 +135,7 @@
-
+
@@ -169,7 +169,7 @@
|
- | = e((string) $quote['quoted_at']) ?> |
+ = e($fmtDateTime((string) $quote['quoted_at'], (string) ($quote['source'] ?? ''))) ?> |
= e(number_format((float) $quote['price'], 4, ',', '.')) ?> = e((string) $quote['currency']) ?> |
= e((string) $quote['source']) ?> |
diff --git a/modules/boersenchecker/src/Support/DashboardPage.php b/modules/boersenchecker/src/Support/DashboardPage.php
index 3c51643..daec9b6 100644
--- a/modules/boersenchecker/src/Support/DashboardPage.php
+++ b/modules/boersenchecker/src/Support/DashboardPage.php
@@ -114,6 +114,8 @@ final class DashboardPage
'selectedInstrumentForQuote' => $state['selectedInstrumentForQuote'],
'selectedInstrumentQuoteCurrency' => $state['selectedInstrumentQuoteCurrency'],
'fmtNumber' => fn (?float $value, int $scale = 2): string => $this->formatNumber($value, $scale),
+ 'fmtDateTime' => fn (?string $value, ?string $source = null): string => (string) \module_fn('boersenchecker', 'format_datetime_for_display', $value, $source),
+ 'localNowInputValue' => (string) \module_fn('boersenchecker', 'local_now_input_value'),
];
}
@@ -674,11 +676,13 @@ final class DashboardPage
$position['latest_price'] = (float) $latestQuote['price'];
$position['latest_currency'] = (string) $latestQuote['currency'];
$position['latest_quoted_at'] = (string) $latestQuote['quoted_at'];
+ $position['latest_source'] = (string) ($latestQuote['source'] ?? '');
$position['current_total_base'] = $currentTotalBase;
} else {
$position['latest_price'] = null;
$position['latest_currency'] = null;
$position['latest_quoted_at'] = null;
+ $position['latest_source'] = null;
$position['current_total_base'] = null;
}
@@ -784,13 +788,22 @@ final class DashboardPage
private function normalizeDateTimeLocal(?string $value): string
{
+ $timezone = new \DateTimeZone('Europe/Berlin');
$value = trim((string) $value);
if ($value === '') {
- return date('Y-m-d H:i:s');
+ return (new \DateTimeImmutable('now', $timezone))->format('Y-m-d H:i:s');
}
- $timestamp = strtotime($value);
- return $timestamp !== false ? date('Y-m-d H:i:s', $timestamp) : date('Y-m-d H:i:s');
+ $date = \DateTimeImmutable::createFromFormat('Y-m-d\TH:i', $value, $timezone);
+ if ($date instanceof \DateTimeImmutable) {
+ return $date->format('Y-m-d H:i:s');
+ }
+
+ try {
+ return (new \DateTimeImmutable($value, $timezone))->format('Y-m-d H:i:s');
+ } catch (\Throwable) {
+ return (new \DateTimeImmutable('now', $timezone))->format('Y-m-d H:i:s');
+ }
}
private function formatNumber(?float $value, int $scale = 2): string
diff --git a/modules/boersenchecker/src/Support/HomePage.php b/modules/boersenchecker/src/Support/HomePage.php
index 3eec9cd..5a0e2b3 100644
--- a/modules/boersenchecker/src/Support/HomePage.php
+++ b/modules/boersenchecker/src/Support/HomePage.php
@@ -68,6 +68,7 @@ final class HomePage
$position['latest_price'] = is_array($latestQuote) && is_numeric($latestQuote['price'] ?? null) ? (float) $latestQuote['price'] : null;
$position['latest_currency'] = is_array($latestQuote) ? (string) ($latestQuote['currency'] ?? '') : '';
$position['latest_quoted_at'] = is_array($latestQuote) ? (string) ($latestQuote['quoted_at'] ?? '') : '';
+ $position['latest_source'] = is_array($latestQuote) ? (string) ($latestQuote['source'] ?? '') : '';
$position['current_total_report'] = null;
$position['gain_report'] = null;
$position['gain_percent'] = null;
@@ -108,6 +109,7 @@ final class HomePage
'summary' => $this->buildSummary($positions),
'defaultReportCurrency' => $this->defaultReportCurrency,
'chartEndpoint' => '/module/boersenchecker/chart_data',
+ 'fmtDateTime' => fn (?string $value, ?string $source = null): string => (string) \module_fn('boersenchecker', 'format_datetime_for_display', $value, $source),
];
}
diff --git a/modules/boersenchecker/src/Support/InstrumentPage.php b/modules/boersenchecker/src/Support/InstrumentPage.php
index efb2794..0bfeff1 100644
--- a/modules/boersenchecker/src/Support/InstrumentPage.php
+++ b/modules/boersenchecker/src/Support/InstrumentPage.php
@@ -97,6 +97,8 @@ final class InstrumentPage
'searchKeywords' => $this->searchKeywords,
'searchResults' => $this->searchResults,
'defaultReportCurrency' => $this->defaultReportCurrency,
+ 'fmtDateTime' => fn (?string $value, ?string $source = null): string => (string) \module_fn('boersenchecker', 'format_datetime_for_display', $value, $source),
+ 'localNowInputValue' => (string) \module_fn('boersenchecker', 'local_now_input_value'),
];
}
@@ -180,7 +182,7 @@ final class InstrumentPage
'instrument_id' => $instrumentId,
'price' => $price,
'currency' => strtoupper(trim((string) ($_POST['quote_currency'] ?? $this->defaultReportCurrency))) ?: $this->defaultReportCurrency,
- 'quoted_at' => date('Y-m-d H:i:s', strtotime((string) ($_POST['quoted_at'] ?? 'now')) ?: time()),
+ 'quoted_at' => $this->normalizeDateTimeLocal((string) ($_POST['quoted_at'] ?? '')),
'source' => trim((string) ($_POST['quote_source'] ?? 'manual')) ?: 'manual',
]);
return 'Kurs gespeichert.';
@@ -272,4 +274,24 @@ final class InstrumentPage
return $instrument;
}
+
+ private function normalizeDateTimeLocal(?string $value): string
+ {
+ $timezone = new \DateTimeZone('Europe/Berlin');
+ $value = trim((string) $value);
+ if ($value === '') {
+ return (new \DateTimeImmutable('now', $timezone))->format('Y-m-d H:i:s');
+ }
+
+ $date = \DateTimeImmutable::createFromFormat('Y-m-d\TH:i', $value, $timezone);
+ if ($date instanceof \DateTimeImmutable) {
+ return $date->format('Y-m-d H:i:s');
+ }
+
+ try {
+ return (new \DateTimeImmutable($value, $timezone))->format('Y-m-d H:i:s');
+ } catch (\Throwable) {
+ return (new \DateTimeImmutable('now', $timezone))->format('Y-m-d H:i:s');
+ }
+ }
}
|