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

support parse_and_remainder #209

Closed
sundy-li opened this issue Jan 21, 2025 · 6 comments · Fixed by #215
Closed

support parse_and_remainder #209

sundy-li opened this issue Jan 21, 2025 · 6 comments · Fixed by #215
Labels
enhancement New feature or request

Comments

@sundy-li
Copy link

Hi, we are migrating chrono into jiff, is there any function that works same as parse_and_remainder ?

https://docs.rs/chrono/latest/chrono/format/fn.parse_and_remainder.html

@BurntSushi
Copy link
Owner

BurntSushi commented Jan 21, 2025

I don't believe so, but I designed the internal parsers to be able to support this style of API.

However, I wanted a concrete use case for where and how it's used before exposing anything. Can you share an MRE of your Chrono code and the high level use case?

@BurntSushi BurntSushi added the enhancement New feature or request label Jan 21, 2025
@sundy-li
Copy link
Author

sundy-li commented Jan 22, 2025

  1. postgresql/greenplum support parse flexible timestamp as the issue describes

  2. we are using a setting named parse_datetime_ignore_remainder defaults to 1 and use chrono to parse it.

https://github.com/databendlabs/databend/blob/7969d365b5003a4cf1224d88050787a179653ac4/src/query/functions/src/scalars/timestamp/src/datetime.rs#L367-L472

@BurntSushi
Copy link
Owner

Looking at that code, it looks like you aren't actually using the remainder right? You're just looking to parse a prefix?

Also, if I do this, I'll probably return an offset into the input given instead of the &str. That's because Jiff's parsing routines work on both &[u8] and &str, and returning the right type of slice would require more generic machinery that I'm not keen on adding. But with an offset, I think you should be fine.

@sundy-li
Copy link
Author

Looking at that code, it looks like you aren't actually using the remainder right? You're just looking to parse a prefix?

Yes, parse the prefix and ignore the remainder that unable to be parsed.

Return an offset would be ok.

BurntSushi added a commit that referenced this issue Jan 23, 2025
I had always intended to expose the ability to parse a prefix of some
string via Jiff's `strptime`-like API, but I wanted a use case first to
make sure the API was well motivated. So this is mostly just exposing
what was already there and documenting it.

Closes #209
BurntSushi added a commit that referenced this issue Jan 23, 2025
I had always intended to expose the ability to parse a prefix of some
string via Jiff's `strptime`-like API, but I wanted a use case first to
make sure the API was well motivated. So this is mostly just exposing
what was already there and documenting it.

Closes #209
@BurntSushi
Copy link
Owner

BurntSushi commented Jan 23, 2025

OK, this should now be available via jiff::fmt::strtime::BrokenDownTime::parse_prefix in jiff 0.1.26. Please let me know if it works for you. I'm hoping to do a jiff 0.2 release soon, so if I've flubbed the API, I can do a quick breaking change if I know about it. Thanks!

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

Successfully merging a pull request may close this issue.

2 participants