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
parse timestamps (number) to Dates #364
Comments
It could probably be implemented as a native date filter that could convert between date formats, like |
Yes please |
Yeah, |
Would like to have this also. |
And today I happen to need this badly too. |
Would it also parse ISO timestamps like |
Well, it's not pretty, but you can now do this with regex to some extent. A nice thing to do is to parse the date to an array, as in [2015, 3, 5, 19, 40, 53, 324], so that the lexicographic order sorts it correctly. |
@nicowilliams awesome! |
I need to add strftime() and others too, but this is a start.
|
@nicowilliams -- Please note: (1) On a Mac (Yosemite with Xcode), HAVE_STRPTIME is not set. Here is the relevant section of config.log:
(2) The error message ( |
@pkoppstein Can you check the |
@nicowilliams - I only had time to run your manual.yml test cases as detailed below. The good news is that there were no failures; the bad news is that in all three cases, the results differ from the advertized output values.
|
I can see this being a package rather than in core. |
@pkoppstein Oops, fixed. @joelpurra Yes, indeed, but having C-coded functions in third-party modules is quite a ways off, and these are super convenient. I was really annoyed at POSIX though. I'd completely forgotten about the sheer awfulness of On the other hand, to deal just with ISO 8601, one could just parse and format dates in entirely jq-coded functions. But then there are the pesky leap years and leap seconds that one would have to very carefully code around. Calling the C library to handle these is very convenient, not least because any bugs can then be blamed on someone else! |
I suppose the docs should say something about localization, given the use of strp/ftime format strings... Up until now jq has completely avoided the subject of localization. If we ever add something like a |
It would be nice if jq can parse timestamps (in milliseconds since Epoch) to Dates.
for example:
input:
{ "created": 1405663200000 }
command:
jq '.created | @Date("yyyy-mm-dd")'
output:
"2014-07-18"
The text was updated successfully, but these errors were encountered: