Skip to content

Commit

Permalink
Merge pull request #85 from ysthakur/fix-relative-time
Browse files Browse the repository at this point in the history
Don't use Durations for calculating relative times
  • Loading branch information
cakebaker authored Sep 17, 2024
2 parents e543ee6 + e41e26f commit 212c6f7
Show file tree
Hide file tree
Showing 2 changed files with 305 additions and 284 deletions.
10 changes: 3 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use chrono::{
Timelike,
};

use parse_relative_time::parse_relative_time;
use parse_relative_time::parse_relative_time_at_date;
use parse_timestamp::parse_timestamp;

#[derive(Debug, PartialEq)]
Expand Down Expand Up @@ -228,12 +228,8 @@ pub fn parse_datetime_at_date<S: AsRef<str> + Clone>(
}

// Parse relative time.
if let Ok(relative_time) = parse_relative_time(s.as_ref()) {
let current_time = DateTime::<FixedOffset>::from(date);

if let Some(date_time) = current_time.checked_add_signed(relative_time) {
return Ok(date_time);
}
if let Ok(datetime) = parse_relative_time_at_date(date, s.as_ref()) {
return Ok(DateTime::<FixedOffset>::from(datetime));
}

// parse time only dates
Expand Down
Loading

0 comments on commit 212c6f7

Please sign in to comment.