chore: fix timezone handling
Some checks failed
Continuous Integration / Lint, Check & Test (push) Failing after 57s
Release / Build and Release (push) Successful in 5s
Continuous Integration / Build Package (push) Successful in 1m43s

This commit is contained in:
Konstantin Fickel 2026-04-07 13:26:34 +02:00
parent e8dc2013bc
commit 5dca68037d
Signed by: kfickel
GPG key ID: A793722F9933C1A5
7 changed files with 194 additions and 94 deletions

View file

@ -24,7 +24,9 @@ fn all_files() -> Result<Vec<LocalizedShard>, StreamdError> {
let content = fs::read_to_string(path)?;
let stream_file = parse_markdown_file(&file_name, &content);
if let Ok(shard) = localize_stream_file(&stream_file, &TaskConfiguration) {
if let Ok(shard) =
localize_stream_file(&stream_file, &TaskConfiguration, chrono_tz::UTC)
{
shards.push(shard);
}
}

View file

@ -5,6 +5,7 @@ use std::path::Path;
use chrono::Datelike;
use chrono::NaiveDate;
use chrono::Utc;
use chrono_tz::Tz;
use walkdir::WalkDir;
use crate::config::Settings;
@ -20,7 +21,7 @@ use crate::timesheet::{
DayType, DayWarning, MonthReport, TimesheetReport,
};
fn load_all_shards(base_folder: &Path) -> Result<Vec<LocalizedShard>, StreamdError> {
fn load_all_shards(base_folder: &Path, tz: Tz) -> Result<Vec<LocalizedShard>, StreamdError> {
let mut shards = Vec::new();
for entry in WalkDir::new(base_folder)
@ -34,7 +35,8 @@ fn load_all_shards(base_folder: &Path) -> Result<Vec<LocalizedShard>, StreamdErr
let content = fs::read_to_string(path)?;
let stream_file = parse_markdown_file(&file_name, &content);
if let Ok(shard) = localize_stream_file(&stream_file, &BasicTimesheetConfiguration) {
if let Ok(shard) = localize_stream_file(&stream_file, &BasicTimesheetConfiguration, tz)
{
shards.push(shard);
}
}
@ -321,6 +323,13 @@ pub fn run(decimal: bool, debug: bool) -> Result<(), StreamdError> {
// Load repository configuration
let repo_config = load_repository_config(base_folder)?;
// Parse timezone from config, defaulting to UTC
let tz: Tz = repo_config
.timezone
.as_deref()
.and_then(|s| s.parse().ok())
.unwrap_or(chrono_tz::UTC);
// Check if timesheet is configured
let timesheet_config = match repo_config.timesheet {
Some(config) => config,
@ -338,12 +347,14 @@ pub fn run(decimal: bool, debug: bool) -> Result<(), StreamdError> {
}
};
let now = Utc::now();
// Load all markdown files and extract timesheets
let all_shards = load_all_shards(base_folder)?;
let timesheets = extract_timesheets(&all_shards, Utc::now())?;
let all_shards = load_all_shards(base_folder, tz)?;
let timesheets = extract_timesheets(&all_shards, now, tz)?;
// Generate the report
let report = generate_report(&timesheets, &timesheet_config)?;
let report = generate_report(&timesheets, &timesheet_config, now, tz)?;
if report.months.is_empty() {
println!("No timesheet data found for the configured periods.");

View file

@ -26,7 +26,9 @@ fn all_files() -> Result<Vec<LocalizedShard>, StreamdError> {
let content = fs::read_to_string(path)?;
let stream_file = parse_markdown_file(&file_name, &content);
if let Ok(shard) = localize_stream_file(&stream_file, &TaskConfiguration) {
if let Ok(shard) =
localize_stream_file(&stream_file, &TaskConfiguration, chrono_tz::UTC)
{
shards.push(shard);
}
}