Skip to content

Commit b615eff

Browse files
authored
Merge pull request uutils#32 from philolo1/fix/add-unix-timestamp-test
Add tests for unix timestamp
2 parents efee20b + cebf55c commit b615eff

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ cannot be parsed as a relative time.
8080

8181
The `from_str` function returns:
8282

83-
- `Ok(DateTime<FixedOffset>)` - If the input string can be prsed as a datetime
83+
- `Ok(DateTime<FixedOffset>)` - If the input string can be parsed as a datetime
8484
- `Err(ParseDurationError::InvalidInput)` - If the input string cannot be parsed
8585

8686
## Fuzzer

src/parse_datetime.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,25 @@ mod tests {
243243
}
244244
}
245245

246+
#[cfg(test)]
247+
mod timestamp {
248+
use crate::parse_datetime::from_str;
249+
use chrono::{TimeZone, Utc};
250+
251+
#[test]
252+
fn test_positive_offsets() {
253+
let offsets: Vec<i64> = vec![
254+
0, 1, 2, 10, 100, 150, 2000, 1234400000, 1334400000, 1692582913, 2092582910,
255+
];
256+
257+
for offset in offsets {
258+
let time = Utc.timestamp(offset, 0);
259+
let dt = from_str(format!("@{}", offset));
260+
assert_eq!(dt.unwrap(), time);
261+
}
262+
}
263+
}
264+
246265
/// Used to test example code presented in the README.
247266
mod readme_test {
248267
use crate::parse_datetime::from_str;

0 commit comments

Comments
 (0)