Skip to content

Commit 242df05

Browse files
committed
Add a unix timestamp
This pr adds tests to support the @ unix timestamp.
1 parent 497bebb commit 242df05

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
@@ -235,6 +235,25 @@ mod tests {
235235
}
236236
}
237237

238+
#[cfg(test)]
239+
mod timestamp {
240+
use crate::parse_datetime::from_str;
241+
use chrono::{TimeZone, Utc};
242+
243+
#[test]
244+
fn test_positive_offsets() {
245+
let offsets: Vec<i64> = vec![
246+
0, 1, 2, 10, 100, 150, 2000, 1234400000, 1334400000, 1692582913, 2092582910,
247+
];
248+
249+
for offset in offsets {
250+
let time = Utc.timestamp(offset, 0);
251+
let dt = from_str(format!("@{}", offset));
252+
assert_eq!(dt.unwrap(), time);
253+
}
254+
}
255+
}
256+
238257
/// Used to test example code presented in the README.
239258
mod readme_test {
240259
use crate::parse_datetime::from_str;

0 commit comments

Comments
 (0)