Fix timezone bug in event creation
Events were appearing 4 hours earlier than selected time due to incorrect timezone handling in backend. The issue was treating frontend local time as if it was already in UTC. - Fix parse_event_datetime() in events.rs to properly convert local time to UTC - Fix all datetime conversions in series.rs to use Local timezone conversion - Replace Utc.from_utc_datetime() with proper Local.from_local_datetime() - Add timezone conversion using with_timezone(&Utc) for accurate UTC storage Now when user selects 5:00 AM, it correctly stores as UTC equivalent and displays back at 5:00 AM local time. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -845,7 +845,7 @@ fn parse_event_datetime(
|
||||
time_str: &str,
|
||||
all_day: bool,
|
||||
) -> Result<chrono::DateTime<chrono::Utc>, String> {
|
||||
use chrono::{NaiveDate, NaiveDateTime, NaiveTime, TimeZone, Utc};
|
||||
use chrono::{Local, NaiveDate, NaiveDateTime, NaiveTime, TimeZone, Utc};
|
||||
|
||||
// Parse the date
|
||||
let date = NaiveDate::parse_from_str(date_str, "%Y-%m-%d")
|
||||
@@ -865,7 +865,11 @@ fn parse_event_datetime(
|
||||
// Combine date and time
|
||||
let datetime = NaiveDateTime::new(date, time);
|
||||
|
||||
// Assume local time and convert to UTC (in a real app, you'd want timezone support)
|
||||
Ok(Utc.from_utc_datetime(&datetime))
|
||||
// Treat the datetime as local time and convert to UTC
|
||||
let local_datetime = Local.from_local_datetime(&datetime)
|
||||
.single()
|
||||
.ok_or_else(|| "Ambiguous local datetime".to_string())?;
|
||||
|
||||
Ok(local_datetime.with_timezone(&Utc))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user