Skip to main content

format_time

Function format_time 

Source
pub fn format_time(
    input: &str,
    mapping: &HashMap<&str, &str>,
    trie: Option<&Trie<()>>,
) -> Option<String>
Expand description

Convert a time format string using a dialect-specific mapping

This function uses a trie-based algorithm to handle overlapping format specifiers correctly. For example, %Y and %y both start with %, so the algorithm needs to find the longest matching specifier.

§Arguments

  • input - The format string to convert
  • mapping - A map from source format specifiers to target format specifiers
  • trie - Optional pre-built trie for the mapping keys (for performance)

§Returns

The converted format string, or None if input is empty

§Example

use polyglot_sql::time::format_time;
use std::collections::HashMap;

let mut mapping = HashMap::new();
mapping.insert("%Y", "YYYY");
mapping.insert("%m", "MM");
mapping.insert("%d", "DD");

let result = format_time("%Y-%m-%d", &mapping, None);
assert_eq!(result, Some("YYYY-MM-DD".to_string()));