RFE: Implement date parsing and formatting on Windows just as on other platforms
The parameter strptime of jq-win64_1.6.exe does not work properly.
for example:
windows-64:
# echo '"2015-03-05T23:51:47Z"' | ./jq-win64_1.6.exe 'strptime("%Y-%m-%dT%H:%M:%SZ")'
jq: error (at <stdin>:1): strptime/1 not implemented on this platform
# echo '"2015-03-05T23:51:47Z"' | ./jq-win64_1.6.exe 'fromdate'
jq: error (at <stdin>:1): strptime/1 not implemented on this platform
unbutu:
root@oss-001:test_jq# echo '"2015-03-05T23:51:47Z"' | jq 'strptime("%Y-%m-%dT%H:%M:%SZ")'
[
2015,
2,
5,
23,
51,
47,
4,
63
]
root@oss-001:test_jq# echo '"2015-03-05T23:51:47Z"'| jq 'fromdate'
1425599507
Same issue for me when using jq's fromdateiso8601 function on Windows 10 build 19042.631.
Same issue for me when using jq's fromdateiso8601 function on Windows 10 build 19045.2486,
same issue for me when using jq's fromdateiso8601 function on windows server 2016.
same issue for me when using jq's fromdateiso8601 function on windows 11
I see that the recent jq-1.8.0 release added #3008, #3094, #3071, and the release notes say:
- Provide strptime/1 on all systems. @george-hopkins @fdellwing https://github.com/jqlang/jq/pull/3008 https://github.com/jqlang/jq/pull/3094
- Fix _WIN32 port of strptime. @emanuele6 https://github.com/jqlang/jq/pull/3071
but I'm guessing that this particular ticket #2071 isn't quite complete yet. I've tried both the -amd64 and the -i386 builds, in case those #ifdef WIN32 actually are specific to the 32-bit build, and I'm still getting strptime/1 only supports ISO 8601 on this platform:
With Windows 11, git-bash (my normal setup):
$ echo '{"date": "2025-05-01T00:00:00Z"}' | jq '.date | strptime("%F")'
jq: error (at <stdin>:1): strptime/1 only supports ISO 8601 on this platform
With Windows 11 cmd window (not my normal setup, so I may be typing this incorrectly), I get:
$ echo '{"date": "2025-05-01T00:00:00Z"}' | jq '.date | strptime("%F")'
'strptime' is not recognized as an internal or external command,
operable program or batch file.
$ echo '{"date": "2025-05-01T00:00:00Z"}' | jq-windows-i386.exe '.date | strptime("%F")'
'strptime' is not recognized as an internal or external command,
operable program or batch file.
$ jq --version
jq-1.8.0
$ jq-windows-i386.exe --version
jq-1.8.0
Ultimately, what I'm looking for is for this to work on Windows as it does on my Mac (even in 1.7.1):
$ echo '{"date": "August 5, 1975"}' | jq '.date | strptime("%B %d, %Y")'
The error message comes from 0fc8200ab42ea2b629fa0852987cfd4f6346b2dc, which implemented strptime fallback using sscanf. After that, fdab39bc7b8d41c1ae410f03a42afc10a9322c99 included strptime from NetBSD. So I think we can drop the #ifdef in f_strptime but am I correct? Also we have to include the license in COPYING. CC: @wader
I think we came to a similar conclusion in the issue millisecond parsing https://github.com/jqlang/jq/issues/1409
@eli-hu @Alanscut Could you test the executable built here?
Is there any Windows user able to test the executable as above comment?
I've mostly used wine to test windows binaries but it feels a bit shaky to use to testing time stuff maybe? The other alternative might be windows dev ISO images from microsoft https://developer.microsoft.com/en-us/windows/downloads/virtual-machines/ but they are giant and in my experience slow to use for development.