MCPcopy Create free account
hub / github.com/aws/aws-lambda-rust-runtime / normalize_timestamp

Function normalize_timestamp

lambda-events/src/encodings/time.rs:183–213  ·  view source on GitHub ↗
(deserializer: D)

Source from the content-addressed store, hash-verified

181}
182
183fn normalize_timestamp<'de, D>(deserializer: D) -> Result<(u64, u64), D::Error>
184where
185 D: Deserializer<'de>,
186{
187 #[derive(Deserialize)]
188 #[serde(untagged)]
189 enum StringOrNumber {
190 String(String),
191 Float(f64),
192 Int(u64),
193 }
194
195 let input: f64 = match StringOrNumber::deserialize(deserializer)? {
196 StringOrNumber::String(s) => s.parse::<f64>().map_err(DeError::custom)?,
197 StringOrNumber::Float(f) => f,
198 StringOrNumber::Int(i) => i as f64,
199 };
200
201 // We need to do this due to floating point issues.
202 let input_as_string = input.to_string();
203 let parts: Result<Vec<u64>, _> = input_as_string
204 .split('.')
205 .map(|x| x.parse::<u64>().map_err(DeError::custom))
206 .collect();
207 let parts = parts?;
208 if parts.len() > 1 {
209 Ok((parts[0], parts[1]))
210 } else {
211 Ok((parts[0], 0))
212 }
213}
214
215#[cfg(test)]
216#[allow(deprecated)]

Callers 2

deserialize_millisecondsFunction · 0.85
deserialize_secondsFunction · 0.85

Calls 2

collectMethod · 0.80
deserializeFunction · 0.50

Tested by

no test coverage detected