fix(tours): Tagesumschlag nach Ortszeit statt UTC

'Heute' wurde per Utc::now().date_naive() bestimmt. Bei CEST (UTC+2)
wechselte der Tag dadurch erst um 02:00 Ortszeit — der Fahrer sah nach
Mitternacht noch die Touren von gestern. Umgestellt auf Local::now() in
list_my_tours_today sowie den Import-/Resync-Defaults und dem
Scheduler-Catch-up.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Dennis Nemec
2026-07-11 00:10:53 +02:00
parent f4f534463d
commit a30f2778fd
4 changed files with 11 additions and 6 deletions

View File

@ -559,7 +559,7 @@ pub(crate) async fn run_app(
let job = Job::new_async(cfg.import.cron.as_str(), move |_uuid, _lock| { let job = Job::new_async(cfg.import.cron.as_str(), move |_uuid, _lock| {
let import = import.clone(); let import = import.clone();
Box::pin(async move { Box::pin(async move {
let date = (chrono::Utc::now() + chrono::Duration::days(offset)).date_naive(); let date = (chrono::Local::now() + chrono::Duration::days(offset)).date_naive();
match import.execute_with(date, SyncTrigger::Scheduler).await { match import.execute_with(date, SyncTrigger::Scheduler).await {
Ok(summary) => tracing::info!( Ok(summary) => tracing::info!(
date = %summary.date, date = %summary.date,
@ -592,7 +592,7 @@ pub(crate) async fn run_app(
let sync_runs = sync_run_repository.clone(); let sync_runs = sync_run_repository.clone();
let offset = cfg.import.date_offset_days; let offset = cfg.import.date_offset_days;
tokio::spawn(async move { tokio::spawn(async move {
let date = (chrono::Utc::now() + chrono::Duration::days(offset)).date_naive(); let date = (chrono::Local::now() + chrono::Duration::days(offset)).date_naive();
match sync_runs.has_successful_run_for(date).await { match sync_runs.has_successful_run_for(date).await {
Ok(true) => tracing::info!( Ok(true) => tracing::info!(
%date, %date,

View File

@ -82,7 +82,7 @@ pub async fn import_erp(
"ungültiges Datum '{s}' (erwartet YYYY-MM-DD): {e}" "ungültiges Datum '{s}' (erwartet YYYY-MM-DD): {e}"
))) )))
})?, })?,
None => chrono::Utc::now().date_naive(), None => chrono::Local::now().date_naive(),
}; };
tracing::info!(%date, "admin.import_erp"); tracing::info!(%date, "admin.import_erp");
let summary = state.import_erp_tours.execute(date).await?; let summary = state.import_erp_tours.execute(date).await?;

View File

@ -50,7 +50,7 @@ pub async fn dev_resync(
"ungültiges Datum '{s}' (erwartet YYYY-MM-DD): {e}" "ungültiges Datum '{s}' (erwartet YYYY-MM-DD): {e}"
))) )))
})?, })?,
None => chrono::Utc::now().date_naive(), None => chrono::Local::now().date_naive(),
}; };
tracing::warn!(%date, "dev.resync: Postgres wird überschrieben + neu importiert"); tracing::warn!(%date, "dev.resync: Postgres wird überschrieben + neu importiert");
let summary = state.dev_resync_tours.execute(date).await?; let summary = state.dev_resync_tours.execute(date).await?;

View File

@ -1,6 +1,6 @@
use std::sync::Arc; use std::sync::Arc;
use chrono::{NaiveDate, Utc}; use chrono::{Local, NaiveDate};
use crate::dto::TourSummary; use crate::dto::TourSummary;
use crate::error::ApplicationError; use crate::error::ApplicationError;
@ -27,9 +27,14 @@ impl ListMyToursTodayUseCase {
} }
pub async fn execute(&self, personalnummer: i64) -> Result<Vec<TourSummary>, ApplicationError> { pub async fn execute(&self, personalnummer: i64) -> Result<Vec<TourSummary>, ApplicationError> {
// Bewusst Local statt Utc: der Tagesumschlag muss sich nach der
// Ortszeit des Fahrers richten. Mit Utc wechselt "heute" erst um
// 02:00 Ortszeit (CEST = UTC+2) — bis dahin sähe der Fahrer nach
// Mitternacht noch die Touren von gestern. Der Server läuft in
// Europe/Vienna, daher ist Local hier korrekt.
let today = self let today = self
.today_override .today_override
.unwrap_or_else(|| Utc::now().date_naive()); .unwrap_or_else(|| Local::now().date_naive());
self.repository self.repository
.find_today_for_driver(personalnummer, today) .find_today_for_driver(personalnummer, today)
.await .await