mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-28 04:04:55 +08:00
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:
@ -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
|
||||
|
||||
Reference in New Issue
Block a user