Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cargo test fails at 0:20 JST #36

Open
philolo1 opened this issue Aug 27, 2023 · 4 comments · May be fixed by #80
Open

Cargo test fails at 0:20 JST #36

philolo1 opened this issue Aug 27, 2023 · 4 comments · May be fixed by #80

Comments

@philolo1
Copy link
Contributor

I ran cargo test on the current repo and got two errors:

failures:

---- test_from_str_at_date_day stdout ----
thread 'test_from_str_at_date_day' panicked at 'assertion failed: `(left == right)`
  left: `Duration { secs: 0, nanos: 0 }`,
 right: `Duration { secs: 86400, nanos: 0 }`', tests/simple.rs:133:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

---- test_duration_parsing stdout ----
thread 'test_duration_parsing' panicked at 'assertion failed: `(left == right)`
  left: `Duration { secs: 31449600, nanos: 0 }`,
 right: `Duration { secs: 31536000, nanos: 0 }`', tests/simple.rs:16:5


failures:
    test_duration_parsing
    test_from_str_at_date_day

test result: FAILED. 4 passed; 2 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.01s

error: test failed, to rerun pass `--test simple`

I did not get the errors before, so it might have to do with the my timezone. It looks like there might be an error or a different usage between JST and UTC.

philolo1 added a commit to philolo1/parse_datetime that referenced this issue Aug 27, 2023
This pr should fix the issue with the timezones uutils#36. Now all tests are passing.
@philolo1
Copy link
Contributor Author

I think it has to do with the fact that its Aug28th on JST but AUG 27th on UTC.

philolo1 added a commit to philolo1/parse_datetime that referenced this issue Aug 27, 2023
This pr should fix the issue with the timezones uutils#36. Now all tests are passing.
philolo1 added a commit to philolo1/parse_datetime that referenced this issue Aug 27, 2023
This pr should fix the issue with the timezones uutils#36. Now all tests are passing.
@philolo1
Copy link
Contributor Author

Interestingly the tests work at 9:15 JST.

@drmorr0
Copy link
Contributor

drmorr0 commented Jun 11, 2024

I ran into this issue in my unit tests, which pass in the morning and fail in the evening (I'm in Pacific time, UTC-8). I believe the root cause of this issue is in parse_relative_time.rs:

pub fn parse_relative_time(s: &str) -> Result<Duration, ParseDateTimeError> {
    parse_relative_time_at_date(Utc::now().date_naive(), s)
}
...
pub fn parse_relative_time_at_date(
    date: NaiveDate,
    s: &str,
) -> Result<Duration, ParseDateTimeError> {
...
    if captures_processed == 0 {
        Err(ParseDateTimeError::InvalidInput)
    } else {
        let time_now = Local::now().date_naive();
        let date_duration = date - time_now;

        Ok(total_duration + date_duration)
    }
}

In other words, parse_relative_time is passing in a Utc::now, and then we're subtracting a Local::now date, which definitely isn't going to work if the offset between Utc and Local crosses midnight. Any progress towards a fix on this?

@tertsdiepraam
Copy link
Member

Nice find! Feel free to open a PR!

@drmorr0 drmorr0 linked a pull request Jun 11, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants