mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-27 19:46:48 +08:00
revert: fix(analytics): feat(analytics): analytics APIs (#2777)
This commit is contained in:
@ -170,51 +170,3 @@ pub mod json_string {
|
||||
serde_json::from_str(&j).map_err(de::Error::custom)
|
||||
}
|
||||
}
|
||||
|
||||
/// Use a custom ISO 8601 format when serializing and deserializing
|
||||
/// [`PrimitiveDateTime`][PrimitiveDateTime].
|
||||
///
|
||||
/// [PrimitiveDateTime]: ::time::PrimitiveDateTime
|
||||
pub mod iso8601custom {
|
||||
|
||||
use serde::{ser::Error as _, Deserializer, Serialize, Serializer};
|
||||
use time::{
|
||||
format_description::well_known::{
|
||||
iso8601::{Config, EncodedConfig, TimePrecision},
|
||||
Iso8601,
|
||||
},
|
||||
serde::iso8601,
|
||||
PrimitiveDateTime, UtcOffset,
|
||||
};
|
||||
|
||||
const FORMAT_CONFIG: EncodedConfig = Config::DEFAULT
|
||||
.set_time_precision(TimePrecision::Second {
|
||||
decimal_digits: None,
|
||||
})
|
||||
.encode();
|
||||
|
||||
/// Serialize a [`PrimitiveDateTime`] using the well-known ISO 8601 format.
|
||||
pub fn serialize<S>(date_time: &PrimitiveDateTime, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
date_time
|
||||
.assume_utc()
|
||||
.format(&Iso8601::<FORMAT_CONFIG>)
|
||||
.map_err(S::Error::custom)?
|
||||
.replace('T', " ")
|
||||
.replace('Z', "")
|
||||
.serialize(serializer)
|
||||
}
|
||||
|
||||
/// Deserialize an [`PrimitiveDateTime`] from its ISO 8601 representation.
|
||||
pub fn deserialize<'a, D>(deserializer: D) -> Result<PrimitiveDateTime, D::Error>
|
||||
where
|
||||
D: Deserializer<'a>,
|
||||
{
|
||||
iso8601::deserialize(deserializer).map(|offset_date_time| {
|
||||
let utc_date_time = offset_date_time.to_offset(UtcOffset::UTC);
|
||||
PrimitiveDateTime::new(utc_date_time.date(), utc_date_time.time())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user