Add a unix timestamp

This pr adds tests to support the @ unix timestamp.
This commit is contained in:
Patrick Klitzke
2023-08-21 11:03:56 +09:00
parent efee20bf01
commit cebf55cf82
2 changed files with 20 additions and 1 deletions
+1 -1
View File
@@ -80,7 +80,7 @@ cannot be parsed as a relative time.
The `from_str` function returns:
- `Ok(DateTime<FixedOffset>)` - If the input string can be prsed as a datetime
- `Ok(DateTime<FixedOffset>)` - If the input string can be parsed as a datetime
- `Err(ParseDurationError::InvalidInput)` - If the input string cannot be parsed
## Fuzzer
+19
View File
@@ -243,6 +243,25 @@ mod tests {
}
}
#[cfg(test)]
mod timestamp {
use crate::parse_datetime::from_str;
use chrono::{TimeZone, Utc};
#[test]
fn test_positive_offsets() {
let offsets: Vec<i64> = vec![
0, 1, 2, 10, 100, 150, 2000, 1234400000, 1334400000, 1692582913, 2092582910,
];
for offset in offsets {
let time = Utc.timestamp(offset, 0);
let dt = from_str(format!("@{}", offset));
assert_eq!(dt.unwrap(), time);
}
}
}
/// Used to test example code presented in the README.
mod readme_test {
use crate::parse_datetime::from_str;