time-rs / time

The most used Rust library for date and time handling.
https://time-rs.github.io
Apache License 2.0
1.1k stars 273 forks source link

could there be a way to parse out of a longer string? #471

Closed laralove143 closed 2 years ago

laralove143 commented 2 years ago

the format_description is very useful, but it wouldn't work with strings like "aaa 12:00 aaa" so maybe there could be made something like format_description!("*[hour]:[minute]*"), it'd be very useful

jhpratt commented 2 years ago

Syntax aside, how would this even work? The ambiguities would be numerous.

laralove143 commented 2 years ago

how so? the rule should be simple, * matches 0 or more characters except the ones that would be matched by the next capture after it, like in *[hour], * would match any number of any character that isn't a digit (or whatever characters [hour] would match)

jhpratt commented 2 years ago

And if there's two instances of the format in a string? It's not clear with should be accepted. Or if there's a random number in the string before the format starts. I think this is too broad, highly error prone, easy to break on the user's end, and ambiguous in many situations. Feel free to try to convince me otherwise, but I don't see this as happening.