Skip to content

Commit bdcc831

Browse files
committed
add a unix timestamp
1 parent 497bebb commit bdcc831

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-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: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,38 @@ mod tests {
235235
}
236236
}
237237

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

tests/simple.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,14 @@ fn test_from_str_at_date_day() {
136136
);
137137
}
138138

139+
#[test]
140+
fn test_unix_timestamp() {
141+
let res = from_str("2004-02-29 16:21:42");
142+
143+
dbg!(res);
144+
145+
}
146+
139147
#[test]
140148
fn test_invalid_input_at_date() {
141149
let today = Utc::now().date_naive();

0 commit comments

Comments
 (0)