Improve day swipe and sleep handling

This commit is contained in:
2026-05-21 13:00:10 +02:00
parent 2047cae61c
commit a087eb508b
5 changed files with 206 additions and 53 deletions
+11 -4
View File
@@ -739,7 +739,9 @@ final class App
if ($name === 'sleep_analysis') {
foreach ($data as $point) {
$date = $this->healthPointDate($point['date'] ?? ($point['sleepEnd'] ?? ($point['endDate'] ?? null)));
$start = $this->healthDateTime($point['sleepStart'] ?? ($point['inBedStart'] ?? ($point['startDate'] ?? null)));
$end = $this->healthDateTime($point['sleepEnd'] ?? ($point['inBedEnd'] ?? ($point['endDate'] ?? null)));
$date = ($end ?? $this->healthDateTime($point['date'] ?? null))?->format('Y-m-d');
if ($date === null) {
continue;
}
@@ -770,8 +772,6 @@ final class App
}
}
$start = $this->healthDateTime($point['sleepStart'] ?? ($point['inBedStart'] ?? ($point['startDate'] ?? null)));
$end = $this->healthDateTime($point['sleepEnd'] ?? ($point['inBedEnd'] ?? ($point['endDate'] ?? null)));
if ($start !== null && ($bucket['start'] === null || $start < $bucket['start'])) {
$bucket['start'] = $start;
}
@@ -1816,7 +1816,7 @@ final class App
$comment = trim((string) ($input['event_comment'] ?? ''));
$value = max(0, min(50000, (float) ($input['event_value'] ?? 0)));
$value = max(0, min(50000, $this->localizedFloat($input['event_value'] ?? 0)));
if (in_array($type, ['walk', 'sport', 'sleep'], true) && $value <= 0) {
throw new RuntimeException('Für diesen Moment braucht es einen Wert oder eine Dauer.');
}
@@ -1847,6 +1847,13 @@ final class App
];
}
private function localizedFloat(mixed $value): float
{
$normalized = str_replace(',', '.', trim((string) $value));
return is_numeric($normalized) ? (float) $normalized : 0.0;
}
private function dashboardMediaDirectory(string $username): string
{
return storage_path('users/' . normalize_username($username) . '/media');
+17
View File
@@ -115,6 +115,23 @@ function format_points(float $value): string
return number_format($rounded, 1, ',', '.');
}
function format_duration_hours(float $hours): string
{
$minutes = max(0, (int) round($hours * 60));
$wholeHours = intdiv($minutes, 60);
$remainingMinutes = $minutes % 60;
if ($wholeHours <= 0) {
return $remainingMinutes . ' min';
}
if ($remainingMinutes === 0) {
return $wholeHours . ' h';
}
return $wholeHours . ' h ' . $remainingMinutes . ' min';
}
function normalize_username(string $username): string
{
return strtolower(trim($username));