chore: fix timezone handling
This commit is contained in:
parent
e8dc2013bc
commit
5dca68037d
7 changed files with 194 additions and 94 deletions
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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(×heets, ×heet_config)?;
|
||||
let report = generate_report(×heets, ×heet_config, now, tz)?;
|
||||
|
||||
if report.months.is_empty() {
|
||||
println!("No timesheet data found for the configured periods.");
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue