| 204 | } |
| 205 | |
| 206 | fn execute(&self, context: &FunctionContext) -> FunctionResult<Value> { |
| 207 | debug!("Executing DATETIME function"); |
| 208 | |
| 209 | // Validate argument count |
| 210 | context.validate_argument_count(1)?; |
| 211 | |
| 212 | // Get the datetime string argument |
| 213 | let datetime_str = match context.get_argument(0)? { |
| 214 | Value::String(s) => s, |
| 215 | _ => { |
| 216 | return Err(FunctionError::InvalidArgumentType { |
| 217 | message: "DATETIME argument must be a string".to_string(), |
| 218 | }) |
| 219 | } |
| 220 | }; |
| 221 | |
| 222 | // Parse the ISO 8601 datetime string |
| 223 | match parse_iso_datetime(datetime_str) { |
| 224 | Ok(datetime) => { |
| 225 | debug!( |
| 226 | "Successfully parsed datetime: {} -> {}", |
| 227 | datetime_str, datetime |
| 228 | ); |
| 229 | Ok(Value::DateTime(datetime)) |
| 230 | } |
| 231 | Err(e) => { |
| 232 | warn!("Failed to parse datetime '{}': {}", datetime_str, e); |
| 233 | Err(FunctionError::ExecutionError { |
| 234 | message: format!("Invalid datetime format '{}': {}", datetime_str, e), |
| 235 | }) |
| 236 | } |
| 237 | } |
| 238 | } |
| 239 | } |
| 240 | |
| 241 | /// NOW function - returns current system time |