refactor(connector): [Adyen] change expiresAt time from string to unixtimestamp (#3506)

Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
This commit is contained in:
Swangi Kumari
2024-01-31 22:37:47 +05:30
committed by GitHub
parent 7251f6474f
commit b7c0f9aa09
4 changed files with 63 additions and 7 deletions

View File

@ -84,6 +84,53 @@ pub mod iso8601 {
})
}
}
/// Use the well-known ISO 8601 format which is without timezone when serializing and deserializing an
/// [`Option<PrimitiveDateTime>`][PrimitiveDateTime].
///
/// [PrimitiveDateTime]: ::time::PrimitiveDateTime
pub mod option_without_timezone {
use serde::{de, Deserialize, Serialize};
use time::macros::format_description;
use super::*;
/// Serialize an [`Option<PrimitiveDateTime>`] using the well-known ISO 8601 format which is without timezone.
pub fn serialize<S>(
date_time: &Option<PrimitiveDateTime>,
serializer: S,
) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
date_time
.map(|date_time| {
let format =
format_description!("[year]-[month]-[day]T[hour]:[minute]:[second]");
date_time.assume_utc().format(format)
})
.transpose()
.map_err(S::Error::custom)?
.serialize(serializer)
}
/// Deserialize an [`Option<PrimitiveDateTime>`] from its ISO 8601 representation.
pub fn deserialize<'a, D>(deserializer: D) -> Result<Option<PrimitiveDateTime>, D::Error>
where
D: Deserializer<'a>,
{
Option::deserialize(deserializer)?
.map(|time_string| {
let format =
format_description!("[year]-[month]-[day]T[hour]:[minute]:[second]");
PrimitiveDateTime::parse(time_string, format).map_err(|_| {
de::Error::custom(format!(
"Failed to parse PrimitiveDateTime from {time_string}"
))
})
})
.transpose()
}
}
}
/// Use the UNIX timestamp when serializing and deserializing an