1use chrono::{DateTime, Utc};
2use url::{ParseError, Url};
3
4use crate::errors::{SuperSTACError, ValidationError};
5
6pub fn get_date_time() -> DateTime<Utc> {
8 Utc::now()
9}
10
11pub fn parse_url(url: &str) -> Result<Url, ParseError> {
13 Url::parse(url)
14}
15
16pub fn validate_identifier(id: &str) -> Result<(), SuperSTACError> {
19 if id.trim().is_empty() {
20 return Err(ValidationError::MissingField("id".into()).into());
21 }
22
23 if !id.chars().all(|c| c.is_ascii_alphanumeric() || c == '-' || c == '_') {
24 return Err(ValidationError::InvalidIdentifier(
25 "only ASCII letters, digits, hyphen, and underscore are allowed".into(),
26 )
27 .into());
28 }
29
30 Ok(())
31}