formualizer_eval/timezone.rs
1/// Timezone support for date/time functions
2use chrono::{Local, NaiveDateTime, Utc};
3
4/// Timezone specification for date/time calculations
5/// Excel behavior: always uses local timezone
6/// This enum allows future extensions while maintaining Excel compatibility
7#[derive(Clone, Debug, Default)]
8pub enum TimeZoneSpec {
9 /// Use the system's local timezone (Excel default behavior)
10 #[default]
11 Local,
12 /// Use UTC timezone
13 Utc,
14 // Named timezone variant removed until feature introduced.
15}
16
17// (Derived Default provides Local)
18
19impl TimeZoneSpec {
20 /// Get the current datetime in the specified timezone
21 pub fn now(&self) -> NaiveDateTime {
22 match self {
23 TimeZoneSpec::Local => Local::now().naive_local(),
24 TimeZoneSpec::Utc => Utc::now().naive_utc(),
25 }
26 }
27
28 /// Get today's date in the specified timezone
29 pub fn today(&self) -> chrono::NaiveDate {
30 self.now().date()
31 }
32}