use super::error;
use super::spec;
use chrono::{DateTime, FixedOffset, Local};
use log::error;
pub fn sip_string(text: &str) -> String {
text.replace('|', "")
}
pub fn sip_date_now() -> String {
Local::now().format(spec::SIP_DATE_FORMAT).to_string()
}
pub fn sip_date(iso_date: &str) -> Result<String, error::Error> {
match DateTime::parse_from_rfc3339(iso_date) {
Ok(dt) => Ok(dt.format(spec::SIP_DATE_FORMAT).to_string()),
Err(s) => {
error!("Error parsing sip date: {} : {}", iso_date, s);
Err(error::Error::DateFormatError)
}
}
}
pub fn sip_date_from_dt(dt: &DateTime<FixedOffset>) -> String {
dt.format(spec::SIP_DATE_FORMAT).to_string()
}
pub fn space_bool(value: bool) -> &'static str {
match value {
true => "Y",
false => " ",
}
}
pub fn sip_bool(value: bool) -> &'static str {
match value {
true => "Y",
false => "N",
}
}
pub fn num_bool(value: bool) -> &'static str {
match value {
true => "1",
false => "0",
}
}
pub fn sip_count4(value: usize) -> String {
format!("{value:0>4}")
}