llm/types.rs
1use std::fmt::Display;
2
3use chrono::{DateTime, TimeZone};
4use serde::{Deserialize, Serialize};
5
6/// A newtype wrapper for ISO 8601 timestamp strings
7#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
8pub struct IsoString(pub String);
9
10impl IsoString {
11 /// Create a new `IsoString` from the current time
12 pub fn now() -> Self {
13 Self(chrono::Utc::now().to_rfc3339())
14 }
15
16 /// Create an `IsoString` from a chrono `DateTime`
17 pub fn from_datetime<T: TimeZone>(datetime: &DateTime<T>) -> Self
18 where
19 T::Offset: Display,
20 {
21 Self(datetime.to_rfc3339())
22 }
23
24 /// Get the inner string value
25 pub fn as_str(&self) -> &str {
26 &self.0
27 }
28}