r1chardj0n3s / parse

Parse strings using a specification based on the Python format() syntax.
http://pypi.python.org/pypi/parse
MIT License
1.72k stars 101 forks source link

Support various number of digits after the comma in the timestamp %f … #178

Closed bbertincourt closed 10 months ago

bbertincourt commented 10 months ago

…format

This PR adds a small modification to support various number of digits (1 to 6) after the comma to be picked up and recognized by the "%f" directive as it does with datetime.strptime.

I believe this also answers https://github.com/r1chardj0n3s/parse/issues/127

Current State

from parse import parse

ok_result = parse("{:%H:%M:%S.%f}", "12:34:56.789000")
print(ok_result)

fail_result = parse("{:%H:%M:%S.%f}", "12:34:56.789")
print(fail_result)  # is None

Output[]

<Result (datetime.time(12, 34, 56, 789000),) {}>
None

Desired State

Output[]

<Result (datetime.time(12, 34, 56, 789000),) {}>
<Result (datetime.time(12, 34, 56, 789000),) {}>
codecov-commenter commented 10 months ago

:warning: Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 94.65%. Comparing base (8ae5d30) to head (b1d2121). Report is 8 commits behind head on master.

:exclamation: Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #178 +/- ## ======================================= Coverage 94.65% 94.65% ======================================= Files 1 1 Lines 543 543 Branches 132 132 ======================================= Hits 514 514 Misses 18 18 Partials 11 11 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

wimglenn commented 10 months ago

This seems reasonable. Thanks for the contribution!

bbertincourt commented 10 months ago

@wimglenn I have these weirdly formatted log exports that parse does a really good job on. Helps me really, thanks for maintaining parse.