chrono
chrono copied to clipboard
#560: Unable to parse millisecond unix timestamps
Thanks for contributing to chrono!
- [X] Have you added yourself and the change to the changelog? (Don't worry about adding the PR number)
- [X] If this pull request fixes a bug, does it add a test that verifies that we can't reintroduce it?
This PR tries to solve #560. When parsing Timestamps, it allows to check the next item fixed length to avoid Timestamp consuming all the remain digits (see #560 example with nanoseconds "%s%3f"). It groups items in tuples (current and next item) inside parse_internal, using slice windows.
Circling back to this. This seems like a reasonable approach to me.
I agree this is worth fixing. Combining %s%3f
to parse a millisecond timestamp is clever. On the other hand it feels just a bit too magical.
An alternative is to add new specifiers to allow parsing millisecond, microsecond, and nanosecond timestamps as a single integer. @djc any preferences?
Also @meiamsome raised a good issue about the implementation here. @jgoday This PR is near the end of its second year... Would you still be available to push it forwards?
The approach in this PR seems wordt persuing to me, but in a more general way.
It would be nice to be able to parse 63015
to 6:30:15
with %-H%M%S
. I.e. support parsing one variable-length number followed by one or more fixed-length numbers.
Given the lack of response from the original submitter, going to just close this for now. IMO the original issue isn't a high priority.
An alternative is to add new specifiers to allow parsing millisecond, microsecond, and nanosecond timestamps as a single integer. @djc any preferences?
This is a worthy improvement.
Worthy how? Have you personally had a use case for this? Given the relative lack of resources I would like to avoid adding features people just think of.
The lack of support for parsing string millisecond timestamps does come up in https://vector.dev/ occasionally, where we use chrono
for date/timestamp parsing. Recent example: https://github.com/vectordotdev/vector/discussions/19577
@jszwedko please open a new issue explaining your use case.
@jszwedko please open a new issue explaining your use case.
I'd actually opened the original issue 🙂 It's here: https://github.com/chronotope/chrono/issues/560
Okay, I'm open to reviewing a new PR that takes into account the feedback on this PR so far.