-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Add support for milliseconds formatted as %f in strptime(fmt). #1413
Conversation
… of the date format string, e.g. "%Y-%m-%dT%H:%M:%S.%fZ".
char *fmtdup = strdup(fmt); | ||
|
||
int ms = -1; | ||
char *pf = strstr(fmtdup, "%f"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Watch out! %
can be escaped with a preceding (unescaped) %
. You have to step over the format string character (well, byte) by character (byte).
I wonder if we may not have to implement |
int ms = -1; | ||
char *pf = strstr(fmtdup, "%f"); | ||
if (pf) { | ||
char *msfmtloc = pf - 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Buffer underrun if the format string starts with "%f"
.
char *msfmtloc = pf - 1; | ||
char delim = *msfmtloc; | ||
*msfmtloc = '\0'; | ||
char *msloc = strrchr(inputdup, delim); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The assumption here is that delim
will not be used for anything else after the %f
... I'm not very comfortable with this.
Note that
That's a lot of work. In the mean time users can use regular expressions to parse and fixup timestamps. Lastly, |
We're in luck as to |
(Hit wrong button; didn't mean to close this!) |
Bah, Ruby uses What a mess. |
Thanks for the fast response. I'm going to try working out the plan you proposed and address the code comments. |
have progress since May? |
I haven't gone any further. |
I'd definitely like to complete this. I can't promise that I will soon though :( |
I just also ran into this issue with parsing milliseconds in jq. |
I'm taking a fresh look at this using the plan put forth by @nicowilliams. |
I was hoping to find a clever way to simply parse out Because I probably don't have the bandwidth for that I'm going to close this to encourage anyone else who wants to try. |
Addresses #1409.
The milliseconds should be added at the end of the fmt string. They're chopped off of the original fmt string which is passed to strptime(3). As before, if the format does not match, e.g. milliseconds in date but not fmt string, a jv error is returned.
I also moved some of the cleanup in case of an error to a goto label to reduce redundancy.
Please let me know if I can change or improve anything!