You've already forked parse_datetime
mirror of
https://github.com/uutils/parse_datetime.git
synced 2026-06-10 16:13:15 -07:00
Add a unix timestamp
This pr adds tests to support the @ unix timestamp.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user