deribit_http/
utils.rs

1use chrono::{DateTime, Duration, Local, Utc}; // Add chrono import
2
3/// Returns tomorrow's date in Deribit format (DDMMMYY)
4///
5/// # Returns
6/// A string representing tomorrow's date in the format used by Deribit:
7/// - DD: Two-digit day
8/// - MMM: Three-letter month (uppercase)
9/// - YY: Two-digit year
10///
11pub fn get_tomorrow_deribit_format() -> String {
12    let today = Local::now();
13    let tomorrow = today + Duration::days(1);
14
15    // Format: day (2 digits) + month (3 letters uppercase) + year (2 digits)
16    // Example: 15SEP25 for September 15, 2025
17    let day = tomorrow.format("%d").to_string(); // Two-digit day
18    let month = tomorrow.format("%b").to_string().to_uppercase(); // Three-letter month
19    let year = tomorrow.format("%y").to_string(); // Two-digit year
20
21    format!("{}{}{}", day, month, year)
22}
23
24/// Converts a date string from Deribit format to UTC DateTime
25///
26/// Parses a date string in Deribit's DDMMMYY format and converts it to a UTC DateTime.
27///
28/// # Arguments
29///
30/// * `date` - A date string in DDMMMYY format (e.g., "15SEP25")
31///
32/// # Returns
33///
34/// Returns a `Result` containing either:
35/// - `Ok(DateTime<Utc>)` - The parsed date in UTC timezone
36/// - `Err(chrono::ParseError)` - If the date string cannot be parsed
37///
38/// # Examples
39///
40/// ```
41/// use deribit_http::utils::from_deribit_format_date;
42///
43/// let date = from_deribit_format_date("15SEP25").unwrap();
44/// ```
45pub fn from_deribit_format_date(date: &str) -> Result<DateTime<Utc>, chrono::ParseError> {
46    Ok(DateTime::parse_from_str(date, "%d%b%y")?.with_timezone(&Utc))
47}