Skip to content

Make parse_datetime::parse_datetime::from_str accept relative time #33

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

Merged

Conversation

philolo1
Copy link
Contributor

@tertsdiepraam @sylvestre

As discussed in uutils/coreutils#5181, this makes parse_dateime::parse_datetime::from_str accept relative time.

@philolo1 philolo1 force-pushed the fix/datetime-should-parse-relative branch from 771b565 to 82ea54a Compare August 21, 2023 11:25
@tertsdiepraam
Copy link
Member

I think this is an opportunity to clean up the interface. There's no reason to expose multiple functions with overlapping functionality. The only public items should be:

  • A parse_datetime function (module should be private and be renamed)
  • A parse_datetime_at_date function
  • ParseDateTimeError (renamed from ParseDurationError)

The parse_datetime module could be called datetime_format maybe (or some other name).

This would hide functions that we are currently using in coreutils, but those should be forced to change :)

@philolo1
Copy link
Contributor Author

philolo1 commented Aug 21, 2023 via email

@tertsdiepraam
Copy link
Member

That makes sense. I think i can tackle that

Great! Thanks!

but with those changes we should probably also increase the version number.

I agree, we'll bump the version number on the next release.

It might cause quite some conflict for existing prs.

Indeed. It's a bit unfortunate, but the sooner we do this the better in my opinion.

@philolo1 philolo1 force-pushed the fix/datetime-should-parse-relative branch 4 times, most recently from 7773727 to 5e8dca9 Compare August 22, 2023 14:31
@philolo1
Copy link
Contributor Author

philolo1 commented Aug 22, 2023

@tertsdiepraam I have done some refactoring. When you have some time, can you take a look a look (its quite a big renaming / refactor, so i am sure there will be some revisions).

Here is what i did:

  • put the parse_datetime into lib.rs
  • Create new file parse_relative_time.rs with the relative time helper function.
  • Renames from_str to parse_datetime and parse_relative_time.
  • Adds function parse_datetime_at_date
  • Update Readme.
  • Update version number as interfaces changes

@philolo1 philolo1 force-pushed the fix/datetime-should-parse-relative branch from 5e8dca9 to 3a68715 Compare August 22, 2023 14:33
@tertsdiepraam
Copy link
Member

We'll get to the version number once we actually publish. You can revert that for now.

Also, edition in Cargo.toml refers to the Rust edition. There's no 2023 edition. 2021 is the latest (and the next one will be 2024). That's what makes the CI fail.

Copy link
Member

@tertsdiepraam tertsdiepraam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First little comment. I'll get to the rest once the CI passes. But looks promising!

@philolo1
Copy link
Contributor Author

@tertsdiepraam Sure, and thanks for the comments. I will mention you ones the pipeline is fixed.

@philolo1 philolo1 force-pushed the fix/datetime-should-parse-relative branch 4 times, most recently from 7b72550 to a99af04 Compare August 22, 2023 15:38
@philolo1
Copy link
Contributor Author

@tertsdiepraam the pipeline is passing now.

@sylvestre
Copy link
Contributor

needs to be rebased :)

@philolo1 philolo1 force-pushed the fix/datetime-should-parse-relative branch 2 times, most recently from 2ae1b40 to ce6ea28 Compare August 22, 2023 23:55
@philolo1 philolo1 changed the title Make parse_dateime::parse_datetime::from_str accept relative time Make parse_datetime::parse_datetime::from_str accept relative time Aug 23, 2023
@philolo1
Copy link
Contributor Author

@sylvestre rebased

@philolo1
Copy link
Contributor Author

Any updates/ feedback?

@tertsdiepraam
Copy link
Member

It's only been a day. We're not that fast ;p

I'll take a look soon!

Copy link
Member

@tertsdiepraam tertsdiepraam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, sorry it took a while. These kinds of changes are always a bit hard to review, because it's hard to distinguish stuff being moved around with actual changes in the code. I might have accidentally commented on some things that aren't due to this change. If that's the case, just reply saying that it's irrelevant :)

@philolo1
Copy link
Contributor Author

@tertsdiepraam thanks for taking the time to review this.

@philolo1 philolo1 force-pushed the fix/datetime-should-parse-relative branch from 016cf2a to 42def80 Compare August 27, 2023 15:21
@philolo1 philolo1 force-pushed the fix/datetime-should-parse-relative branch from 42def80 to f3b7d47 Compare August 28, 2023 11:44
@philolo1 philolo1 force-pushed the fix/datetime-should-parse-relative branch 4 times, most recently from a0bdb21 to fbf1c4e Compare August 28, 2023 12:04
@philolo1 philolo1 requested a review from tertsdiepraam August 28, 2023 12:06
@philolo1 philolo1 force-pushed the fix/datetime-should-parse-relative branch from fbf1c4e to 8a99960 Compare August 28, 2023 12:07
@philolo1
Copy link
Contributor Author

@tertsdiepraam i believe i have adjusted the code according to your review. As its a big change of the library, take your time to review it.

Copy link
Member

@tertsdiepraam tertsdiepraam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! This is almost ready to be merged, just some small final things to clean up.

Create new file parse_relative_time.rs with the relative time helper function.
Renames from_str to parse_datetime and parse_relative time.
Adds function parse_datetime_at_date.
@philolo1 philolo1 force-pushed the fix/datetime-should-parse-relative branch from 8a99960 to f10749e Compare August 29, 2023 00:03
@philolo1 philolo1 requested a review from tertsdiepraam August 29, 2023 00:04
@philolo1
Copy link
Contributor Author

@tertsdiepraam i believe i fixed all issues.

@tertsdiepraam tertsdiepraam merged commit 2737b4a into uutils:main Aug 29, 2023
@sylvestre
Copy link
Contributor

@philolo1 is it by design that parse_relative_time is private?
I am trying to use it in the rust coreutils:

error[E0603]: function `parse_relative_time` is private
  --> src/uu/touch/src/touch.rs:92:49
   |
92 |             if let Ok(offset) = parse_datetime::parse_relative_time(date) {
   |                                                 ^^^^^^^^^^^^^^^^^^^ private function

@philolo1
Copy link
Contributor Author

@sylvestre i am sorry I do not remember why we only exposed one function. I dont see any issue also exposing this function.
Do you remember the reason @tertsdiepraam ?
@sylvestre it would be fine with me to expose this.

@sylvestre
Copy link
Contributor

@philolo1 yeah, it is significantly reducing the scope of this crate :)

could you please make the change? thanks

@philolo1
Copy link
Contributor Author

Sure i can do it either today or tomorrow @sylvestre , then we should create a new version

@sylvestre
Copy link
Contributor

actually, i did it here :)
#50

@philolo1
Copy link
Contributor Author

philolo1 commented Sep 23, 2023 via email

@tertsdiepraam
Copy link
Member

tertsdiepraam commented Sep 23, 2023

Do you remember the reason @tertsdiepraam ?

Yes, there's a good reason not to do relative time only, because a relative time on its own is undefined. For example, if we get a relative time of "1 month", how many days should we go forward? We've tried to work around this a bit, but that makes it more difficult. Instead we should always parse the full datetime relative to some reference datetime (which is the current time by default). So, in that format both "tomorrow" and "2023-09-23" are supported. I don't think there's anything in the coreutils that accept only a relative time, but not an absolute time as well. We haven't reduced the scope of the crate because the parse_datetime function is a superset of parse_relative_time in terms of functionality.

@sylvestre
Copy link
Contributor

oh ok, my bad :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants